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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 13 19:28:53 CEST 2012


Author: chaussep
Date: 2012-04-13 19:28:53 +0200 (Fri, 13 Apr 2012)
New Revision: 50

Modified:
   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/getModel.Rd
   pkg/gmm/man/gmm.Rd
Log:
Added equality constraints: see help(gmm)

Modified: pkg/gmm/NAMESPACE
===================================================================
--- pkg/gmm/NAMESPACE	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/NAMESPACE	2012-04-13 17:28:53 UTC (rev 50)
@@ -7,7 +7,7 @@
 	residuals.gmm, fitted.gel, residuals.gel, plot.gmm, plot.gel,formula.gmm, formula.gel, charStable, specTest, 
 	specTest.gmm, specTest.gel, print.specTest, momentEstim.baseGmm.twoStep, momentEstim.baseGmm.twoStep.formula,
         momentEstim.baseGmm.iterative.formula, momentEstim.baseGmm.iterative, momentEstim.baseGmm.cue.formula, 
-	momentEstim.baseGmm.cue, getModel.baseGmm, getModel.baseGel, FinRes.baseGmm.res, momentEstim.baseGel.mod, 
+	momentEstim.baseGmm.cue, getModel.baseGmm, getModel.baseGel, getModel.constGmm, FinRes.baseGmm.res, momentEstim.baseGel.mod, 
 	momentEstim.baseGel.modFormula,tsls,summary.tsls, print.summary.tsls)
  
 S3method(summary, gmm)
@@ -38,6 +38,7 @@
 S3method(FinRes, baseGmm.res)
 S3method(getModel, baseGmm)
 S3method(getModel, baseGel)
+S3method(getModel, constGmm)
 S3method(momentEstim, baseGmm.twoStep)
 S3method(momentEstim, baseGmm.twoStep.formula)
 S3method(momentEstim, baseGmm.iterative.formula)

Modified: pkg/gmm/NEWS
===================================================================
--- pkg/gmm/NEWS	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/NEWS	2012-04-13 17:28:53 UTC (rev 50)
@@ -27,6 +27,7 @@
   The first step estimates are usually computed using the identity matrix. The vector is now printed for better control. 
 o Cleaned the codes. The data are in object$dat and we can get the moment matrix by calling gt <- object$g(object$coef,object$dat) for linear and 
   non-linear models, where object is of class gmm.
+o We can now impose equality constraints of the type theta_i=c_i with the option eqConst=. See help(gmm) which includes examples.
 
 Changes in version 1.3-8
 

Modified: pkg/gmm/R/Methods.gmm.R
===================================================================
--- pkg/gmm/R/Methods.gmm.R	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/R/Methods.gmm.R	2012-04-13 17:28:53 UTC (rev 50)
@@ -34,6 +34,7 @@
 		ans$initTheta <- object$initTheta
 		names(ans$initTheta) <- names(z$coefficients)
 		}
+        ans$specMod <- object$specMod
 	class(ans) <- "summary.gmm"
 	ans
 	}
@@ -51,6 +52,7 @@
 	pvfstat <- 1-pf(fstat,df1, df2)
 	names(fstat) <- colnames(object$dat$x)[(object$dat$ny+1):(object$dat$ny+k)]
 	ans$fstatistic <- list(fstat = fstat, pvfstat = pvfstat, df1 = df1, df2 = df2)
+        ans$specMod <- object$specMod
 	class(ans) <- "summary.tsls"
 	return(ans)
 	}
@@ -95,6 +97,7 @@
 		print(x$initTheta)
 		cat("\n")
 		}
+        cat(x$specMod)
 	if(!is.null(x$algoInfo))
 		{	
 		cat("#############\n")
@@ -159,6 +162,7 @@
 	cat("\n")
 	if(!is.null(x$algoInfo$convergence))
 		cat("Convergence code = ", x$algoInfo$convergence,"\n")
+	cat(x$specMod)
 	invisible(x)
 	}
 

Modified: pkg/gmm/R/getModel.R
===================================================================
--- pkg/gmm/R/getModel.R	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/R/getModel.R	2012-04-13 17:28:53 UTC (rev 50)
@@ -16,6 +16,72 @@
   UseMethod("getModel")
   }
 
+getModel.constGmm <- function(object, ...)
+  {
+  class(object) <- "baseGmm"
+  obj <- getModel(object)
+	
+  if (!is.null(object$t0))
+	{
+	if (!is.null(dim(object$eqConst)))
+		stop("When t0 is provided, eqConst must be a vector")
+	if (length(object$eqConst)>=length(object$t0))
+		stop("Too many constraints")
+        if (is.character(object$eqConst))
+		{
+		if (is.null(names(object$t0)))
+		   stop("t0 must be a named vector if you want eqConst to be names")
+		if (any(!(object$eqConst %in% names(object$t0))))
+		   stop("Wrong coefficient names in eqConst")
+		object$eqConst <- sort(match(object$eqConst,names(object$t0)))
+		}
+	restTet <- object$t0[object$eqConst]
+	obj$t0 <- object$t0[-object$eqConst]
+	object$eqConst <- cbind(object$eqConst,restTet)	
+	}  else {
+	if (is.null(dim(object$eqConst)))
+		stop("When t0 is not provided, eqConst must be a 2xq matrix")
+	}
+  rownames(object$eqConst) <- obj$namesCoef[object$eqConst[,1]]
+  if(is(object$g, "formula"))
+	{
+	if (obj$x$ny>1)
+	  stop("Constrained GMM not implemented yet for system of equations")
+	x <- as.matrix(obj$x$x[,1+(object$eqConst[,1])])%*%object$eqConst[,2]
+	obj$x$x <- obj$x$x[,-(1+(object$eqConst[,1]))]
+	obj$x$x[,1] <- obj$x$x[,1]-x
+	obj$x$k <- obj$x$k-nrow(object$eqConst)
+	if (obj$x$k<=0)
+		stop("Nothing to estimate")
+	attr(obj$x,"eqConst") <- list(eqConst = object$eqConst)
+	} else {
+	attr(obj$x,"eqConst") <- list(unConstg = obj$g, unConstgradv = obj$gradv, eqConst = object$eqConst)   	   	
+	obj$g <- function(tet, dat)
+		{
+		resTet <- attr(dat,"eqConst")$eqConst
+		tet2 <- vector(length=length(tet)+length(resTet))
+		tet2[resTet[,1]] <- resTet[,2]
+		tet2[-resTet[,1]] <- tet
+		attr(dat,"eqConst")$unConstg(tet2, dat)
+		}
+	obj$gradv <- function(tet, dat)
+		{
+		resTet <- attr(dat,"eqConst")$eqConst
+		tet2 <- vector(length=length(tet)+length(resTet))
+		tet2[resTet[,1]] <- resTet[,2]
+		tet2[-resTet[,1]] <- tet
+		attr(dat,"eqConst")$unConstgradv(tet2, dat)[,-resTet[,1]]
+		}
+	}
+  obj$namesCoef <- obj$namesCoef[-object$eqConst[,1]]
+  obj$type <- paste(obj$type,"(with equality constraints)",sep=" ")	
+  clname <-  strsplit(class(obj),"constGmm")
+  mess <- paste(rownames(object$eqConst), " = " , object$eqConst[,2], "\n",collapse="")
+  mess <- paste("#### Equality constraints ####\n",mess,"##############################\n\n",sep="")
+  obj$specMod <- mess                                         
+  return(obj)
+  }
+
 getModel.baseGmm <- function(object, ...)
   {
   if(is(object$g, "formula"))
@@ -64,11 +130,30 @@
       dgb <- -(t(x[,(ny+k+1):(ny+k+nh)]) %*% x[,(ny+1):(ny+k)]) %x% diag(rep(1,ny))/nrow(x)
       return(dgb)
       }
+
+    namex <- colnames(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
+    nameh <- colnames(dat$x[,(dat$ny+dat$k+1):(dat$ny+dat$k+dat$nh)])
+ 
+    if (dat$ny > 1)
+      {
+      namey <- colnames(dat$x[,1:dat$ny])
+      object$namesCoef <- paste(rep(namey, dat$k), "_", rep(namex, rep(dat$ny, dat$k)), sep = "")
+      object$namesgt <- paste(rep(namey, dat$nh), "_", rep(nameh, rep(dat$ny, dat$nh)), sep = "")
+      } else {
+      object$namesCoef <- namex
+      object$namesgt <- nameh
+      }
     object$g <- g
     object$x <- dat
     }
   else
     {
+    k <- length(object$t0)
+    if(is.null(names(object$t0)))
+       object$namesCoef <- paste("Theta[" ,1:k, "]", sep = "")
+    else
+       object$namesCoef <- names(object$t0)
+
     if(is.null(object$weightsMatrix))
       clname <- paste(class(object), "." ,object$type, sep = "")
     else

Modified: pkg/gmm/R/gmm.R
===================================================================
--- pkg/gmm/R/gmm.R	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/R/gmm.R	2012-04-13 17:28:53 UTC (rev 50)
@@ -14,7 +14,7 @@
 gmm <- function(g,x,t0=NULL,gradv=NULL, type=c("twoStep","cue","iterative"), wmatrix = c("optimal","ident"),  vcov=c("HAC","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"),
-	      model=TRUE, X=FALSE, Y=FALSE, TypeGmm = "baseGmm", centeredVcov = TRUE, weightsMatrix = NULL, traceIter = FALSE, data, ...)
+	      model=TRUE, X=FALSE, Y=FALSE, TypeGmm = "baseGmm", centeredVcov = TRUE, weightsMatrix = NULL, traceIter = FALSE, data, eqConst = NULL, ...)
 {
 
 type <- match.arg(type)
@@ -23,6 +23,9 @@
 wmatrix <- match.arg(wmatrix)
 optfct <- match.arg(optfct)
 
+if (!is.null(eqConst))
+	TypeGmm <- "constGmm"
+
 if(vcov=="TrueFixed" & is.null(weightsMatrix))
 	stop("TrueFixed vcov only for fixed weighting matrix")
 if(!is.null(weightsMatrix))
@@ -33,9 +36,9 @@
 all_args<-list(data = data, g = g, x = x, t0 = t0, gradv = gradv, type = type, wmatrix = wmatrix, vcov = vcov, kernel = kernel,
                    crit = crit, bw = bw, prewhite = prewhite, ar.method = ar.method, approx = approx, 
                    weightsMatrix = weightsMatrix, centeredVcov = centeredVcov,
-                   tol = tol, itermax = itermax, optfct = optfct, model = model, X = X, Y = Y, call = match.call(), traceIter = traceIter)
+                   tol = tol, itermax = itermax, optfct = optfct, model = model, X = X, Y = Y, call = match.call(), traceIter = traceIter, eqConst = eqConst)
 class(all_args)<-TypeGmm
-Model_info<-getModel(all_args)
+Model_info<-getModel(all_args, ...)
 z <- momentEstim(Model_info, ...)
 
 z <- FinRes(z, Model_info)

Modified: pkg/gmm/R/momentEstim.R
===================================================================
--- pkg/gmm/R/momentEstim.R	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/R/momentEstim.R	2012-04-13 17:28:53 UTC (rev 50)
@@ -143,11 +143,6 @@
 	z$algoInfo <- list(convergence = res2$convergence, counts = res2$evaluations, message = res2$message)
     }
 
-  if(is.null(names(P$t0)))
-    names(z$coefficients) <- paste("Theta[" ,1:k, "]", sep = "")
-  else
-    names(z$coefficients) <- names(P$t0)
-
   if(P$gradvf)
     z$G <- P$gradv(z$coefficients, P$x)
   else
@@ -159,7 +154,11 @@
   z$iid <- P$iid
   z$g <- P$g
 
+  names(z$coefficients) <- P$namesCoef
+  if (is.null(colnames(z$gt)))
+	colnames(z$gt) <- paste("gt",1:ncol(z$gt),sep="")
   class(z) <- paste(P$TypeGmm,".res",sep="")	
+  z$specMod <- P$specMod 
   return(z)
   }
 
@@ -208,10 +207,9 @@
     }
   z$gt <- g(z$coefficients, dat) 
   b <- z$coefficients
-  y <- as.matrix(model.response(dat$mf, "numeric"))
-  ny <- dat$ny
+  y <- as.matrix(dat$x[,1:dat$ny])
   b <- t(matrix(b, nrow = dat$ny))
-  x <- as.matrix(model.matrix(dat$mt, dat$mf, NULL))
+  x <- as.matrix(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
   yhat <- x %*% b
   z$fitted.values <- yhat	
   z$residuals <- y - yhat	
@@ -223,27 +221,15 @@
   z$iid <- P$iid
   z$g <- P$g
   z$G <- P$gradv(dat) 
-
   
-  namex <- colnames(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
-  nameh <- colnames(dat$x[,(dat$ny+dat$k+1):(dat$ny+dat$k+dat$nh)])
+  names(z$coefficients) <- P$namesCoef
+  colnames(z$gt) <- P$namesgt
  
-  if (dat$ny > 1)
-    {
-    namey <- colnames(dat$x[,1:dat$ny])
-    names(z$coefficients) <- paste(rep(namey, dat$k), "_", rep(namex, rep(dat$ny, dat$k)), sep = "")
-    colnames(z$gt) <- paste(rep(namey, dat$nh), "_", rep(nameh, rep(dat$ny, dat$nh)), sep = "")
-    }
- 
-  if (dat$ny == 1)
-    {
-    names(z$coefficients) <- namex
-    colnames(z$gt) <- nameh
-    }
   if (P$vcov == "iid" & P$wmatrix != "ident")
 	z$fsRes <- res2$fsRes
 
   class(z) <- paste(P$TypeGmm,".res",sep="")
+  z$specMod <- P$specMod
   return(z)	
   }
 
@@ -306,10 +292,9 @@
    }
   z$gt <- g(z$coefficients, dat) 
   b <- z$coefficients
-  y <- as.matrix(model.response(dat$mf, "numeric"))
-  ny <- dat$ny
+  y <- as.matrix(dat$x[,1:dat$ny])
   b <- t(matrix(b, nrow = dat$ny))
-  x <- as.matrix(model.matrix(dat$mt, dat$mf, NULL))
+  x <- as.matrix(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
   yhat <- x %*% b
   z$fitted.values <- yhat	
   z$residuals <- y - yhat	
@@ -322,22 +307,11 @@
   z$g <- P$g
   z$G <- P$gradv(dat) 
 
-  namex <- colnames(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
-  nameh <- colnames(dat$x[,(dat$ny+dat$k+1):(dat$ny+dat$k+dat$nh)])
- 
-  if (dat$ny > 1)
-    {
-    namey <- colnames(dat$x[,1:dat$ny])
-    names(z$coefficients) <- paste(rep(namey, dat$k), "_", rep(namex, rep(dat$ny, dat$k)), sep = "")
-    colnames(z$gt) <- paste(rep(namey, dat$nh), "_", rep(nameh, rep(dat$ny, dat$nh)), sep = "")
-    }
- 
-  if (dat$ny == 1)
-    {
-    names(z$coefficients) <- namex
-    colnames(z$gt) <- nameh
-    }
+  names(z$coefficients) <- P$namesCoef
+  colnames(z$gt) <- P$namesgt
+
   class(z) <- paste(P$TypeGmm,".res",sep="")
+  z$specMod <- P$specMod
   return(z)	
   }
 
@@ -487,10 +461,7 @@
 
     }
 
-  if(is.null(names(P$t0)))
-    names(z$coefficients) <- paste("Theta[" ,1:k, "]", sep = "")
-  else
-    names(z$coefficients) <- names(P$t0)
+  
 
   if(P$gradvf)
     z$G <- P$gradv(z$coefficients, P$x)
@@ -503,6 +474,10 @@
   z$iid <- P$iid
   z$g <- P$g
  
+  names(z$coefficients) <- P$namesCoef
+  if (is.null(colnames(z$gt)))
+	colnames(z$gt) <- paste("gt",1:ncol(z$gt),sep="")
+  z$specMod <- P$specMod
   class(z) <- paste(P$TypeGmm,".res",sep="")	
   return(z)
   }
@@ -581,10 +556,9 @@
 
   z$gt <- g(z$coefficients, dat) 
   b <- z$coefficients
-  y <- as.matrix(model.response(dat$mf, "numeric"))
-  ny <- dat$ny
+  y <- as.matrix(dat$x[,1:dat$ny])
   b <- t(matrix(b, nrow = dat$ny))
-  x <- as.matrix(model.matrix(dat$mt, dat$mf, NULL))
+  x <- as.matrix(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
   yhat <- x %*% b
   z$dat <- dat 
   z$fitted.values <- yhat	
@@ -597,24 +571,12 @@
   z$iid <- P$iid
   z$g <- P$g
   z$G <- P$gradv(dat) 
-
+  z$specMod <- P$specMod
   z$cue <- list(weights=P$fixedKernW,message=P$weightMessage)
   
-  namex <- colnames(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
-  nameh <- colnames(dat$x[,(dat$ny+dat$k+1):(dat$ny+dat$k+dat$nh)])
- 
-  if (dat$ny > 1)
-    {
-    namey <- colnames(dat$x[,1:dat$ny])
-    names(z$coefficients) <- paste(rep(namey, dat$k), "_", rep(namex, rep(dat$ny, dat$k)), sep = "")
-    colnames(z$gt) <- paste(rep(namey, dat$nh), "_", rep(nameh, rep(dat$ny, dat$nh)), sep = "")
-    }
- 
-  if (dat$ny == 1)
-    {
-    names(z$coefficients) <- namex
-    colnames(z$gt) <- nameh
-    }
+  names(z$coefficients) <- P$namesCoef
+  colnames(z$gt) <- P$namesgt
+
   class(z) <- paste(P$TypeGmm,".res",sep="")
   return(z)	
   }
@@ -677,11 +639,6 @@
 
     }
 
-  if(is.null(names(P$t0)))
-    names(z$coefficients) <- paste("Theta[" ,1:k, "]", sep = "")
-  else
-    names(z$coefficients) <- names(P$t0)
-
   if(P$gradvf)
     z$G <- P$gradv(z$coefficients, P$x)
   else
@@ -693,8 +650,11 @@
   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$specMod <- P$specMod
   class(z) <- paste(P$TypeGmm, ".res", sep = "")	
   return(z)
   }
@@ -911,10 +871,9 @@
 
   z$gt <- g(z$coefficients, dat) 
   b <- z$coefficients
-  y <- as.matrix(model.response(dat$mf, "numeric"))
-  ny <- dat$ny
+  y <- as.matrix(dat$x[,1:dat$ny])
   b <- t(matrix(b, nrow = dat$ny))
-  x <- as.matrix(model.matrix(dat$mt, dat$mf, NULL))
+  x <- as.matrix(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
   yhat <- x %*% b
   z$dat <- dat 
   z$fitted.values <- yhat	
@@ -928,21 +887,10 @@
   z$g <- P$g
   z$G <- P$gradv(dat) 
 
-  namex <- colnames(dat$x[,(dat$ny+1):(dat$ny+dat$k)])
-  nameh <- colnames(dat$x[,(dat$ny+dat$k+1):(dat$ny+dat$k+dat$nh)])
- 
-  if (dat$ny > 1)
-    {
-    namey <- colnames(dat$x[,1:dat$ny])
-    names(z$coefficients) <- paste(rep(namey, dat$k), "_", rep(namex, rep(dat$ny, dat$k)), sep = "")
-    colnames(z$gt) <- paste(rep(namey, dat$nh), "_", rep(nameh, rep(dat$ny, dat$nh)), sep = "")
-    }
- 
-  if (dat$ny == 1)
-    {
-    names(z$coefficients) <- namex
-    colnames(z$gt) <- nameh
-    }
+  names(z$coefficients) <- P$namesCoef
+  colnames(z$gt) <- P$namesgt
+
+  z$specMod <- P$specMod
   class(z) <- paste(P$TypeGmm,".res",sep="")
   return(z)	
   }
@@ -1020,12 +968,6 @@
   else if(P$optfct == "nlminb")
      z$algoInfo <- list(convergence = res2$convergence, counts = res2$evaluations, message = res2$message)
 
-
-  if(is.null(names(P$t0)))
-    names(z$coefficients) <- paste("Theta[" ,1:k, "]", sep = "")
-  else
-    names(z$coefficients) <- names(P$t0)
-
   if(P$gradvf)
     z$G <- P$gradv(z$coefficients, P$x)
   else
@@ -1036,7 +978,10 @@
   z$gradv <- P$gradv
   z$iid <- P$iid
   z$g <- P$g
- 
+  names(z$coefficients) <- P$namesCoef
+  if (is.null(colnames(z$gt)))
+	colnames(z$gt) <- paste("gt",1:ncol(z$gt),sep="") 
+  z$specMod <- P$specMod
   class(z) <- paste(P$TypeGmm,".res",sep="")	
   return(z)
   }

Modified: pkg/gmm/man/getModel.Rd
===================================================================
--- pkg/gmm/man/getModel.Rd	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/man/getModel.Rd	2012-04-13 17:28:53 UTC (rev 50)
@@ -1,12 +1,14 @@
 \name{getModel}
 \alias{getModel.baseGmm}
 \alias{getModel.baseGel}
+\alias{getModel.constGmm}
 \title{Method for setting the properties of a model}
 \description{
 It collects what is needed by the method \code{momentEstim} (see details). 
 }
 \usage{
 \method{getModel}{baseGmm}(object, ...)
+\method{getModel}{baseGel}(object, ...)
 }
 \arguments{
 \item{object}{An object of class \code{baseGmm} }

Modified: pkg/gmm/man/gmm.Rd
===================================================================
--- pkg/gmm/man/gmm.Rd	2012-04-12 16:58:12 UTC (rev 49)
+++ pkg/gmm/man/gmm.Rd	2012-04-13 17:28:53 UTC (rev 50)
@@ -14,7 +14,7 @@
 "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"), model=TRUE, X=FALSE, Y=FALSE, 
-TypeGmm = "baseGmm", centeredVcov = TRUE, weightsMatrix = NULL, traceIter = FALSE, data,  ...)
+TypeGmm = "baseGmm", centeredVcov = TRUE, weightsMatrix = NULL, traceIter = FALSE, data, eqConst = NULL, ...)
 }
 \arguments{
 \item{g}{A function of the form \eqn{g(\theta,x)} and which returns a \eqn{n \times q} matrix with typical element \eqn{g_i(\theta,x_t)} for \eqn{i=1,...q} and \eqn{t=1,...,n}. This matrix is then used to build the q sample moment conditions. It can also be a formula if the model is linear (see details below).}
@@ -23,7 +23,7 @@
 
 \item{t0}{A \eqn{k \times 1} vector of starting values. It is required only when "g" is a function because only then a numerical algorithm is used to minimize the objective function. If the dimension of \eqn{\theta} is one, see the argument "optfct".}
 
-\item{gradv}{A function of the form \eqn{G(\theta,x)} which returns a \eqn{q\times k} matrix of derivatives of \eqn{\bar{g}(\theta)} with respect to \eqn{\theta}. By default, the numerical algorithm \code{numericDeriv} is used. It is of course strongly suggested to provide this function when it is possible. This gradiant is used to compute the asymptotic covariance matrix of \eqn{\hat{\theta}} and to obtain the analytical gradiant of the objective function if the method is set to "CG" or "BFGS" in \code{\link{optim}} and if "type" is not set to "cue". If "g" is a formula, the gradiant is not required (see the details below).}
+\item{gradv}{A function of the form \eqn{G(\theta,x)} which returns a \eqn{q\times k} matrix of derivatives of \eqn{\bar{g}(\theta)} with respect to \eqn{\theta}. By default, the numerical algorithm \code{numericDeriv} is used. It is of course strongly suggested to provide this function when it is possible. This gradient is used to compute the asymptotic covariance matrix of \eqn{\hat{\theta}} and to obtain the analytical gradient of the objective function if the method is set to "CG" or "BFGS" in \code{\link{optim}} and if "type" is not set to "cue". If "g" is a formula, the gradiant is not required (see the details below).}
 
 \item{type}{The GMM method: "twostep" is the two step GMM proposed by Hansen(1982) and the "cue" and "iterative" are respectively the continuous updated and the iterative GMM proposed by Hansen, Eaton et Yaron (1996)}
 
@@ -33,7 +33,7 @@
 
 \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{crit}{The stoping rule for the iterative GMM. It can be reduce to increase the precision.}
+\item{crit}{The stopping rule for the iterative GMM. It can be reduce to increase the precision.}
 
 \item{bw}{The method to compute the bandwidth parameter. By default it is \code{\link{bwAndrews}} which is proposed by Andrews (1991). The alternative is \code{\link{bwNeweyWest}} of Newey-West(1994).}
 
@@ -47,11 +47,11 @@
 
 \item{itermax}{The maximum number of iterations for the iterative GMM. It is unlikely that the algorithm does not converge but we keep it as a safety.}
 
-\item{optfct}{Only when the dimension of \eqn{\theta} is 1, you can choose between the algorithm \code{\link{optim}} or \code{\link{optimize}}. In that case, the former is unreliable. If \code{\link{optimize}} is chosen, "t0" must be \eqn{1\times 2} which represents the interval in which the algorithm seeks the solution. It is also possible to choose the \code{\link{nlminb}} algorithm. In that case, borns for the coefficients can be set by the options \code{upper=} and \code{lower=}.}
+\item{optfct}{Only when the dimension of \eqn{\theta} is 1, you can choose between the algorithm \code{\link{optim}} or \code{\link{optimize}}. In that case, the former is unreliable. If \code{\link{optimize}} is chosen, "t0" must be \eqn{1\times 2} which represents the interval in which the algorithm seeks the solution. It is also possible to choose the \code{\link{nlminb}} algorithm. In that case, boundaries for the coefficients can be set by the options \code{upper=} and \code{lower=}.}
 
-\item{model, X, Y}{logicals.  If \code{TRUE} the corresponding components of the fit (the model frame, the model matrix, the response) are returned if g is a formula.}
+\item{model, X, Y}{logical.  If \code{TRUE} the corresponding components of the fit (the model frame, the model matrix, the response) are returned if g is a formula.}
 
-\item{TypeGmm}{The name of the class object created by the method \code{getModel}. It allows developers to extand the package and create other GMM methods.}
+\item{TypeGmm}{The name of the class object created by the method \code{getModel}. It allows developers to extend the package and create other GMM methods.}
 
 \item{centeredVcov}{Should the moment function be centered when computing its covariance matrix. Doing so may improve inference.}
 
@@ -59,15 +59,17 @@
 
 \item{traceIter}{Tracing information for GMM of type "iter"}
 
-\item{data}{A data.frame or a matrix with column names (Optionnal). }
+\item{data}{A data.frame or a matrix with column names (Optional). }
 
+\item{eqConst}{Either a named vector (if "g" is a function), a simple vector for the nonlinear case indicating which of the \eqn{\theta_0} is restricted, or a qx2 vector defining equality constraints of the form \eqn{\theta_i=c_i}. See below for an example.}
+
 \item{...}{More options to give to \code{\link{optim}}.}
 }
 
 \details{
 If we want to estimate a model like \eqn{Y_t = \theta_1 + X_{2t} \theta_2 + \cdots + X_{k}\theta_k + \epsilon_t} using the moment conditions \eqn{Cov(\epsilon_tH_t)=0}, where \eqn{H_t} is a vector of \eqn{Nh} instruments, than we can define "g" like we do for \code{\link{lm}}. We would have \eqn{g = y ~\tilde{}~ x2+x3+ \cdots +xk} and the argument "x" above would become the matrix H of instruments. As for \code{\link{lm}}, \eqn{Y_t} can be a \eqn{Ny \times 1} vector which would imply that \eqn{k=Nh \times Ny}. The intercept is included by default so you do not have to add a column of ones to the matrix \eqn{H}. You do not need to provide the gradiant in that case since in that case it is embedded in \code{\link{gmm}}. The intercept can be removed by adding -1 to the formula. In that case, the column of ones need to be added manually to H. It is also possible to express "x" as a formula. For example, if the instruments are \eqn{\{1,z_1,z_2,z_3\}}, we can set "x" to \eqn{\tilde{} z1+z2+z3}. By default, a column of ones is added. To remove it, set "x" to \eqn{\tilde{}z1+z2+z3-1}. 
 
-The following explains the last example bellow. Thanks to Dieter Rozenich, a student from the Vienna Universtiy of Economics and Business Administration. He suggested that it would help to understand the implementation of the jacobian.  
+The following explains the last example bellow. Thanks to Dieter Rozenich, a student from the Vienna University of Economics and Business Administration. He suggested that it would help to understand the implementation of the Jacobian.  
 
 For the two parameters of a normal distribution \eqn{(\mu,\sigma)} we have the following three moment conditions:
 \deqn{
@@ -257,7 +259,32 @@
 res4 <- gmm(d$Y~d$X-1,~d$Z-1,vcov="iid")
 res4
 
+### Examples with equality constraint 
+######################################
 
+# Random numbers of a normal distribution
 
+## Not run:
+# The following works but produces warning message because the dimension of coef is 1
+# Brent should be used
+
+# without named vector
+gmm(g, x, c(4, 0), grad = Dg, eqCons=1)
+# with named vector
+gmm(g, x, c(mu=4, sig=2), grad = Dg, eqCons="sig")
+
+## End(Not run)
+
+gmm(g, x, c(4, 0), grad = Dg, eqCons=1,method="Brent",lower=0,upper=6)
+gmm(g, x, c(mu=4, sig=2), grad = Dg, eqCons="sig",method="Brent",lower=0,upper=6)
+
+# Example with formula
+# first coef = 0 and second coef = 1
+# Only available for one dimensional yt
+
+z <- z[,1]
+res2 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, eqConst = matrix(c(1,2,0,1),2,2))
+res2
+
 }
 



More information about the Gmm-commits mailing list