[Gmm-commits] r125 - in pkg/gmm4: R vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 26 22:25:50 CEST 2018


Author: chaussep
Date: 2018-06-26 22:25:49 +0200 (Tue, 26 Jun 2018)
New Revision: 125

Modified:
   pkg/gmm4/R/allClasses.R
   pkg/gmm4/R/rGmmModel-methods.R
   pkg/gmm4/vignettes/gmmS4.Rnw
   pkg/gmm4/vignettes/gmmS4.pdf
Log:
added to vignette and fixed restriction issues

Modified: pkg/gmm4/R/allClasses.R
===================================================================
--- pkg/gmm4/R/allClasses.R	2018-06-26 01:51:07 UTC (rev 124)
+++ pkg/gmm4/R/allClasses.R	2018-06-26 20:25:49 UTC (rev 125)
@@ -211,7 +211,7 @@
                              v <- from at varNames[[i]]
                              chk <- "(Intercept)" %in% v
                              v <- v[v!="(Intercept)"]
-                             X <- from at data[,v]
+                             X <- from at data[,v, drop=FALSE]
                              colnames(X) <- paste(eqnNames[[i]],".", v, sep="")
                              if (chk)
                                  {
@@ -223,7 +223,7 @@
                          function(i) {
                              v <- all.vars(from at instT[[i]])
                              chk <- attr(from at instT[[i]], "intercept")==1
-                             Z <- from at data[,v]
+                             Z <- from at data[,v, drop=FALSE]
                              colnames(Z) <- paste(eqnNames[[i]],".", v, sep="")
                              if (chk)
                                  {

Modified: pkg/gmm4/R/rGmmModel-methods.R
===================================================================
--- pkg/gmm4/R/rGmmModel-methods.R	2018-06-26 01:51:07 UTC (rev 124)
+++ pkg/gmm4/R/rGmmModel-methods.R	2018-06-26 20:25:49 UTC (rev 125)
@@ -67,11 +67,14 @@
     {
         r <- R[i,]
         t1 <- which(r!=0)
-        q[i] <- q[i]/r[t1[1]]
-        r <- r/r[t1[1]]
-        diag(theta)[t1[1]] <- 0
-        minY[t1[1]] <- q[i]
-        theta[t1[1],t1[-1]] <- -r[t1[-1]]
+        st1 <- 1
+        while (sum(theta[,t1[st1]]!=0)>1)
+            st1 <- st1+1
+        q[i] <- q[i]/r[t1[st1]]
+        r <- r/r[t1[st1]]
+        diag(theta)[t1[st1]] <- 0
+        minY[t1[st1]] <- q[i]
+        theta[t1[st1],t1[-st1]] <- -r[t1[-st1]]
     }
     theta <- theta[,apply(theta,2,function(x) any(x!=0)), drop=FALSE]
     newParNames <- .getRestNames(theta, parNames)

Modified: pkg/gmm4/vignettes/gmmS4.Rnw
===================================================================
--- pkg/gmm4/vignettes/gmmS4.Rnw	2018-06-26 01:51:07 UTC (rev 124)
+++ pkg/gmm4/vignettes/gmmS4.Rnw	2018-06-26 20:25:49 UTC (rev 125)
@@ -1119,7 +1119,22 @@
 smod3
 @ 
 
+There is one other way to create a system classes. If one tries to create a ``linearGmm'' class using a matrix as the left hand side of the regression, the model will automatically converted to a system of equation with the same regressors and same instruments. Here is an example using simulated data.
 
+<<>>=
+dat <- list(y=matrix(rnorm(150),50,3),
+            x=rnorm(50), z1=rnorm(50),
+            z2=rnorm(50))
+mod <- gmmModel(y~x, ~z1+z2, data=dat, vcov="iid")
+mod
+@ 
+
+We could therefore create a multivariate regression in the following way:
+
+<<>>=
+mod <- gmmModel(y~x, ~x, vcov="iid", data=dat)
+@ 
+
 \subsection{Methods for ``sgmmModels'' classes}\label{sec:sgmmmodels-methods}
 
 The methods are very similar to the ones described above for ``gmmModels'' classes. Here, we briefly describe the difference.
@@ -1490,6 +1505,33 @@
 rsmod1<- restGmmModel(smod1, R2)
 summary(gmmFit(rsmod1))@coef
 @ 
+
+\item \textit{hypothesisTest}: For hypothesis testing, the method can test any linear restriction using either LM, LR or Wald tests. Consider the following unrestricted and restricted models.
+  
+<<>>=
+smod1 <- sysGmmModel(g, h, vcov="MDS", data=simData)
+res.u <- gmmFit(smod1)
+R1 <- list(c("x1=-12*z2"), character(), c("x3=0.8", "z1=0.3"))
+rsmod1 <- restGmmModel(smod1, R1)
+res.r <- gmmFit(rsmod1)
+@ 
+
+The methods works as for single equations. We can just provide the unrestricted model and the $R$ and $q$ to get the Wald test, provide only the restricted fit for the LR test, or provide both and choose among the three tests by setting the argument ``type'' to the appropriate value. We only show the latter case. 
+
+<<>>=
+hypothesisTest(res.u, res.r, type="Wald")
+@ 
+
+It is as easy to test cross-equation restrictions.
+
+<<>>=
+R2<- c("Supply.x1=1", "Demand1.x3=Demand2.x3")
+rsmod1<- restGmmModel(smod1, R2)
+res2.r <- gmmFit(rsmod1)
+hypothesisTest(res.u, res2.r, type="LR")
+@ 
+
+
 \end{itemize}
 
 \subsection{Direct estimation with \textit{gmm4}}\label{sec:sgmmmodels-gmm4}

Modified: pkg/gmm4/vignettes/gmmS4.pdf
===================================================================
(Binary files differ)



More information about the Gmm-commits mailing list