[Gmm-commits] r159 - in pkg/gmm: . R vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 4 17:32:33 CET 2019


Author: chaussep
Date: 2019-12-04 17:32:33 +0100 (Wed, 04 Dec 2019)
New Revision: 159

Modified:
   pkg/gmm/DESCRIPTION
   pkg/gmm/R/FinRes.R
   pkg/gmm/R/Methods.gmm.R
   pkg/gmm/R/gel.R
   pkg/gmm/R/getModel.R
   pkg/gmm/R/gmm.R
   pkg/gmm/R/gmmTests.R
   pkg/gmm/R/momentEstim.R
   pkg/gmm/vignettes/gmm_with_R.pdf
   pkg/gmm/vignettes/gmm_with_R.rnw
Log:
fixed errors caused by new matrix class in the new R version

Modified: pkg/gmm/DESCRIPTION
===================================================================
--- pkg/gmm/DESCRIPTION	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/DESCRIPTION	2019-12-04 16:32:33 UTC (rev 159)
@@ -1,6 +1,6 @@
 Package: gmm
-Version: 1.6-3
-Date: 2019-05-15
+Version: 1.6-4
+Date: 2019-12-04
 Title: Generalized Method of Moments and Generalized Empirical
         Likelihood
 Author: Pierre Chausse <pchausse at uwaterloo.ca>
@@ -14,6 +14,7 @@
         Kitamura 1997; <doi:10.1214/aos/1069362388>, Newey and Smith 2004; <doi:10.1111/j.1468-0262.2004.00482.x>,
 	and Anatolyev 2005 <doi:10.1111/j.1468-0262.2005.00601.x>).
 Depends: R (>= 2.10.0), sandwich
+NeedsCompilation: yes
 Suggests: mvtnorm, car, stabledist, MASS, timeDate, timeSeries
 Imports: stats, methods, grDevices, graphics
 License: GPL (>= 2) 

Modified: pkg/gmm/R/FinRes.R
===================================================================
--- pkg/gmm/R/FinRes.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/FinRes.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -56,7 +56,7 @@
         if (P$vcov == "TrueFixed") 
             {
                 z$vcov=try(solve(crossprod(G, P$weightsMatrix) %*% G)/n, silent = TRUE)
-                if(class(z$vcov) == "try-error")
+                if(any(class(z$vcov) == "try-error"))
                     {
                         z$vcov <- matrix(Inf,length(z$coef),length(z$coef))
                         warning("The covariance matrix of the coefficients is singular")
@@ -69,7 +69,7 @@
                     } else {                                                
                         z$vcov <- try(solve(crossprod(G, solve(v, G)))/n, silent = TRUE)
                     }
-                if(class(z$vcov) == "try-error")
+                if(any(class(z$vcov) == "try-error"))
                     {
                         z$vcov <- matrix(Inf,length(z$coef),length(z$coef))
                         warning("The covariance matrix of the coefficients is singular")
@@ -84,7 +84,7 @@
                 } else {
                     T1 <- try(solve(t(G)%*%w%*%G,t(G)%*%w), silent = TRUE)
                 }
-                if(class(T1) == "try-error")
+                if(any(class(T1) == "try-error"))
                     {
                         z$vcov <- matrix(Inf,length(z$coef),length(z$coef))
                         warning("The covariance matrix of the coefficients is singular")
@@ -102,7 +102,7 @@
                         z$w <- diag(ncol(z$gt))
                     } else {
                         z$w <- try(solve(v), silent = TRUE)
-                        if(class(z$w) == "try-error")
+                        if(any(class(z$w) == "try-error"))
                             warning("The covariance matrix of the moment function is singular")
                     }
             } else {
@@ -135,7 +135,7 @@
         if (P$vcov == "TrueFixed") 
             {
                 z$vcov=try(solve(crossprod(G, P$weightsMatrix) %*% G)/n, silent = TRUE)
-                if(class(z$vcov) == "try-error")
+                if(any(class(z$vcov) == "try-error"))
                     {
                         z$vcov <- matrix(Inf,nk,nk)
                         warning("The covariance matrix of the coefficients is singular")
@@ -142,7 +142,7 @@
                     }
             } else if ( (is.null(P$weightsMatrix)) & (P$wmatrix != "ident") ) {
                 z$vcov <- try(solve(crossprod(G, solve(v, G)))/n, silent = TRUE)
-                if(class(z$vcov) == "try-error")
+                if(any(class(z$vcov) == "try-error"))
                     {
                         z$vcov <- matrix(Inf,nk,nk)
                         warning("The covariance matrix of the coefficients is singular")
@@ -157,7 +157,7 @@
                 } else {
                     T1 <- try(solve(t(G)%*%w%*%G,t(G)%*%w), silent = TRUE)
                 }
-                if(class(T1) == "try-error")
+                if(any(class(T1) == "try-error"))
                     {
                         z$vcov <- matrix(Inf, nk, nk)
                         warning("The covariance matrix of the coefficients is singular")
@@ -177,7 +177,7 @@
                         z$w <- .weightFct_Sys(z$coefficient, x, "ident")
                     } else {
                         z$w <- try(solve(v), silent = TRUE)
-                        if(class(z$w) == "try-error")
+                        if(any(class(z$w) == "try-error"))
                             warning("The covariance matrix of the moment function is singular")
                     }
             } else {

Modified: pkg/gmm/R/Methods.gmm.R
===================================================================
--- pkg/gmm/R/Methods.gmm.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/Methods.gmm.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -55,7 +55,7 @@
             {
 		fstat <- vector()
                 fsRes <- object$fsRes
-                if (class(fsRes) == "listof")
+                if (class(fsRes)[1] == "listof")
                     {
                         nendo <- length(fsRes)
                     } else {
@@ -294,7 +294,7 @@
     {
         GWG <- crossprod(x$G, x$w %*% x$G)
         b <- try(solve(GWG), silent = TRUE)
-        if (class(b) == "try-error")
+        if (any(class(b) == "try-error"))
             stop("The bread matrix is singular")
         return(b)
     }

Modified: pkg/gmm/R/gel.R
===================================================================
--- pkg/gmm/R/gel.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/gel.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -198,7 +198,7 @@
                 if (i > maxit)
                     return(list(lambda=rep(0,ncol(gt)), obj=0, pt=rep(1/n,n),
                                 convergence=list(convergence=1)))
-                if (class(res) == "try-error")                    
+                if (any(class(res) == "try-error"))
                     return(list(lambda=rep(0,ncol(gt)), obj=0, pt=rep(1/n,n),
                                 convergence=list(convergence=2)))
                 pt[!w] <- getpt(gt2, res$lambda)
@@ -226,7 +226,7 @@
                         lam=double(q),pt=double(n),
                         obj=double(1)
                             ), silent=TRUE)
-        if (class(res) == "try-error")
+        if (any(class(res) == "try-error"))
             return(list(lambda=rep(0,q), obj=0, pt=rep(1/n,n),
                         convergence=list(convergence=3)))
         list(lambda=res$lam, obj=res$obj, pt=res$pt,
@@ -351,7 +351,7 @@
                         w <- kernel(1)
                     }
             } else {
-                if (class(w) != "tskernel")                   
+                if (class(w)[1] != "tskernel")                   
                     stop("Provided weights must be a numeric vector or an object of class 'tskernel'")
             }
         if (length(w$coef)>1)
@@ -456,7 +456,7 @@
                                             tol_obj = P$tol_obj, k = P$k1/P$k2,
                                             control = P$Lambdacontrol, 
                                             method = P$optlam), silent = TRUE)
-                        if(class(lamb) == "try-error")
+                        if(any(class(lamb) == "try-error"))
                             lamb <- getLamb(gt, l0, type = P$type, tol_lam = P$tol_lam,
                                             maxiterlam = P$maxiterlam, 
                                             tol_obj = P$tol_obj, k = P$k1/P$k2,
@@ -471,7 +471,7 @@
                 lamb <- try(.getCgelLam(gt, l0, type = P$type, method = "nlminb",
                                         control=P$Lambdacontrol, k = P$k1/P$k2,
                                         alpha = P$CGEL),silent=TRUE)
-                if (class(lamb) == "try-error")
+                if (any(class(lamb) == "try-error"))
                     lamb <- try(.getCgelLam(gt, l0, type = P$type,
                                             method = "constrOptim",
                                             control=P$Lambdacontrol, 

Modified: pkg/gmm/R/getModel.R
===================================================================
--- pkg/gmm/R/getModel.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/getModel.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -62,7 +62,7 @@
             typeDesc <- paste(typeDesc, " (Common Coefficients)")
         dat <- lapply(1:length(object$g), function(i) try(getDat(object$g[[i]], object$h[[i]], data = object$data,
                                                                  error=!object$commonCoef), silent=TRUE))
-        chk <- sapply(1:length(dat), function(i) class(dat[[i]]) == "try-error")
+        chk <- sapply(1:length(dat), function(i) any(class(dat[[i]]) == "try-error"))
         chk <- which(chk)
         mess <- vector()
         for (i in chk)

Modified: pkg/gmm/R/gmm.R
===================================================================
--- pkg/gmm/R/gmm.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/gmm.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -86,7 +86,7 @@
 
 tsls <- function(g,x,data)
     {
-        if(class(g) != "formula")
+        if(class(g)[1] != "formula")
             stop("2SLS is for linear models expressed as formula only")
         ans <- gmm(g,x,data=data,vcov="iid", TypeGmm="tsls")
         ans$met <- "Two Stage Least Squares"

Modified: pkg/gmm/R/gmmTests.R
===================================================================
--- pkg/gmm/R/gmmTests.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/gmmTests.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -81,7 +81,7 @@
 
 KTest <- function(obj, theta0=NULL, alphaK = 0.04, alphaJ = 0.01)
 	{
-	if (class(obj) != "gmm")
+	if (class(obj)[1] != "gmm")
 		stop("KTest is only for gmm type objects")
 
 	if (!is.null(attr(obj$dat,"eqConst")))

Modified: pkg/gmm/R/momentEstim.R
===================================================================
--- pkg/gmm/R/momentEstim.R	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/R/momentEstim.R	2019-12-04 16:32:33 UTC (rev 159)
@@ -654,7 +654,7 @@
                     {
                         res <- try(gmm(P$allArg$g,P$allArg$x,P$t0,wmatrix="ident",
                                        optfct=P$optfct, ...))                      
-                        if(class(res)=="try-error")
+                        if(any(class(res)=="try-error"))
                             stop("Cannot get a first step estimate to compute the weights for the Kernel estimate of the covariance matrix; try different starting values")
                         w <- .weightFct(res$coefficients, x, P$vcov)
                         attr(x, "weight")$WSpec$sandwich$bw <- attr(w,"Spec")$bw
@@ -805,7 +805,7 @@
             G <- P$gradv(z$coefficients, P$x, z$pt)
         allVcov <- try(.vcovGel(gt, G, P$k1, P$k2, P$bwVal, z$pt),
                        silent=TRUE)
-        if (class(allVcov) == "try-error")
+        if (any(class(allVcov) == "try-error"))
             {
                 z$vcov_par <- matrix(NA, length(z$coefficients), length(z$coefficients))
                 z$vcov_lambda <- matrix(NA, length(z$lambda), length(z$lambda))
@@ -905,7 +905,7 @@
         z$G <- G
         allVcov <- try(.vcovGel(gt, G, P$k1, P$k2, P$bwVal, z$pt),
                          silent=TRUE)
-        if (class(allVcov) == "try-error")
+        if (any(class(allVcov) == "try-error"))
             {
                 z$vcov_par <- matrix(NA, length(z$coefficients), length(z$coefficients))
                 z$vcov_lambda <- matrix(NA, length(z$lambda), length(z$lambda))

Modified: pkg/gmm/vignettes/gmm_with_R.pdf
===================================================================
(Binary files differ)

Modified: pkg/gmm/vignettes/gmm_with_R.rnw
===================================================================
--- pkg/gmm/vignettes/gmm_with_R.rnw	2019-12-03 22:40:22 UTC (rev 158)
+++ pkg/gmm/vignettes/gmm_with_R.rnw	2019-12-04 16:32:33 UTC (rev 159)
@@ -20,18 +20,31 @@
 \Plaintitle{Computing Generalized Method of Moments and Generalized Empirical Likelihood with R} 
 \Shorttitle{GMM and GEL with R} 
 
-\Abstract{This paper shows how to estimate models by the generalized method of moments and the generalized empirical likelihood using the \proglang{R} package \pkg{gmm}. A brief discussion is offered on the theoretical aspects of both methods and the functionality of the package is presented through several examples in economics and finance. It is a modified version of \cite{chausse10} published in the Journal of Statistical Software. It has been adapted to the version 1.4-0.  
-}
-\Keywords{generalized empirical likelihood, generalized method of moments, empirical likelihood, continuous updated estimator, exponential tilting, exponentially tilted empirical likelihood, \proglang{R}}
-\Plainkeywords{generalized empirical likelihood, generalized method of moments, empirical likelihood, continuous updated estimator, exponential tilting, exponentially tilted empirical likelihood, R}
+\Abstract{This paper shows how to estimate models by the generalized
+  method of moments and the generalized empirical likelihood using the
+  \proglang{R} package \pkg{gmm}. A brief discussion is offered on the
+  theoretical aspects of both methods and the functionality of the
+  package is presented through several examples in economics and
+  finance. It is a modified version of \cite{chausse10} published in
+  the Journal of Statistical Software. It has been adapted to the
+  version 1.4-0. \textbf{Notice that the maintenance of the package is
+    converging to zero. The new \pkg{gmm4} package, available on
+    RForge, will soon replace the \pkg{gmm} package.} }
 
+\Keywords{generalized empirical likelihood,
+  generalized method of moments, empirical likelihood, continuous
+  updated estimator, exponential tilting, exponentially tilted
+  empirical likelihood, \proglang{R}} \Plainkeywords{generalized
+  empirical likelihood, generalized method of moments, empirical
+  likelihood, continuous updated estimator, exponential tilting,
+  exponentially tilted empirical likelihood, R}
+
 \Address{
   Pierre Chaus\'e\\
   Department of Economics\\
   University of Waterloo\\
   Waterloo (Ontario), Canada\\
-  E-mail: \email{pierre.chausse at uqam.ca}\\
-  URL: \url{http://www.er.uqam.ca/nobel/k34115/}
+  E-mail: \email{pchausse at uwaterloo.ca}
 }
 \begin{document}
 
@@ -606,7 +619,7 @@
 @
 where $t0$ is any consistent estimate. As long as the optimal matrix is used, the covariance matrix of the coefficients can be estimated as follows:
 \[
-(\hat{G}'\hat{V}\hat{G})^{-1}/n,
+(\hat{G}'W\hat{G})^{-1}/n \equiv (\hat{G}'\hat{V}^{-1}\hat{G})^{-1}/n,
 \]
 where $\hat{G}=d\bar{g}(\hat{\theta})/d\theta$ and $\hat{V}$ is obtained using \code{kernHAC()}. It is not a sandwich covariance matrix and is computed using the \code{vcov()} method included in \pkg{gmm}. However, if any other weighting matrix is used, say $W$, the estimated covariance matrix of the coefficients must then be estimated as follows: 
 \[



More information about the Gmm-commits mailing list