[Gmm-commits] r118 - pkg/gmm/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 27 19:32:19 CET 2017


Author: chaussep
Date: 2017-11-27 19:32:19 +0100 (Mon, 27 Nov 2017)
New Revision: 118

Modified:
   pkg/gmm/R/FinRes.R
   pkg/gmm/R/specTest.R
Log:
Computation of the covariance matrix in justidentified models is more stable now

Modified: pkg/gmm/R/FinRes.R
===================================================================
--- pkg/gmm/R/FinRes.R	2017-09-27 18:51:43 UTC (rev 117)
+++ pkg/gmm/R/FinRes.R	2017-11-27 18:32:19 UTC (rev 118)
@@ -62,7 +62,13 @@
                         warning("The covariance matrix of the coefficients is singular")
                     }
             } else if ( (is.null(P$weightsMatrix)) & (P$wmatrix != "ident") ) {
-                z$vcov <- try(solve(crossprod(G, solve(v, G)))/n, silent = TRUE)
+                if (dim(G)[1] == dim(G)[2])
+                    {
+                        T1 <- try(solve(G), silent=TRUE)
+                        z$vcov <- try(T1%*%v%*%t(T1)/n, silent=TRUE)
+                    } else {                                                
+                        z$vcov <- try(solve(crossprod(G, solve(v, G)))/n, silent = TRUE)
+                    }
                 if(class(z$vcov) == "try-error")
                     {
                         z$vcov <- matrix(Inf,length(z$coef),length(z$coef))

Modified: pkg/gmm/R/specTest.R
===================================================================
--- pkg/gmm/R/specTest.R	2017-09-27 18:51:43 UTC (rev 117)
+++ pkg/gmm/R/specTest.R	2017-11-27 18:32:19 UTC (rev 118)
@@ -8,18 +8,25 @@
 	if (x$infWmatrix == "ident")
 		{
 		gb <- colMeans(x$gt)
-		j <- crossprod(gb,solve(x$v,gb))*x$n
+		j <- try(crossprod(gb,solve(x$v,gb))*x$n, silent=TRUE)
 		}
 	else if ( (x$infVcov!="TrueFixed") & !is.null(x$weightsMatrix) )
 		{
 		gb <- colMeans(x$gt)
-		j <- crossprod(gb,solve(x$v,gb))*x$n
+		j <- try(crossprod(gb,solve(x$v,gb))*x$n, silent=TRUE)
 		}
 	else
 		j <- x$objective*x$n
+        if (any(class(j)=="try-error"))
+            {
+                j <- noquote(cbind("Failed", "Failed"))
+            } else {
+                j <- noquote(cbind(j, ifelse(x$df>0,pchisq(j,x$df,
+                                                           lower.tail = FALSE),
+                                             "*******")))
+            }
+	J_test <- noquote(paste("J-Test: degrees of freedom is ",x$df,sep=""))
 
-	J_test <- noquote(paste("J-Test: degrees of freedom is ",x$df,sep=""))
-	j <- noquote(cbind(j, ifelse(x$df>0,pchisq(j,x$df, lower.tail = FALSE),"*******")))
 	dimnames(j) <- list("Test E(g)=0:  ", c("J-test", "P-value"))
 	ans<-list(ntest=J_test, test = j)
 	class(ans) <- "specTest"



More information about the Gmm-commits mailing list