[Gmm-commits] r92 - in pkg/gmm: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 18 19:23:40 CEST 2016


Author: chaussep
Date: 2016-05-18 19:23:39 +0200 (Wed, 18 May 2016)
New Revision: 92

Added:
   pkg/gmm/R/bandwidth.R
   pkg/gmm/man/bwWilhelm.Rd
Modified:
   pkg/gmm/DESCRIPTION
   pkg/gmm/NAMESPACE
   pkg/gmm/NEWS
   pkg/gmm/R/Methods.gmm.R
   pkg/gmm/R/getModel.R
   pkg/gmm/R/gmm.R
   pkg/gmm/R/momentEstim.R
   pkg/gmm/man/gmm.Rd
Log:
Added Wilhelm (2005) bandwidth method and a little more

Modified: pkg/gmm/DESCRIPTION
===================================================================
--- pkg/gmm/DESCRIPTION	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/DESCRIPTION	2016-05-18 17:23:39 UTC (rev 92)
@@ -1,6 +1,6 @@
 Package: gmm
-Version: 1.6-0
-Date: 2015-10-23
+Version: 1.6-1
+Date: 2016-05-17
 Title: Generalized Method of Moments and Generalized Empirical
         Likelihood
 Author: Pierre Chausse <pchausse at uwaterloo.ca>

Modified: pkg/gmm/NAMESPACE
===================================================================
--- pkg/gmm/NAMESPACE	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/NAMESPACE	2016-05-18 17:23:39 UTC (rev 92)
@@ -14,7 +14,7 @@
        KTest, print.gmmTests, gmmWithConst, estfun.tsls, model.matrix.tsls,vcov.tsls, bread.tsls, evalGmm, momentEstim.baseGmm.eval,
        momentEstim.baseGel.eval, evalGel, confint.gmm, print.confint, sysGmm, getModel.sysGmm, momentEstim.sysGmm.twoStep.formula,
        momentEstim.tsls.twoStep.formula, getModel.tsls, summary.sysGmm, print.sysGmm, print.summary.sysGmm,
-       sur, threeSLS, randEffect, five)
+       sur, threeSLS, randEffect, five, bwWilhelm)
  
 S3method(summary, gmm)
 S3method(summary, sysGmm)

Modified: pkg/gmm/NEWS
===================================================================
--- pkg/gmm/NEWS	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/NEWS	2016-05-18 17:23:39 UTC (rev 92)
@@ -1,3 +1,10 @@
+Changes in version 1.6-1
+
+o Added the function bwWilhelm() to compute the optimal bandwidth of Wilhelm(2015).
+o The argument $vcov of tsls object is the Classical covariance matrix. vcov() must be used to obtain a different covariance
+o Changed the default value of prewhite to 1 in gmm() because it is recommended for HAC estimation
+o gmm with optfct="optimize" was generating an error message. It has been fixed
+
 Changes in version 1.6-0
 
 o tsls is now a real 2-stage least square. Before it was a 2-step optimal GMM with HCCM weighting matrix.

Modified: pkg/gmm/R/Methods.gmm.R
===================================================================
--- pkg/gmm/R/Methods.gmm.R	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/R/Methods.gmm.R	2016-05-18 17:23:39 UTC (rev 92)
@@ -48,8 +48,6 @@
     {
 	if (!is.null(vcov))
             object$vcov=vcov
-	else
-            object$vcov=vcov(object)
 	ans <- summary.gmm(object)
 	ans$met <- paste(ans$met, "(Meat type = ", attr(object$vcov, "vcovType"), ")",sep="")
 	k <- object$dat$k

Added: pkg/gmm/R/bandwidth.R
===================================================================
--- pkg/gmm/R/bandwidth.R	                        (rev 0)
+++ pkg/gmm/R/bandwidth.R	2016-05-18 17:23:39 UTC (rev 92)
@@ -0,0 +1,154 @@
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  A copy of the GNU General Public License is available at
+#  http://www.r-project.org/Licenses/
+
+
+bwWilhelm <- function(x, order.by = NULL, kernel = c("Quadratic Spectral",
+  "Bartlett", "Parzen", "Tukey-Hanning"), approx = c("AR(1)", "ARMA(1,1)"),
+  weights = NULL, prewhite = 1, ar.method = "ols", data=list()) 
+{
+  ## ensure that NAs are omitted
+  if(is.list(x) && !is.null(x$na.action)) class(x$na.action) <- "omit"
+
+  # ensure that x is a gmm object
+  stopifnot(attr(x,"class") == "gmm")
+
+  kernel <- match.arg(kernel)
+  approx <- match.arg(approx)
+  prewhite <- as.integer(prewhite)
+
+  # the following line applies only to the case class(res)=="gmm"
+  umat <- x$gt
+  n <- nrow(umat)
+  k <- ncol(umat)
+
+  # the following line applies only to the case class(res)=="gmm"
+  G <- x$G
+  p <- ncol(G)
+
+  # return Andrews' bandwidth in the just-identified case
+  
+  if (p==k)
+      {
+          class(x$gt) <- "gmmFct"
+          return(bwAndrews(x$gt, order.by=order.by, kernel=kernel,
+                           approx=approx, weights=weights, prewhite=prewhite,
+                           ar.method=ar.method, data=data))
+      }
+
+  if(!is.null(order.by))
+  {
+    if(inherits(order.by, "formula")) {
+      z <- model.matrix(order.by, data = data)
+      z <- as.vector(z[,ncol(z)])
+    } else {
+      z <- order.by
+    }
+    index <- order(z)
+  } else {
+    index <- 1:n
+  }
+
+  umat <- umat[index, , drop = FALSE]
+
+  ## compute weights (w_a, see p. 834)
+  ## (try to set the intercept weight to 0)
+  #### could be ignored by using: weights = 1
+  
+  if(is.null(weights)) {
+    weights <- rep(1, p)
+    unames <- colnames(umat)
+    if(!is.null(unames) && "(Intercept)" %in% unames) 
+      weights[which(unames == "(Intercept)")] <- 0
+    else {
+      res <- try(as.vector(rowMeans(estfun(x)/model.matrix(x), na.rm = TRUE)), silent = TRUE)
+      if(inherits(res, "try-error")) res <- try(residuals(x), silent = TRUE)
+      if(!inherits(res, "try-error")) weights[which(colSums((umat - res)^2) < 1e-16)] <- 0
+    }
+    if(isTRUE(all.equal(weights, rep(0, p)))) weights <- rep(1, p)
+  } else {
+    weights <- rep(weights, length.out = p)
+  }
+  if(length(weights) < 2) weights <- 1
+
+  ## pre-whitening
+  if(prewhite > 0) {
+    var.fit <- ar(umat, order.max = prewhite, demean = FALSE, aic = FALSE, method = ar.method)
+    if(inherits(var.fit, "try-error")) stop(sprintf("VAR(%i) prewhitening of estimating functions failed", prewhite))
+    umat <- as.matrix(na.omit(var.fit$resid))
+    n <- n - prewhite
+  }
+ 
+  # define kernel constants
+  kernConst <- switch(kernel,
+    "Bartlett"           = list(q = 1, g_q = 1,        mu1 = 1,       mu2 = 2/3),
+    "Parzen"             = list(q = 2, g_q = 6,        mu1 = 0.75,    mu2 = 0.539286),
+    "Tukey-Hanning"      = list(q = 2, g_q = pi^2/4,   mu1 = 1,       mu2 = 0.75),
+    "Quadratic Spectral" = list(q = 2, g_q = 1.421223, mu1 = 1.25003, mu2 = 0.999985))
+
+  # fit approximating model to moments
+  if(approx == "AR(1)") {
+
+    fitAR1 <- function(x) {
+      rval <- ar(x, order.max = 1, aic = FALSE, method = "ols")
+      rval <- c(rval$ar, sqrt(rval$var.pred))
+      names(rval) <- c("rho", "sigma")
+      return(rval)
+    }
+    
+    ar.coef <- apply(umat, 2, fitAR1)
+
+    Omega0 <- ar.coef["sigma", ]^2 / (1-ar.coef["rho", ])^2
+    Omega_q <- if(kernConst$q == 1) {
+      diag(2 * ar.coef["sigma", ]^2 * ar.coef["rho", ] / ((1 - ar.coef["rho", ])^3 * (1 + ar.coef["rho", ])))
+    } else {
+      diag(2 * ar.coef["sigma", ]^2 * ar.coef["rho", ] / (1 - ar.coef["rho", ])^4) 
+    }
+
+  } else {
+
+    fitARMA11 <- function(x) {
+      rval <- arima(x, order = c(1, 0, 1), include.mean = FALSE)
+      rval <- c(rval$coef, sqrt(rval$sigma2))
+      names(rval) <- c("rho", "psi", "sigma")
+      return(rval)
+    }
+    
+    arma.coef <- apply(umat, 2, fitARMA11)
+
+    Omega0 <- (1 + ar.coef["psi", ])^2 * ar.coef["sigma", ]^2 / (1 - ar.coef["rho", ])^2
+    Omega_q <- if(kernConst$q == 1) {
+      diag(2 * (1 + ar.coef["psi", ] * ar.coef["rho", ]) * (ar.coef["psi", ] + ar.coef["rho", ]) * ar.coef["sigma", ]^2 / ((1 - ar.coef["rho", ])^3 * (1 + ar.coef["rho", ])))
+    } else {
+      diag(2 * (1 + ar.coef["psi", ] * ar.coef["rho", ]) * (ar.coef["psi", ] + ar.coef["rho", ]) * ar.coef["sigma", ]^2 / (1 - ar.coef["rho", ])^4)
+    }
+
+  }
+
+  # compute remaining bandwidth components
+  W <- diag(weights)
+  Omega0inv <- diag(1/Omega0)
+  Sigma0 <- solve( crossprod(Omega0inv%*%G, G) )
+  H0 <- Sigma0 %*% t(G) %*% Omega0inv
+  P0 <- Omega0inv - Omega0inv %*% G %*% H0
+  
+  # compute optimal bandwidth
+  nu2 <- (2 * kernConst$mu1 + kernConst$mu2) * (k - p) * sum(diag(Sigma0 %*% W))
+  nu3 <- kernConst$g_q^2 * sum(diag(t(Omega_q) %*% t(H0) %*% W %*% H0 %*% Omega_q %*% P0))
+  c0 <- if(nu2 * nu3 > 0) 2 * kernConst$q else -1
+  rval <- (c0 * nu3/nu2 * n)^(1/(1 + 2 * kernConst$q))
+
+  return(rval)
+}
+
+
+

Modified: pkg/gmm/R/getModel.R
===================================================================
--- pkg/gmm/R/getModel.R	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/R/getModel.R	2016-05-18 17:23:39 UTC (rev 92)
@@ -222,10 +222,15 @@
                 attr(object$x, "k") <- length(object$t0)
                 attr(object$x, "q") <- NCOL(object$g(object$t0, object$x))
                 attr(object$x, "n") <- NROW(object$x)
-                if(is.null(names(object$t0)))
-                    object$namesCoef <- paste("Theta[" ,1:attr(object$x, "k"), "]", sep = "")
-                else
-                    object$namesCoef <- names(object$t0)
+                if (object$optfct == "optimize")
+                    {
+                        object$namesCoef <- "Theta1"
+                    } else {
+                        if(is.null(names(object$t0)))
+                            object$namesCoef <- paste("Theta[" ,1:attr(object$x, "k"), "]", sep = "")
+                        else
+                            object$namesCoef <- names(object$t0)
+                    }
                 if(is.null(object$weightsMatrix))
                     {
                         clname <- paste(class(object), "." ,object$type, sep = "")

Modified: pkg/gmm/R/gmm.R
===================================================================
--- pkg/gmm/R/gmm.R	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/R/gmm.R	2016-05-18 17:23:39 UTC (rev 92)
@@ -13,7 +13,7 @@
 
 gmm <- function(g,x,t0=NULL,gradv=NULL, type=c("twoStep","cue","iterative"), wmatrix = c("optimal","ident"),  vcov=c("HAC","MDS","iid","TrueFixed"), 
                 kernel=c("Quadratic Spectral","Truncated", "Bartlett", "Parzen", "Tukey-Hanning"),crit=10e-7,bw = bwAndrews, 
-                prewhite = FALSE, ar.method = "ols", approx="AR(1)",tol = 1e-7, itermax=100,optfct=c("optim","optimize","nlminb", "constrOptim"),
+                prewhite = 1, ar.method = "ols", approx="AR(1)",tol = 1e-7, itermax=100,optfct=c("optim","optimize","nlminb", "constrOptim"),
                 model=TRUE, X=FALSE, Y=FALSE, TypeGmm = "baseGmm", centeredVcov = TRUE, weightsMatrix = NULL, traceIter = FALSE, data, eqConst = NULL, 
                 eqConstFullVcov = FALSE, ...)
     {
@@ -86,30 +86,33 @@
         ans$met <- "Two Stage Least Squares"
         ans$call <- match.call()
         class(ans) <- c("tsls","gmm")
+        ans$vcov <- vcov(ans, type="Classical")
         return(ans)
     }
 
-
 .myKernHAC <- function(gmat, obj)
     {
         gmat <- as.matrix(gmat)
         if(obj$centeredVcov) 
-            gmat <- lm(gmat~1)
-        else
-            class(gmat) <- "gmmFct"
+            gmat <- scale(gmat, scale=FALSE)
+        class(gmat) <- "gmmFct"
 	AllArg <- obj$WSpec$sandwich
-	AllArg$x <- gmat
+        AllArg$x <- gmat
 	if (is.function(AllArg$bw))
             {
-		bw <- AllArg$bw(gmat, order.by = AllArg$order.by, kernel = AllArg$kernel, 
-                                prewhite = AllArg$prewhite, ar.method = AllArg$ar.method)
-		AllArg$bw <- bw
+		AllArg$bw <- AllArg$bw(gmat, order.by = AllArg$order.by,
+                                       kernel = AllArg$kernel, 
+                                       prewhite = AllArg$prewhite,
+                                       ar.method = AllArg$ar.method,
+                                       approx=AllArg$approx)
             }
-	weights <- do.call(weightsAndrews,AllArg)
-	AllArg$sandwich <- FALSE
-	AllArg$weights <- weights
-	w <- do.call(vcovHAC, AllArg)
-	attr(w,"Spec") <- list(weights = weights, bw = AllArg$bw, kernel = AllArg$kernel)
+	weights <- weightsAndrews(x=gmat, bw=AllArg$bw, kernel=AllArg$kernel,
+                                  prewhite=AllArg$prewhite, tol=AllArg$tol)
+	w <- vcovHAC(x=gmat, order.by=AllArg$order.by, weights=weights,
+                     prewhite=AllArg$prewhite, sandwich=FALSE,
+                     ar.method=AllArg$ar.method)
+	attr(w,"Spec") <- list(weights = weights, bw = AllArg$bw,
+                               kernel = AllArg$kernel)
 	w
     }
 
@@ -372,13 +375,16 @@
         return(G)
     }
 
-.objCue <- function(thet, x, type=c("HAC", "iid", "ident", "fct", "fixed"))
+.objCue <- function(thet, x, type=c("HAC", "MDS", "iid", "ident", "fct", "fixed"))
     {
         type <- match.arg(type)
         gt <- .momentFct(thet, x)
         gbar <- as.vector(colMeans(gt))
         w <- .weightFct(thet, x, type)
-        obj <- crossprod(gbar,solve(w,gbar))
+        if (attr(w, "inv"))
+            obj <- crossprod(gbar,solve(w,gbar))
+        else
+            obj <- crossprod(gbar,w%*%gbar)
         return(obj)
     }	
 
@@ -462,10 +468,10 @@
             {
                 w <- diag(attr(dat, "q"))
                 attr(w, "inv") <- FALSE
-            } else { 
+            } else {
                 gt <- .momentFct(tet,dat)
                 if(attr(dat, "weight")$centeredVcov)
-                    gt <- residuals(lm(gt~1))
+                    gt <- scale(gt, scale=FALSE)
                 n <- NROW(gt)
             }
         if (type == "HAC")

Modified: pkg/gmm/R/momentEstim.R
===================================================================
--- pkg/gmm/R/momentEstim.R	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/R/momentEstim.R	2016-05-18 17:23:39 UTC (rev 92)
@@ -227,7 +227,8 @@
         z$iid <- P$iid
         z$g <- P$g
         z$WSpec <- P$WSpec
-        
+        print(P$namesCoef)
+        print(z$coefficients)
         names(z$coefficients) <- P$namesCoef
         if (is.null(colnames(z$gt)))
             colnames(z$gt) <- paste("gt",1:ncol(z$gt),sep="")
@@ -542,8 +543,8 @@
         k <- attr(dat, "k")  
         k2 <- k*dat$ny
         df <- q-k*dat$ny
-        P$weightMessage <- "Weights for kernel estimate of the covariance are fixed and based on the first step estimate of Theta"	
-
+        w <- .weightFct(NULL, dat, "ident")                  
+        
         if (q == k2 | P$wmatrix == "ident")
             {
                 res <- .tetlin(dat, w)
@@ -552,16 +553,17 @@
             } else {
                 if (is.null(P$t0))
                     {
-                        w <- .weightFct(NULL, dat, "ident")          
                         P$t0 <- .tetlin(dat, w, type="2sls")$par
                         initTheta <- P$t0
                     } else {
                         initTheta <- P$t0
                     }
-                gt0 <- g(P$t0, dat)
-                w <- .myKernHAC(gt0, attr(dat, "weight"))
-                attr(dat, "weight")$WSpec$sandwich$bw <- attr(w,"Spec")$bw
-
+                if (P$vcov == "HAC")
+                    {
+                        w <- .weightFct(P$t0, dat, P$vcov)
+                        attr(dat, "weight")$WSpec$sandwich$bw <- attr(w,"Spec")$bw
+                        P$weightMessage <- "Weights for kernel estimate of the covariance are fixed and based on the first step estimate of Theta"
+                    }
                 if (P$optfct == "optim")
                     res2 <- optim(P$t0,.objCue, x = dat, type = P$vcov, ...)
                 if (P$optfct == "constrOptim")
@@ -613,7 +615,7 @@
         z$specMod <- P$specMod
         z$cue <- list(weights=P$fixedKernW,message=P$weightMessage)
         z$WSpec <- P$WSpec
-        z$w0 <- w
+        z$w0 <- .weightFct(z$coefficients, dat, P$vcov)
         names(z$coefficients) <- P$namesCoef
         colnames(z$gt) <- P$namesgt
         
@@ -630,22 +632,26 @@
         k <- attr(x, "k")
         k2 <- k
         df <- q - k
-        w = .weightFct(NULL, x, "ident")
 
-        res <- try(gmm(P$g,P$x,P$t0,wmatrix="ident",optfct=P$optfct, ...))
-        if(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")
-        initTheta <- res$coef
-
         if (q == k2 | P$wmatrix == "ident")
             {
-                z <- list(coefficients = res$coef, objective = res$objective, algoInfo = res$algoInfo, k=k, k2=k2, n=n, q=q, df=df)
+                w = .weightFct(NULL, x, "ident")
+                res <- gmm(P$g,P$x,P$t0,wmatrix="ident",optfct=P$optfct, ...)                
+                z <- list(coefficients = res$coef, objective = res$objective, algoInfo = res$algoInfo, k=k, k2=k2, n=n, q=q, df=df, initTheta=P$t0)
                 P$weightMessage <- "No CUE needed because the model if just identified or you set wmatrix=identity"
             } else {
-                gt0 <- P$g(res$coef,x) #Should we compute the weigths with the initial value provided?
-                w <- .myKernHAC(gt0, attr(x, "weight"))
-                attr(x, "weight")$WSpec$sandwich$bw <- attr(w,"Spec")$bw
-                P$weightMessage <- "Weights for kernel estimate of the covariance are fixed and based on the first step estimate of Theta"
+                w <- .weightFct(P$t0, x, P$vcov)
+                initTheta <- P$t0
+                if (P$vcov == "HAC")
+                    {
+                        res <- try(gmm(P$g,P$x,P$t0,wmatrix="ident",optfct=P$optfct, ...))
+                        if(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")
+                        gt0 <- res$gt
+                        w <- .myKernHAC(gt0, attr(x, "weight"))
+                        attr(x, "weight")$WSpec$sandwich$bw <- attr(w,"Spec")$bw
+                        P$weightMessage <- "Weights for kernel estimate of the covariance are fixed and based on the first step estimate of Theta"
+                    }
                 if (P$optfct == "optim")
                     {
                         res2 <- optim(P$t0, .objCue, x = x, type = P$vcov, ...)
@@ -687,14 +693,14 @@
         z$dat <- P$x
         z$gradv <- P$gradv
         z$gt <- P$g(z$coefficients, P$x)
+        z$w0 <- .weightFct(z$coefficients, P$x, P$vcov)        
         z$iid <- P$iid
         z$g <- P$g
         z$cue <- list(weights=P$fixedKernW,message=P$weightMessage)
         names(z$coefficients) <- P$namesCoef
         if (is.null(colnames(z$gt)))
             colnames(z$gt) <- paste("gt",1:ncol(z$gt),sep="")
-        z$WSpec <- P$WSpec
-        
+        z$WSpec <- P$WSpec        
         z$specMod <- P$specMod
         class(z) <- paste(P$TypeGmm, ".res", sep = "")	
         return(z)

Added: pkg/gmm/man/bwWilhelm.Rd
===================================================================
--- pkg/gmm/man/bwWilhelm.Rd	                        (rev 0)
+++ pkg/gmm/man/bwWilhelm.Rd	2016-05-18 17:23:39 UTC (rev 92)
@@ -0,0 +1,74 @@
+\name{bwWilhelm}
+\alias{bwWilhelm}
+	
+\title{Wilhelm (2015) bandwidth selection}
+
+\description{
+It computes the optimal bandwidth for the HAC estimation of the covariance matrix of the moment conditions. 
+}
+\usage{
+bwWilhelm(x, order.by = NULL, kernel = c("Quadratic Spectral",
+  "Bartlett", "Parzen", "Tukey-Hanning"), approx = c("AR(1)", "ARMA(1,1)"),
+  weights = NULL, prewhite = 1, ar.method = "ols", data = list())
+}
+\arguments{
+\item{x}{An object of class \code{gmm}.}
+
+\item{order.by}{Either a vector 'z' or a formula with a single
+  explanatory variable like '~ z'. The observations in the model are ordered by the size of 'z'. If set to 'NULL' (the default)
+the observations are assumed to be ordered (e.g., a time
+series).}
+
+\item{kernel}{type of kernel used to compute the covariance matrix of the vector of sample moment conditions (see \code{\link{kernHAC}} for more details)}
+
+\item{approx}{A character specifying the approximation method if the bandwidth has to be chosen by \code{bwAndrews}.}
+
+\item{weights}{numeric. A vector of weights used for weighting the
+  estimated coefficients of the approximation model (as specified by 'approx'). By default all weights are 1 except that for the
+  intercept term (if there is more than one variable)}
+
+\item{prewhite}{logical or integer. Should the estimating functions be prewhitened? If \code{TRUE} or greater than 0 a VAR model of order \code{as.integer(prewhite)} is fitted via \code{ar} with method \code{"ols"} and \code{demean = FALSE}.}
+
+\item{ar.method}{character. The \code{method} argument passed to \code{\link{ar}} for prewhitening.}
+
+\item{data}{an optional data frame containing the variables in the 'order.by' model.}
+
+}
+
+\value{
+The function 'bwWilhelm'  returns the optimal bandwidth.
+ }
+
+
+\references{
+
+  Wilhelm, D. (2015), Optimal Bandwidth Selection for Robust Generalized
+  Method of Moments Estimation.
+  \emph{Econometric Theory}, \bold{31}, 1054--1077
+
+  Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.
+  \emph{Journal of Statistical Software}, \bold{16}(9), 1--16.
+  URL \url{http://www.jstatsoft.org/v16/i09/}.
+}
+
+\note{
+  The function was written by Daniel Wilhelm and is based on \link{bwAndrews}.
+}
+
+\examples{
+data(Finance)
+f1 <- Finance[1:300, "rm"] 
+f2 <- Finance[1:300, "hml"] 
+f3 <- Finance[1:300, "smb"] 
+y <- Finance[1:300,"WMK"]
+
+## Silly example just to make it over-identified
+###############################################
+res <- gmm(y ~ f1, ~ f1 + f2 + f3)
+summary(res)
+bw <- bwWilhelm(res)
+res2 <- update(res, bw=bw)
+summary(res2)
+
+}
+

Modified: pkg/gmm/man/gmm.Rd
===================================================================
--- pkg/gmm/man/gmm.Rd	2015-12-16 19:18:41 UTC (rev 91)
+++ pkg/gmm/man/gmm.Rd	2016-05-18 17:23:39 UTC (rev 92)
@@ -13,7 +13,7 @@
 gmm(g,x,t0=NULL,gradv=NULL, type=c("twoStep","cue","iterative"), 
     wmatrix = c("optimal","ident"), vcov=c("HAC","MDS","iid","TrueFixed"), 
     kernel=c("Quadratic Spectral","Truncated", "Bartlett", "Parzen", "Tukey-Hanning"),
-    crit=10e-7,bw = bwAndrews, prewhite = FALSE, ar.method = "ols", approx="AR(1)",
+    crit=10e-7,bw = bwAndrews, prewhite = 1, ar.method = "ols", approx="AR(1)",
     tol = 1e-7, itermax=100,optfct=c("optim","optimize","nlminb", "constrOptim"),
     model=TRUE, X=FALSE, Y=FALSE, TypeGmm = "baseGmm", centeredVcov = TRUE, 
     weightsMatrix = NULL, traceIter = FALSE, data, eqConst = NULL, 



More information about the Gmm-commits mailing list