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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 18 22:43:37 CEST 2016


Author: chaussep
Date: 2016-05-18 22:43:37 +0200 (Wed, 18 May 2016)
New Revision: 93

Modified:
   pkg/gmm/R/bandwidth.R
   pkg/gmm/R/gmm.R
   pkg/gmm/R/momentEstim.R
   pkg/gmm/man/bwWilhelm.Rd
Log:
bwWilhelm can be an argument of gmm()

Modified: pkg/gmm/R/bandwidth.R
===================================================================
--- pkg/gmm/R/bandwidth.R	2016-05-18 17:23:39 UTC (rev 92)
+++ pkg/gmm/R/bandwidth.R	2016-05-18 20:43:37 UTC (rev 93)
@@ -39,8 +39,8 @@
   
   if (p==k)
       {
-          class(x$gt) <- "gmmFct"
-          return(bwAndrews(x$gt, order.by=order.by, kernel=kernel,
+          class(umat) <- "gmmFct"
+          return(bwAndrews(umat, order.by=order.by, kernel=kernel,
                            approx=approx, weights=weights, prewhite=prewhite,
                            ar.method=ar.method, data=data))
       }

Modified: pkg/gmm/R/gmm.R
===================================================================
--- pkg/gmm/R/gmm.R	2016-05-18 17:23:39 UTC (rev 92)
+++ pkg/gmm/R/gmm.R	2016-05-18 20:43:37 UTC (rev 93)
@@ -100,7 +100,15 @@
         AllArg$x <- gmat
 	if (is.function(AllArg$bw))
             {
-		AllArg$bw <- AllArg$bw(gmat, order.by = AllArg$order.by,
+                if (identical(AllArg$bw, bwWilhelm))
+                    {
+                        G <- .DmomentFct(obj$tet, obj$dat)
+                        obj <- list(gt=gmat, G=G)
+                        class(obj) <- "gmm"
+                    } else {
+                        obj <- gmat
+                    }
+		AllArg$bw <- AllArg$bw(obj, order.by = AllArg$order.by,
                                        kernel = AllArg$kernel, 
                                        prewhite = AllArg$prewhite,
                                        ar.method = AllArg$ar.method,
@@ -478,6 +486,8 @@
             {
                 obj <- attr(dat, "weight")
                 obj$centeredVcov <- FALSE
+                obj$tet <- tet
+                obj$dat <- dat
                 w <- .myKernHAC(gt, obj)
                 attr(w, "inv") <- TRUE
             }

Modified: pkg/gmm/R/momentEstim.R
===================================================================
--- pkg/gmm/R/momentEstim.R	2016-05-18 17:23:39 UTC (rev 92)
+++ pkg/gmm/R/momentEstim.R	2016-05-18 20:43:37 UTC (rev 93)
@@ -303,7 +303,6 @@
             } else {
                 res1 <- .tetlin(dat, w, type="2sls")
                 initTheta <- res1$par
-                gmat <- g(res1$par, dat)
                 w <- .weightFct(res1$par, dat, P$vcov)
                 res2 <- .tetlin(dat, w)
                 res2$firstStageReg <- res1$firstStageReg
@@ -647,8 +646,7 @@
                         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"))
+                        w <- .weightFct(res$coefficients, x, P$vcov)
                         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"
                     }

Modified: pkg/gmm/man/bwWilhelm.Rd
===================================================================
--- pkg/gmm/man/bwWilhelm.Rd	2016-05-18 17:23:39 UTC (rev 92)
+++ pkg/gmm/man/bwWilhelm.Rd	2016-05-18 20:43:37 UTC (rev 93)
@@ -66,9 +66,21 @@
 ###############################################
 res <- gmm(y ~ f1, ~ f1 + f2 + f3)
 summary(res)
+
+
+## Set the bandwidth using the second step estimate
+################################################
 bw <- bwWilhelm(res)
 res2 <- update(res, bw=bw)
 summary(res2)
 
+## Set the bandwidth using the first-step estimate as for bwAndrews
+###################################################################
+res3 <- gmm(y ~ f1, ~ f1 + f2 + f3, bw=bwWilhelm)
+summary(res3)
+
+
+
+
 }
 



More information about the Gmm-commits mailing list