[Vars-commits] r58 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 11 12:52:27 CET 2009


Author: matthieu
Date: 2009-12-11 12:52:26 +0100 (Fri, 11 Dec 2009)
New Revision: 58

Added:
   pkg/R/toMlm.R
Log:
Add toMlm.R allows to run coeftest and sandwich


Added: pkg/R/toMlm.R
===================================================================
--- pkg/R/toMlm.R	                        (rev 0)
+++ pkg/R/toMlm.R	2009-12-11 11:52:26 UTC (rev 58)
@@ -0,0 +1,40 @@
+toMlm<- function(x, ...) {
+  UseMethod("toMlm")
+}
+
+toMlm.default <- function(x){
+  lm(x$model)
+}
+
+toMlm.varest<-function(x){
+  ix <- 1:x$K
+  X<-x$datamat
+  #remove constant in datamat
+  if(x$type%in%c("const", "both")) X<-X[, -grep("const", colnames(X))]
+  #construct formula
+  left <- paste(names(X)[ix], collapse = ",")
+  fo <- as.formula(paste("cbind(", left, ") ~ ."))
+  #apply lm
+  res<-eval(substitute(lm(fo, X), list(fo = fo))) #code suggested by Gabor Groothendick
+  return(res)
+}
+
+coeftest.varest<-function(x, ...){
+  coeftest(toMlm.varest(x), ...)
+}
+
+bread.varest<-function(x, ...){
+  bread(toMlm.varest(x), ...)
+}
+
+vcov.varest<-function(object, ...){
+  vcov(toMlm.varest(object), ...)
+}
+
+vcovHC.varest<-function(x, ...){
+  vcovHC(toMlm.varest(x), ...)
+}
+
+estfun.varest<-function(x, ...){
+  estfun(toMlm.varest(x), ...)
+}
\ No newline at end of file



More information about the Vars-commits mailing list