Title: | Generalized Method of Moments and Generalized Empirical Likelihood |
---|---|
Description: | It is a complete suite to estimate models based on moment conditions. It includes the two step Generalized method of moments (Hansen 1982; <doi:10.2307/1912775>), the iterated GMM and continuous updated estimator (Hansen, Eaton and Yaron 1996; <doi:10.2307/1392442>) and several methods that belong to the Generalized Empirical Likelihood family of estimators (Smith 1997; <doi:10.1111/j.0013-0133.1997.174.x>, 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>). |
Authors: | Pierre Chausse <[email protected]> |
Maintainer: | Pierre Chausse <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.8 |
Built: | 2024-11-11 07:01:02 UTC |
Source: | CRAN |
Function to estimate the average treatment effect with the sample being balanced by GEL.
ATEgel(g, balm, w=NULL, y=NULL, treat=NULL, tet0=NULL,momType=c("bal","balSample","ATT"), popMom = NULL, family=c("linear","logit", "probit"), type = c("EL", "ET", "CUE", "ETEL", "HD", "ETHD", "RCUE"), tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, optfct = c("optim", "nlminb"), optlam = c("nlminb", "optim", "iter", "Wu"), data=NULL, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, ...) checkConv(obj, tolConv=1e-4, verbose=TRUE, ...)
ATEgel(g, balm, w=NULL, y=NULL, treat=NULL, tet0=NULL,momType=c("bal","balSample","ATT"), popMom = NULL, family=c("linear","logit", "probit"), type = c("EL", "ET", "CUE", "ETEL", "HD", "ETHD", "RCUE"), tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, optfct = c("optim", "nlminb"), optlam = c("nlminb", "optim", "iter", "Wu"), data=NULL, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, ...) checkConv(obj, tolConv=1e-4, verbose=TRUE, ...)
g |
A formula as |
obj |
Object of class |
balm |
A formula for the moments to be balanced between the treated and control groups (see details) |
y |
The response variable when |
treat |
The treatment indicator when |
w |
A formula to add covariates to the main regression. When
|
tet0 |
A |
momType |
How the moments of the covariates should be balanced. By default, it is simply balanced without restriction. Alternatively, moments can be set equal to the sample moments of the whole sample, or to the sample moments of the treated group. The later will produce the average treatment effect of the treated (ATT) |
popMom |
A vector of population moments to use for balancing. It can be used of those moments are available from a census, for example. When available, it greatly improves efficiency. |
family |
By default, the outcome is linearly related to the treatment indicators. If the outcome is binary, it is possible to use the estimating equations of either the logit or probit model. |
type |
"EL" for empirical likelihood, "ET" for exponential tilting, "CUE" for continuous updated estimator, "ETEL" for exponentially tilted empirical likelihood of Schennach(2007), "HD" for Hellinger Distance of Kitamura-Otsu-Evdokimov (2013), and "ETHD" for the exponentially tilted Hellinger distance of Antoine-Dovonon (2015). "RCUE" is a restricted version of "CUE" in which the probabilities are bounded below by zero. In that case, an analytical Kuhn-Tucker method is used to find the solution. |
tol_lam |
Tolerance for |
maxiterlam |
The algorithm to compute |
tol_obj |
Tolerance for the gradiant of the objective function to
compute |
optfct |
Algorithm used for the parameter estimates |
tol_mom |
It is the tolerance for the moment condition
|
optlam |
Algorithm used to solve for the lagrange multiplier in
|
data |
A data.frame or a matrix with column names (Optional). |
Lambdacontrol |
Controls for the optimization of the vector of
Lagrange multipliers used by either |
model , X , Y
|
logicals. If |
verbose |
If TRUE, a summary of the convergence is printed |
tolConv |
The tolerance for comparing moments between groups |
... |
More options to give to |
We want to estimate the model , where
is the treatment effect. GEL is
used to balance the sample based on the argument
x
above.
For example, if we want the sample mean of x1
and x2
to be
balanced between the treated and control, we set x
to
~x1+x2
. If we want the sample mean of x1
, x2
,
x1*x2
, x1^2
and x2^2
, we set x
to
~x1*x2 + I(x1^2) + I(x2^2)
.
'gel' returns an object of 'class' '"ategel"'
The functions 'summary' is used to obtain and print a summary of the results.
The object of class "ategel" is a list containing the same elements
contained in objects of class gel
.
Lee, Seojeong (2016), Asymptotic refinements of misspecified-robust bootstrap for GEL estimators, Journal of Econometrics, 192, 86–104.
Schennach, Susanne, M. (2007), Point Estimation with Exponentially Tilted Empirical Likelihood. Econometrica, 35, 634-672.
Wu, C. (2005), Algorithms and R codes for the pseudo empirical likelihood method in survey sampling. Survey Methodology, 31(2), page 239.
Chausse, P. (2010), Computing Generalized Method of Moments and Generalized Empirical Likelihood with R. Journal of Statistical Software, 34(11), 1–35. URL doi:10.18637/jss.v034.i11.
Chausse, P. and Giurcanu, M. and Luta, G. (2021) Estimating the Average Causal Effect using Generalized Empirical Likelihood Methods, Work in progress.
data(nsw) # Scale income nsw$re78 <- nsw$re78/1000 nsw$re75 <- nsw$re75/1000 res <- ATEgel(re78~treat, ~age+ed+black+hisp+married+nodeg+re75, data=nsw,type="ET") summary(res) chk <- checkConv(res) res2 <- ATEgel(re78~treat, ~age+ed+black+hisp+married+nodeg+re75, data=nsw,type="ET", momType="balSample") summary(res2) chk2 <- checkConv(res2)
data(nsw) # Scale income nsw$re78 <- nsw$re78/1000 nsw$re75 <- nsw$re75/1000 res <- ATEgel(re78~treat, ~age+ed+black+hisp+married+nodeg+re75, data=nsw,type="ET") summary(res) chk <- checkConv(res) res2 <- ATEgel(re78~treat, ~age+ed+black+hisp+married+nodeg+re75, data=nsw,type="ET", momType="balSample") summary(res2) chk2 <- checkConv(res2)
Computes the bread of the sandwich covariance matrix
## S3 method for class 'gmm' bread(x, ...) ## S3 method for class 'gel' bread(x, ...) ## S3 method for class 'tsls' bread(x, ...)
## S3 method for class 'gmm' bread(x, ...) ## S3 method for class 'gel' bread(x, ...) ## S3 method for class 'tsls' bread(x, ...)
x |
A fitted model of class |
... |
Other arguments when |
When the weighting matrix is not the optimal one, the covariance matrix of the estimated coefficients is:
,
where
,
is the matrix of weights, and
is the covariance matrix of the moment function. Therefore, the bread is
, which is the second derivative of the objective function.
The method if not yet available for gel
objects.
A matrix (see details).
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
# See \code{\link{gmm}} for more details on this example. # With the identity matrix # bread is the inverse of (G'G) n <- 1000 x <- rnorm(n, mean = 4, sd = 2) g <- function(tet, x) { m1 <- (tet[1] - x) m2 <- (tet[2]^2 - (x - tet[1])^2) m3 <- x^3 - tet[1]*(tet[1]^2 + 3*tet[2]^2) f <- cbind(m1, m2, m3) return(f) } Dg <- function(tet, x) { jacobian <- matrix(c( 1, 2*(-tet[1]+mean(x)), -3*tet[1]^2-3*tet[2]^2,0, 2*tet[2], -6*tet[1]*tet[2]), nrow=3,ncol=2) return(jacobian) } res <- gmm(g, x, c(0, 0), grad = Dg,weightsMatrix=diag(3)) G <- Dg(res$coef, x) bread(res) solve(crossprod(G))
# See \code{\link{gmm}} for more details on this example. # With the identity matrix # bread is the inverse of (G'G) n <- 1000 x <- rnorm(n, mean = 4, sd = 2) g <- function(tet, x) { m1 <- (tet[1] - x) m2 <- (tet[2]^2 - (x - tet[1])^2) m3 <- x^3 - tet[1]*(tet[1]^2 + 3*tet[2]^2) f <- cbind(m1, m2, m3) return(f) } Dg <- function(tet, x) { jacobian <- matrix(c( 1, 2*(-tet[1]+mean(x)), -3*tet[1]^2-3*tet[2]^2,0, 2*tet[2], -6*tet[1]*tet[2]), nrow=3,ncol=2) return(jacobian) } res <- gmm(g, x, c(0, 0), grad = Dg,weightsMatrix=diag(3)) G <- Dg(res$coef, x) bread(res) solve(crossprod(G))
It computes the optimal bandwidth for the HAC estimation of the covariance matrix of the moment conditions. The bandwidth was shown by Wilhelm (2005) to be the one that minimizes the MSE of the GMM estimator.
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())
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())
x |
An object of class |
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). |
kernel |
type of kernel used to compute the covariance matrix of the vector of sample moment conditions (see |
approx |
A character specifying the approximation method if the bandwidth has to be chosen by |
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) |
prewhite |
logical or integer. Should the estimating functions be prewhitened? If |
ar.method |
character. The |
data |
an optional data frame containing the variables in the 'order.by' model. |
The function 'bwWilhelm' returns the optimal bandwidth.
The function was written by Daniel Wilhelm and is based on bwAndrews.
Wilhelm, D. (2015), Optimal Bandwidth Selection for Robust Generalized Method of Moments Estimation. Econometric Theory, 31, 1054–1077
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
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) ## 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)
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) ## 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)
It computes the theoretical characteristic function of a stable distribution for two different parametrizations. It is used in the vignette to illustrate the estimation of the parameters using GMM.
charStable(theta, tau, pm = 0)
charStable(theta, tau, pm = 0)
theta |
Vector of parameters of the stable distribution. See details. |
tau |
A vector of numbers at which the function is evaluated. |
pm |
The type of parametization. It takes the values 0 or 1. |
The function returns the vector defined as
, where
is a vector of real numbers,
is the imaginary number,
is a stable random variable with parameters
=
and
pm
is the type of parametrization. The vector of parameters are the characteristic exponent, the skewness, the scale and the location parameters, respectively. The restrictions on the parameters are: ,
and
. For mode details see Nolan(2009).
It returns a vector of complex numbers with the dimension equals to length(tau)
.
Nolan J. P. (2020), Univariate Stable Distributions - Models for Heavy Tailed Data. Springer Series in Operations Research and Financial Engineering. URL https://edspace.american.edu/jpnolan/stable/.
# GMM is like GLS for linear models without endogeneity problems pm <- 0 theta <- c(1.5,.5,1,0) tau <- seq(-3, 3, length.out = 20) char_fct <- charStable(theta, tau, pm)
# GMM is like GLS for linear models without endogeneity problems pm <- 0 theta <- c(1.5,.5,1,0) tau <- seq(-3, 3, length.out = 20) char_fct <- charStable(theta, tau, pm)
It extracts the coefficients from gel
or gmm
objects.
## S3 method for class 'gmm' coef(object, ...) ## S3 method for class 'gel' coef(object, lambda = FALSE, ...)
## S3 method for class 'gmm' coef(object, ...) ## S3 method for class 'gel' coef(object, lambda = FALSE, ...)
object |
An object of class |
lambda |
If set to TRUE, the lagrange multipliers are extracted instead of the vector of coefficients |
... |
Other arguments when |
Vector of coefficients
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) coef(res) coef(res, lambda = TRUE) ################### res <- gmm(g, x) coef(res)
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) coef(res) coef(res, lambda = TRUE) ################### res <- gmm(g, x) coef(res)
It produces confidence intervals for the coefficients from gel
or gmm
estimation.
## S3 method for class 'gel' confint(object, parm, level = 0.95, lambda = FALSE, type = c("Wald", "invLR", "invLM", "invJ"), fact = 3, corr = NULL, ...) ## S3 method for class 'gmm' confint(object, parm, level = 0.95, ...) ## S3 method for class 'ategel' confint(object, parm, level = 0.95, lambda = FALSE, type = c("Wald", "invLR", "invLM", "invJ"), fact = 3, corr = NULL, robToMiss=TRUE, ...) ## S3 method for class 'confint' print(x, digits = 5, ...)
## S3 method for class 'gel' confint(object, parm, level = 0.95, lambda = FALSE, type = c("Wald", "invLR", "invLM", "invJ"), fact = 3, corr = NULL, ...) ## S3 method for class 'gmm' confint(object, parm, level = 0.95, ...) ## S3 method for class 'ategel' confint(object, parm, level = 0.95, lambda = FALSE, type = c("Wald", "invLR", "invLM", "invJ"), fact = 3, corr = NULL, robToMiss=TRUE, ...) ## S3 method for class 'confint' print(x, digits = 5, ...)
object |
An object of class |
parm |
A specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
The confidence level |
lambda |
If set to TRUE, the confidence intervals for the Lagrange multipliers are produced. |
type |
'Wald' is the usual symetric confidence interval. The thee others are based on the inversion of the LR, LM, and J tests. |
fact |
This parameter control the span of search for the inversion of the test. By default we search within plus or minus 3 times the standard error of the coefficient estimate. |
corr |
This numeric scalar is meant to apply a correction to the critical value, such as a Bartlett correction. This value depends on the model (See Owen; 2001) |
x |
An object of class |
digits |
The number of digits to be printed |
robToMiss |
If |
... |
Other arguments when |
It returns a matrix with the first column being the lower bound and the second the upper bound.
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054, Hansen, L.P. and Heaton, J. and Yaron, A.(1996), Finit-Sample Properties of Some Alternative GMM Estimators. Journal of Business and Economic Statistics, 14 262-280. Owen, A.B. (2001), Empirical Likelihood. Monographs on Statistics and Applied Probability 92, Chapman and Hall/CRC
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) resGel <- gel(g, x, t0) confint(resGel) confint(resGel, level = 0.90) confint(resGel, lambda = TRUE) ######################## resGmm <- gmm(g, x) confint(resGmm) confint(resGmm, level = 0.90) ## Confidence interval with inversion of the LR, LM or J test. ############################################################## set.seed(112233) x <- rt(40, 3) y <- x+rt(40,3) # Simple interval on the mean res <- gel(x~1, ~1, method="Brent", lower=-4, upper=4) confint(res, type = "invLR") confint(res) # Using a Bartlett correction k <- mean((x-mean(x))^4)/sd(x)^4 s <- mean((x-mean(x))^3)/sd(x)^3 a <- k/2-s^2/3 corr <- 1+a/40 confint(res, type = "invLR", corr=corr) # Interval on the slope res <- gel(y~x, ~x) confint(res, "x", type="invLR") confint(res, "x")
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) resGel <- gel(g, x, t0) confint(resGel) confint(resGel, level = 0.90) confint(resGel, lambda = TRUE) ######################## resGmm <- gmm(g, x) confint(resGmm) confint(resGmm, level = 0.90) ## Confidence interval with inversion of the LR, LM or J test. ############################################################## set.seed(112233) x <- rt(40, 3) y <- x+rt(40,3) # Simple interval on the mean res <- gel(x~1, ~1, method="Brent", lower=-4, upper=4) confint(res, type = "invLR") confint(res) # Using a Bartlett correction k <- mean((x-mean(x))^4)/sd(x)^4 s <- mean((x-mean(x))^3)/sd(x)^3 a <- k/2-s^2/3 corr <- 1+a/40 confint(res, type = "invLR", corr=corr) # Interval on the slope res <- gel(y~x, ~x) confint(res, "x", type="invLR") confint(res, "x")
It extracts the matrix of empirical moments so that it can be used by the kernHAC
function.
## S3 method for class 'gmmFct' estfun(x, y = NULL, theta = NULL, ...) ## S3 method for class 'gmm' estfun(x, ...) ## S3 method for class 'gel' estfun(x, ...) ## S3 method for class 'tsls' estfun(x, ...) ## S3 method for class 'tsls' model.matrix(object, ...)
## S3 method for class 'gmmFct' estfun(x, y = NULL, theta = NULL, ...) ## S3 method for class 'gmm' estfun(x, ...) ## S3 method for class 'gel' estfun(x, ...) ## S3 method for class 'tsls' estfun(x, ...) ## S3 method for class 'tsls' model.matrix(object, ...)
x |
A function of the form |
object |
An object of class |
y |
The matrix or vector of data from which the function |
theta |
Vector of parameters if |
... |
Other arguments when |
For estfun.gmmFct
, it returns a matrix with typical element
for
and
. It is only used by
gmm
to obtain the estimates.
For estfun.gmm
, it returns the matrix of first order conditions of , which is a
matrix with the
row being
, where
is
. It allows to compute the sandwich covariance matrix using
kernHAC
or vcovHAC
when is not the optimal matrix.
The method if not yet available for gel
objects.
For tsls, model.matrix and estfun are used by vcov()
to compute different covariance matrices using the sandwich
package. See vcov.tsls
. model.matrix
returns the fitted values frin the first stage regression and esfun
the residuals.
A matrix (see details).
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x,weightsMatrix = diag(5)) gt <- res$gt G <- res$G foc <- gt foc2 <- estfun(res) foc[1:5,] foc2[1:5,]
n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x,weightsMatrix = diag(5)) gt <- res$gt G <- res$G foc <- gt foc2 <- estfun(res) foc[1:5,] foc2[1:5,]
Daily returns on selected stocks, the Market portfolio and factors of Fama and French from 1993-01-05 to 2009-01-30 for CAPM and APT analysis
data(Finance)
data(Finance)
A data frame containing 24 time series. Dates are reported as rownames(). In the following description, company symboles are used.
Returns of WEIS MARKETS INC
Returns of UNISYS CP NEW
Returns of ORBITAL SCIENCES CP
Returns of Mattel, Inc.
Returns of ABAXIS, Inc.
Returns of AT&T INC.
Returns of EMERSON ELEC CO
Returns of Communications Systems Inc.
Returns of Audiovox Corp.
Returns of ZOOM Technologies Inc.
Returns of TIDEWATER INC
Returns of Rogers Corporation
Returns of Graco Inc.
Returns of Panasonic Corporation
Returns of Genesco Inc.
Returns of ENNIS, INC
Returns of FORD MOTOR CO
Returns of FANNIE MAE
Returns of NATIONWIDE HLTH PROP
Returns of ALCOA INC
Risk-free rate of Fama-French
Return of the market portfolio of Fama-French
Factor High-Minus-Low of Fama-French
Factor Small-Minus-Big of Fama-French
Yahoo Finance and https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/
It computes the final results that will be needed to create the object of class gmm
.).
## S3 method for class 'baseGmm.res' FinRes(z, object, ...)
## S3 method for class 'baseGmm.res' FinRes(z, object, ...)
z |
An object of class determined by the method |
object |
An object produced my |
... |
Other argument to be passed to other |
It returns an object of class gmm
. See gmm
for more details.
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
Hansen, L.P. and Heaton, J. and Yaron, A.(1996), Finit-Sample Properties of Some Alternative GMM Estimators. Journal of Business and Economic Statistics, 14 262-280.
Method to extract the fitted values of the model estimated by gel
or gmm
.
## S3 method for class 'gel' fitted(object, ...) ## S3 method for class 'gmm' fitted(object, ...)
## S3 method for class 'gel' fitted(object, ...) ## S3 method for class 'gmm' fitted(object, ...)
object |
An object of class |
... |
Other arguments when |
It returns a matrix of the estimated mean in
g=y~x
as it is done by fitted.lm
.
# GEL can deal with endogeneity problems n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) plot(y, main = "Fitted ARMA with GEL") lines(fitted(res), col = 2) # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) plot(x, y, main = "Fitted model with GMM") lines(x, fitted(res), col = 2) legend("topright", c("Y","Yhat"), col = 1:2, lty = c(1,1))
# GEL can deal with endogeneity problems n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) plot(y, main = "Fitted ARMA with GEL") lines(fitted(res), col = 2) # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) plot(x, y, main = "Fitted model with GMM") lines(x, fitted(res), col = 2) legend("topright", c("Y","Yhat"), col = 1:2, lty = c(1,1))
Method to extract the formula from gel
or gmm
objects.
## S3 method for class 'gel' formula(x, ...) ## S3 method for class 'gmm' formula(x, ...)
## S3 method for class 'gel' formula(x, ...) ## S3 method for class 'gmm' formula(x, ...)
x |
An object of class |
... |
Other arguments to pass to other methods |
## GEL ## n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) formula(res) # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) formula(res)
## GEL ## n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) formula(res) # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) formula(res)
Function to estimate a vector of parameters based on moment conditions using the GEL method as presented by Newey-Smith(2004) and Anatolyev(2005).
gel(g, x, tet0 = NULL, gradv = NULL, smooth = FALSE, type = c("EL","ET","CUE","ETEL","HD","ETHD","RCUE"), kernel = c("Truncated", "Bartlett"), bw = bwAndrews, approx = c("AR(1)", "ARMA(1,1)"), prewhite = 1, ar.method = "ols", tol_weights = 1e-7, tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, constraint = FALSE, optfct = c("optim", "optimize", "nlminb"), optlam = c("nlminb", "optim", "iter", "Wu"), data, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, TypeGel = "baseGel", alpha = NULL, eqConst = NULL, eqConstFullVcov = FALSE, onlyCoefficients=FALSE, ...) evalGel(g, x, tet0, gradv = NULL, smooth = FALSE, type = c("EL", "ET", "CUE", "ETEL", "HD", "ETHD","RCUE"), kernel = c("Truncated", "Bartlett"), bw = bwAndrews, approx = c("AR(1)", "ARMA(1,1)"), prewhite = 1, ar.method = "ols", tol_weights = 1e-7, tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, optlam = c("nlminb", "optim", "iter", "Wu"), data, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, alpha = NULL, ...)
gel(g, x, tet0 = NULL, gradv = NULL, smooth = FALSE, type = c("EL","ET","CUE","ETEL","HD","ETHD","RCUE"), kernel = c("Truncated", "Bartlett"), bw = bwAndrews, approx = c("AR(1)", "ARMA(1,1)"), prewhite = 1, ar.method = "ols", tol_weights = 1e-7, tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, constraint = FALSE, optfct = c("optim", "optimize", "nlminb"), optlam = c("nlminb", "optim", "iter", "Wu"), data, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, TypeGel = "baseGel", alpha = NULL, eqConst = NULL, eqConstFullVcov = FALSE, onlyCoefficients=FALSE, ...) evalGel(g, x, tet0, gradv = NULL, smooth = FALSE, type = c("EL", "ET", "CUE", "ETEL", "HD", "ETHD","RCUE"), kernel = c("Truncated", "Bartlett"), bw = bwAndrews, approx = c("AR(1)", "ARMA(1,1)"), prewhite = 1, ar.method = "ols", tol_weights = 1e-7, tol_lam = 1e-9, tol_obj = 1e-9, tol_mom = 1e-9, maxiterlam = 100, optlam = c("nlminb", "optim", "iter", "Wu"), data, Lambdacontrol = list(), model = TRUE, X = FALSE, Y = FALSE, alpha = NULL, ...)
g |
A function of the form |
tet0 |
A |
x |
The matrix or vector of data from which the function |
gradv |
A function of the form |
smooth |
If set to TRUE, the moment function is smoothed as proposed by Kitamura(1997) |
type |
"EL" for empirical likelihood, "ET" for exponential tilting, "CUE" for continuous updated estimator, "ETEL" for exponentially tilted empirical likelihood of Schennach(2007), "HD" for Hellinger Distance of Kitamura-Otsu-Evdokimov (2013), and "ETHD" for the exponentially tilted Hellinger distance of Antoine-Dovonon (2015). "RCUE" is a restricted version of "CUE" in which the probabilities are bounded below by zero. In that case, an analytical Kuhn-Tucker method is used to find the solution. |
kernel |
type of kernel used to compute the covariance matrix of the vector of sample moment conditions (see |
bw |
The method to compute the bandwidth parameter. By default it is |
prewhite |
logical or integer. Should the estimating functions be prewhitened? If |
ar.method |
character. The |
approx |
a character specifying the approximation method if the bandwidth has to be chosen by |
tol_weights |
numeric. Weights that exceed |
tol_lam |
Tolerance for |
maxiterlam |
The algorithm to compute |
tol_obj |
Tolerance for the gradiant of the objective function to compute |
optfct |
Only when the dimension of |
constraint |
If set to TRUE, the constraint optimization algorithm is used. See |
tol_mom |
It is the tolerance for the moment condition |
optlam |
Algorithm used to solve for the lagrange multiplier in
|
data |
A data.frame or a matrix with column names (Optional). |
Lambdacontrol |
Controls for the optimization of the vector of Lagrange multipliers used by either |
model , X , Y
|
logicals. If |
TypeGel |
The name of the class object created by the method |
alpha |
Regularization coefficient for discrete CGEL estimation (experimental). By setting alpha to any value, the model is estimated by CGEL of type specified by the option |
eqConst |
Either a named vector (if "g" is a function), a simple vector for the nonlinear case indicating which of the |
eqConstFullVcov |
If FALSE, the constrained coefficients are assumed to be fixed and only the covariance of the unconstrained coefficients is computed. If TRUE, the covariance matrix of the full set of coefficients is computed. |
onlyCoefficients |
If |
... |
More options to give to |
If we want to estimate a model like using the moment conditions
, where
is a vector of
instruments, than we can define "g" like we do for
lm
. We would have g = y~x2+x3+...+xk
and the argument "x" above would become the matrix H of instruments. As for lm
, can be a
vector which would imply that
. The intercept is included by default so you do not have to add a column of ones to the matrix
. You do not need to provide the gradiant in that case since in that case it is embedded in
gel
. 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.
If "smooth" is set to TRUE, the sample moment conditions is replaced by:
,
where
,
where
is a truncated parameter that depends on the bandwidth and
are normalized weights so that they sum to 1.
The method solves
evalGel
generates the object of class "gel" for a fixed vector of
parameters. There is no estimation for , but the optimal
vector of Lagrange multipliers
is computed. The objective
function is then the profiled likelihood for a given
. It
can be used to construct a confidence interval by inverting the
likelihood ratio test.
'gel' returns an object of 'class' '"gel"'
The functions 'summary' is used to obtain and print a summary of the results.
The object of class "gel" is a list containing at least the following:
coefficients |
|
residuals |
the residuals, that is response minus fitted values if "g" is a formula. |
fitted.values |
the fitted mean values if "g" is a formula. |
lambda |
|
vcov_par |
the covariance matrix of "coefficients" |
vcov_lambda |
the covariance matrix of "lambda" |
pt |
The implied probabilities |
objective |
the value of the objective function |
conv_lambda |
Convergence code for "lambda" (see |
conv_mes |
Convergence message for "lambda" (see |
conv_par |
Convergence code for "coefficients" (see |
terms |
the |
call |
the matched call. |
y |
if requested, the response used (if "g" is a formula). |
x |
if requested, the model matrix used if "g" is a formula or the data if "g" is a function. |
model |
if requested (the default), the model frame used if "g" is a formula. |
Anatolyev, S. (2005), GMM, GEL, Serial Correlation, and Asymptotic Bias. Econometrica, 73, 983-1002.
Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica, 59, 817–858.
Kitamura, Yuichi (1997), Empirical Likelihood Methods With Weakly Dependent Processes. The Annals of Statistics, 25, 2084-2102.
Kitamura, Y. and Otsu, T. and Evdokimov, K. (2013), Robustness, Infinitesimal Neighborhoods and Moment Restrictions. Econometrica, 81, 1185-1201.
Newey, W.K. and Smith, R.J. (2004), Higher Order Properties of GMM and Generalized Empirical Likelihood Estimators. Econometrica, 72, 219-255.
Smith, R.J. (2004), GEL Criteria for Moment Condition Models. Working paper, CEMMAP.
Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica, 55, 703–708.
Newey WK & West KD (1994), Automatic Lag Selection in Covariance Matrix Estimation. Review of Economic Studies, 61, 631-653.
Schennach, Susanne, M. (2007), Point Estimation with Exponentially Tilted Empirical Likelihood. Econometrica, 35, 634-672.
Wu, C. (2005), Algorithms and R codes for the pseudo empirical likelihood method in survey sampling. Survey Methodology, 31(2), page 239.
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
Chausse (2010), Computing Generalized Method of Moments and Generalized Empirical Likelihood with R. Journal of Statistical Software, 34(11), 1–35. URL doi:10.18637/jss.v034.i11.
Chausse (2011), Generalized Empirical likelihood for a continumm of moment conditions. Working Paper, Department of Economics, University of Waterloo.
# First, an exemple with the fonction g() g <- function(tet, x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } Dg <- function(tet,x) { n <- nrow(x) xx <- cbind(rep(1, (n-6)), x[6:(n-1)], x[5:(n-2)]) H <- cbind(rep(1, (n-6)), x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) f <- -crossprod(H, xx)/(n-6) return(f) } n = 200 phi<-c(.2, .7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) res <- gel(g, x, c(0, .3, .6), grad = Dg) summary(res) # The same model but with g as a formula.... much simpler in that case y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0, .3, .6)) summary(res) # Using evalGel to create the object without estimation res <- evalGel(g, x, res$coefficients)
# First, an exemple with the fonction g() g <- function(tet, x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } Dg <- function(tet,x) { n <- nrow(x) xx <- cbind(rep(1, (n-6)), x[6:(n-1)], x[5:(n-2)]) H <- cbind(rep(1, (n-6)), x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) f <- -crossprod(H, xx)/(n-6) return(f) } n = 200 phi<-c(.2, .7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) res <- gel(g, x, c(0, .3, .6), grad = Dg) summary(res) # The same model but with g as a formula.... much simpler in that case y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0, .3, .6)) summary(res) # Using evalGel to create the object without estimation res <- evalGel(g, x, res$coefficients)
It extract the data from a formula y~z with instrument h and put everything in a matrix. It helps redefine the function that is required by
gmm
and gel
.
getDat(formula, h, data, error=TRUE)
getDat(formula, h, data, error=TRUE)
formula |
A formula that defines the linear model to be estimated (see details). |
h |
A |
data |
A data.frame or a matrix with colnames (Optionnal). |
error |
If FALSE, the data is generated without giving any error message |
The model to be estimated is based on the moment conditions
. It adds a column of ones to z and h by
default. They are removed if -1 is added to the formula.
The error argument has been added for
sysGmm
with common
coefficients because the check is only valid for
equation by equation identification.
x: A matrix, where
if "intercept" is TRUE and
if "intercept" is FALSE.
nh: dimension of h
k: dimension of z
ny: dimension of y
n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) x <- getDat(y ~ ym1 + ym2, H)
n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) x <- getDat(y ~ ym1 + ym2, H)
It computes the implied
probabilities from objects of class gel
with additional options.
## S3 method for class 'gel' getImpProb(object, posProb=TRUE, normalize=TRUE, checkConv=FALSE,...)
## S3 method for class 'gel' getImpProb(object, posProb=TRUE, normalize=TRUE, checkConv=FALSE,...)
object |
Object of class
|
posProb |
Should the implied probabilities be transformed into positive probabilities? |
normalize |
Should we normalize the probabilities so that they sum to one? |
checkConv |
Should we add the attribute convergence to check the sum of the probabilities and the weighted sum of the moment conditions? |
... |
Additional arguments to pass to other methods |
A vector af implied probabilities.
Newey, W.K. and Smith, R.J. (2004), Higher Order Properties of GMM and Generalized Empirical Likelihood Estimators. Econometrica, 72, 219-255.
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) pt <- getImpProb(res)
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) pt <- getImpProb(res)
It computes the vector of Lagrange multipliers, which maximizes the GEL objective function, using an iterative Newton method.
getLamb(gt, l0, type = c("EL","ET","CUE", "ETEL", "HD","ETHD","RCUE"), tol_lam = 1e-7, maxiterlam = 100, tol_obj = 1e-7, k = 1, method = c("nlminb", "optim", "iter", "Wu"), control = list())
getLamb(gt, l0, type = c("EL","ET","CUE", "ETEL", "HD","ETHD","RCUE"), tol_lam = 1e-7, maxiterlam = 100, tol_obj = 1e-7, k = 1, method = c("nlminb", "optim", "iter", "Wu"), control = list())
gt |
A |
l0 |
Vector of starting values for lambda |
type |
"EL" for empirical likelihood, "ET" for exponential tilting, "CUE" for continuous updated estimator, and "HD" for Hellinger Distance. See details for "ETEL" and "ETHD". "RCUE" is a restricted version of "CUE" in which the probabilities are bounded below by zero. In that case, an analytical Kuhn-Tucker method is used to find the solution. |
tol_lam |
Tolerance for |
maxiterlam |
The algorithm stops if there is no convergence after "maxiterlam" iterations. |
tol_obj |
Tolerance for the gradiant of the objective function. The
algorithm returns a non-convergence message if |
k |
It represents the ratio k1/k2, where
|
method |
The iterative procedure uses a Newton method for solving
the FOC. It i however recommended to use |
control |
Controls to send to |
It solves
the problem . For the type "ETEL", it is only used by
gel
. In that case is obtained by maximizing
, using
(so ET) and
by minimizing the same
equation but with
. To avoid NA's,
constrOptim
is used with the restriction . The type "ETHD" is experimental and proposed by Antoine-Dovonon
(2015). The paper is not yet available.
lambda: A vector of Lagrange multipliers which solve the system of equations given above.
conv
: Details on the type of convergence.
Newey, W.K. and Smith, R.J. (2004), Higher Order Properties of GMM and Generalized Empirical Likelihood Estimators. Econometrica, 72, 219-255.
Smith, R.J. (2004), GEL Criteria for Moment Condition Models. Working paper, CEMMAP.
Wu, C. (2005), Algorithms and R codes for the pseudo empirical likelihood method in survey sampling. Survey Methodology, 31(2), page 239.
g <- function(tet,x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) gt <- g(c(0,phi),x) getLamb(gt, type = "EL",method="optim")
g <- function(tet,x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) gt <- g(c(0,phi),x) getLamb(gt, type = "EL",method="optim")
It collects what is needed by the method momentEstim
(see details).
## S3 method for class 'baseGmm' getModel(object, ...) ## S3 method for class 'sysGmm' getModel(object, ...) ## S3 method for class 'baseGel' getModel(object, ...) ## S3 method for class 'constGel' getModel(object, ...) ## S3 method for class 'constGel' getModel(object, ...) ## S3 method for class 'tsls' getModel(object, ...) ## S3 method for class 'ateGel' getModel(object, ...)
## S3 method for class 'baseGmm' getModel(object, ...) ## S3 method for class 'sysGmm' getModel(object, ...) ## S3 method for class 'baseGel' getModel(object, ...) ## S3 method for class 'constGel' getModel(object, ...) ## S3 method for class 'constGel' getModel(object, ...) ## S3 method for class 'tsls' getModel(object, ...) ## S3 method for class 'ateGel' getModel(object, ...)
object |
An object of class |
... |
Other arguments when |
It returns an object of the right class which determines how the method momentEstim
will treat it. For example, if g
is a formula and type
is set to "cue", it creates an object of class baseGmm.cue.formula
. It this case, momentEstim
, applied to this object, computes the continuously updated GMM of a linear model. It allows more flexibility this way. For example, it could be easy to add a GMM method which is robust in presence of weak identification simply by creating a new class of model and the associated momentEstime
method.
Function to estimate a vector of parameters based on moment conditions using the GMM method of Hansen(82).
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 = 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, mustar = NULL, onlyCoefficients=FALSE, ...) evalGmm(g, x, t0, tetw=NULL, gradv=NULL, 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, model=TRUE, X=FALSE, Y=FALSE, centeredVcov = TRUE, weightsMatrix = NULL, data, mustar = NULL) gmmWithConst(obj, which, value)
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 = 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, mustar = NULL, onlyCoefficients=FALSE, ...) evalGmm(g, x, t0, tetw=NULL, gradv=NULL, 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, model=TRUE, X=FALSE, Y=FALSE, centeredVcov = TRUE, weightsMatrix = NULL, data, mustar = NULL) gmmWithConst(obj, which, value)
g |
A function of the form |
x |
The matrix or vector of data from which the function |
t0 |
A |
tetw |
A |
gradv |
A function of the form |
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) |
wmatrix |
Which weighting matrix should be used in the objective function. By default, it is the inverse of the covariance matrix of |
vcov |
Assumption on the properties of the random vector x. By default, x is a weakly dependant process. The "iid" option will avoid using the HAC matrix which will accelerate the estimation if one is ready to make that assumption. The option "TrueFixed" is used only when the matrix of weights is provided and it is the optimal one. |
kernel |
type of kernel used to compute the covariance matrix of the vector of sample moment conditions (see |
crit |
The stopping rule for the iterative GMM. It can be reduce to increase the precision. |
bw |
The method to compute the bandwidth parameter in the HAC
weighting matrix. The default is |
prewhite |
logical or integer. Should the estimating functions be prewhitened? If |
ar.method |
character. The |
approx |
A character specifying the approximation method if the bandwidth has to be chosen by |
tol |
Weights that exceed |
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. |
optfct |
Only when the dimension of |
model , X , Y
|
logical. If |
TypeGmm |
The name of the class object created by the method |
centeredVcov |
Should the moment function be centered when computing its covariance matrix. Doing so may improve inference. |
weightsMatrix |
It allows users to provide |
traceIter |
Tracing information for GMM of type "iter" |
data |
A data.frame or a matrix with column names (Optional). |
eqConst |
Either a named vector (if "g" is a function), a simple vector for the nonlinear case indicating which of the |
which , value
|
The equality constraint is of the form which=value. "which" can be a vector of type characters with the names of the coefficients being constrained, or a vector of type numeric with the position of the coefficient in the whole vector. |
obj |
Object of class "gmm" |
eqConstFullVcov |
If FALSE, the constrained coefficients are assumed to be fixed and only the covariance of the unconstrained coefficients is computed. If TRUE, the covariance matrix of the full set of coefficients is computed. |
mustar |
If not null, it must be a vector with the number of elements being equal to the number of moment conditions. In that case, the vector is subtracted from the sample moment vector before minimizing the objective function. It is useful to do a bootstrap procedure. |
onlyCoefficients |
If set to |
... |
More options to give to |
If we want to estimate a model like using the moment conditions
, where
is a vector of
instruments, than we can define "g" like we do for
lm
. We would have and the argument "x" above would become the matrix H of instruments. As for
lm
, can be a
vector which would imply that
. The intercept is included by default so you do not have to add a column of ones to the matrix
. You do not need to provide the gradiant in that case since in that case it is embedded in
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 , we can set "x" to
. By default, a column of ones is added. To remove it, set "x" to
.
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 we have the following three moment conditions:
can be directly obtained by the definition of
. The third moment condition comes from the third derivative of the moment generating function (MGF)
evaluated at .
Note that we have more equations (3) than unknown parameters (2).
The Jacobian of these two conditions is (it should be an array but I can't make it work):
gmmWithConst()
re-estimates an unrestricted model by adding an
equality constraint.
evalGmm()
creates an object of class '"gmm"' for a given
parameter vector. If no vector "tetw" is provided and the weighting
matrix needs to be computed, "t0" is used.,
'gmm' returns an object of 'class' '"gmm"'
The functions 'summary' is used to obtain and print a summary of the results. It also compute the J-test of overidentying restriction
The object of class "gmm" is a list containing at least:
coefficients |
|
residuals |
the residuals, that is response minus fitted values if "g" is a formula. |
fitted.values |
the fitted mean values if "g" is a formula. |
vcov |
the covariance matrix of the coefficients |
objective |
the value of the objective function |
terms |
the |
call |
the matched call. |
y |
if requested, the response used (if "g" is a formula). |
x |
if requested, the model matrix used if "g" is a formula or the data if "g" is a function. |
model |
if requested (the default), the model frame used if "g" is a formula. |
algoInfo |
Information produced by either |
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
Pierre Chausse (2010), Computing Generalized Method of Moments and Generalized Empirical Likelihood with R. Journal of Statistical Software, 34(11), 1–35. URL doi:10.18637/jss.v034.i11.
Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica, 59, 817–858.
Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica, 55, 703–708.
Newey WK & West KD (1994), Automatic Lag Selection in Covariance Matrix Estimation. Review of Economic Studies, 61, 631-653.
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
Hansen, L.P. and Heaton, J. and Yaron, A.(1996), Finite-Sample Properties of Some Alternative GMM Estimators. Journal of Business and Economic Statistics, 14 262-280.
## CAPM test with GMM data(Finance) r <- Finance[1:300, 1:10] rm <- Finance[1:300, "rm"] rf <- Finance[1:300, "rf"] z <- as.matrix(r-rf) t <- nrow(z) zm <- rm-rf h <- matrix(zm, t, 1) res <- gmm(z ~ zm, x = h) summary(res) ## linear tests can be performed using linearHypothesis from the car package ## The CAPM can be tested as follows: library(car) linearHypothesis(res,cbind(diag(10),matrix(0,10,10)),rep(0,10)) # The CAPM of Black g <- function(theta, x) { e <- x[,2:11] - theta[1] - (x[,1] - theta[1]) %*% matrix(theta[2:11], 1, 10) gmat <- cbind(e, e*c(x[,1])) return(gmat) } x <- as.matrix(cbind(rm, r)) res_black <- gmm(g, x = x, t0 = rep(0, 11)) summary(res_black)$coefficients ## APT test with Fama-French factors and GMM f1 <- zm f2 <- Finance[1:300, "hml"] f3 <- Finance[1:300, "smb"] h <- cbind(f1, f2, f3) res2 <- gmm(z ~ f1 + f2 + f3, x = h) coef(res2) summary(res2)$coefficients ## Same result with x defined as a formula: res2 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3) coef(res2) ## The following example has been provided by Dieter Rozenich (see details). # It generates normal random numbers and uses the GMM to estimate # mean and sd. #------------------------------------------------------------------------------- # Random numbers of a normal distribution # First we generate normally distributed random numbers and compute the two parameters: n <- 1000 x <- rnorm(n, mean = 4, sd = 2) # Implementing the 3 moment conditions g <- function(tet, x) { m1 <- (tet[1] - x) m2 <- (tet[2]^2 - (x - tet[1])^2) m3 <- x^3 - tet[1]*(tet[1]^2 + 3*tet[2]^2) f <- cbind(m1, m2, m3) return(f) } # Implementing the jacobian Dg <- function(tet, x) { jacobian <- matrix(c( 1, 2*(-tet[1]+mean(x)), -3*tet[1]^2-3*tet[2]^2,0, 2*tet[2], -6*tet[1]*tet[2]), nrow=3,ncol=2) return(jacobian) } # Now we want to estimate the two parameters using the GMM. gmm(g, x, c(0, 0), grad = Dg) # Two-stage-least-squares (2SLS), or IV with iid errors. # The model is: # Y(t) = b[0] + b[1]C(t) + b[2]Y(t-1) + e(t) # e(t) is an MA(1) # The instruments are Z(t)={1 C(t) y(t-2) y(t-3) y(t-4)} getdat <- function(n) { e <- arima.sim(n,model=list(ma=.9)) C <- runif(n,0,5) Y <- rep(0,n) Y[1] = 1 + 2*C[1] + e[1] for (i in 2:n){ Y[i] = 1 + 2*C[i] + 0.9*Y[i-1] + e[i] } Yt <- Y[5:n] X <- cbind(1,C[5:n],Y[4:(n-1)]) Z <- cbind(1,C[5:n],Y[3:(n-2)],Y[2:(n-3)],Y[1:(n-4)]) return(list(Y=Yt,X=X,Z=Z)) } d <- getdat(5000) 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 # Method Brent is used because the problem is now one-dimensional gmm(g, x, c(4, 0), grad = Dg, eqConst=1, method="Brent", lower=-10,upper=10) # with named vector gmm(g, x, c(mu=4, sig=2), grad = Dg, eqConst="sig", method="Brent", lower=-10,upper=10) ## End(Not run) gmm(g, x, c(4, 0), grad = Dg, eqConst=1,method="Brent",lower=0,upper=6) gmm(g, x, c(mu=4, sig=2), grad = Dg, eqConst="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 # CUE with starting t0 requires eqConst to be a vector res3 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=c(0,1,.5,.5), type="cue", eqConst = c(1,2)) res3 ### Examples with equality constraints, where the constrained coefficients is used to compute ### the covariance matrix. ### Useful when some coefficients have been estimated before, they are just identified in GMM ### and don't need to be re-estimated. ### To use with caution because the covariance won't be valid if the coefficients do not solve ### the GMM FOC. ###################################### res4 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=c(0,1,.5,.5), eqConst = c(1,2), eqConstFullVcov=TRUE) summary(res4) ### Examples with equality constraint using gmmWithConst ########################################################### res2 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3) gmmWithConst(res2,c("f2","f3"),c(.5,.5)) gmmWithConst(res2,c(2,3),c(.5,.5)) ## Creating an object without estimation for a fixed parameter vector ################################################################### res2_2 <- evalGmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=res2$coefficients, tetw=res2$coefficients) summary(res2_2)
## CAPM test with GMM data(Finance) r <- Finance[1:300, 1:10] rm <- Finance[1:300, "rm"] rf <- Finance[1:300, "rf"] z <- as.matrix(r-rf) t <- nrow(z) zm <- rm-rf h <- matrix(zm, t, 1) res <- gmm(z ~ zm, x = h) summary(res) ## linear tests can be performed using linearHypothesis from the car package ## The CAPM can be tested as follows: library(car) linearHypothesis(res,cbind(diag(10),matrix(0,10,10)),rep(0,10)) # The CAPM of Black g <- function(theta, x) { e <- x[,2:11] - theta[1] - (x[,1] - theta[1]) %*% matrix(theta[2:11], 1, 10) gmat <- cbind(e, e*c(x[,1])) return(gmat) } x <- as.matrix(cbind(rm, r)) res_black <- gmm(g, x = x, t0 = rep(0, 11)) summary(res_black)$coefficients ## APT test with Fama-French factors and GMM f1 <- zm f2 <- Finance[1:300, "hml"] f3 <- Finance[1:300, "smb"] h <- cbind(f1, f2, f3) res2 <- gmm(z ~ f1 + f2 + f3, x = h) coef(res2) summary(res2)$coefficients ## Same result with x defined as a formula: res2 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3) coef(res2) ## The following example has been provided by Dieter Rozenich (see details). # It generates normal random numbers and uses the GMM to estimate # mean and sd. #------------------------------------------------------------------------------- # Random numbers of a normal distribution # First we generate normally distributed random numbers and compute the two parameters: n <- 1000 x <- rnorm(n, mean = 4, sd = 2) # Implementing the 3 moment conditions g <- function(tet, x) { m1 <- (tet[1] - x) m2 <- (tet[2]^2 - (x - tet[1])^2) m3 <- x^3 - tet[1]*(tet[1]^2 + 3*tet[2]^2) f <- cbind(m1, m2, m3) return(f) } # Implementing the jacobian Dg <- function(tet, x) { jacobian <- matrix(c( 1, 2*(-tet[1]+mean(x)), -3*tet[1]^2-3*tet[2]^2,0, 2*tet[2], -6*tet[1]*tet[2]), nrow=3,ncol=2) return(jacobian) } # Now we want to estimate the two parameters using the GMM. gmm(g, x, c(0, 0), grad = Dg) # Two-stage-least-squares (2SLS), or IV with iid errors. # The model is: # Y(t) = b[0] + b[1]C(t) + b[2]Y(t-1) + e(t) # e(t) is an MA(1) # The instruments are Z(t)={1 C(t) y(t-2) y(t-3) y(t-4)} getdat <- function(n) { e <- arima.sim(n,model=list(ma=.9)) C <- runif(n,0,5) Y <- rep(0,n) Y[1] = 1 + 2*C[1] + e[1] for (i in 2:n){ Y[i] = 1 + 2*C[i] + 0.9*Y[i-1] + e[i] } Yt <- Y[5:n] X <- cbind(1,C[5:n],Y[4:(n-1)]) Z <- cbind(1,C[5:n],Y[3:(n-2)],Y[2:(n-3)],Y[1:(n-4)]) return(list(Y=Yt,X=X,Z=Z)) } d <- getdat(5000) 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 # Method Brent is used because the problem is now one-dimensional gmm(g, x, c(4, 0), grad = Dg, eqConst=1, method="Brent", lower=-10,upper=10) # with named vector gmm(g, x, c(mu=4, sig=2), grad = Dg, eqConst="sig", method="Brent", lower=-10,upper=10) ## End(Not run) gmm(g, x, c(4, 0), grad = Dg, eqConst=1,method="Brent",lower=0,upper=6) gmm(g, x, c(mu=4, sig=2), grad = Dg, eqConst="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 # CUE with starting t0 requires eqConst to be a vector res3 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=c(0,1,.5,.5), type="cue", eqConst = c(1,2)) res3 ### Examples with equality constraints, where the constrained coefficients is used to compute ### the covariance matrix. ### Useful when some coefficients have been estimated before, they are just identified in GMM ### and don't need to be re-estimated. ### To use with caution because the covariance won't be valid if the coefficients do not solve ### the GMM FOC. ###################################### res4 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=c(0,1,.5,.5), eqConst = c(1,2), eqConstFullVcov=TRUE) summary(res4) ### Examples with equality constraint using gmmWithConst ########################################################### res2 <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3) gmmWithConst(res2,c("f2","f3"),c(.5,.5)) gmmWithConst(res2,c(2,3),c(.5,.5)) ## Creating an object without estimation for a fixed parameter vector ################################################################### res2_2 <- evalGmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, t0=res2$coefficients, tetw=res2$coefficients) summary(res2_2)
Panel of Macroeconomic data for 125 countries from 1960 to 1985 constructed by Summers and Heston (1991))
data(Growth)
data(Growth)
A data frame containing 9 vectors.
Country identification number
1 if the country is in a communist regime, 0 otherwise
1 if the country is part of the OPEC, 0 otherwise
Year
Per capita GDP (in thousands) in 1985 U.S. dollars.
GDP of the previous period
Saving rate measured as the ratio of real investment to real GDP
SavRate of the previous period
Country names
Population in thousands
Population of the previous period
http://fhayashi.fc2web.com/datasets.htm
The test is proposed by Kleibergen (2005). It is robust to weak identification.
KTest(obj, theta0 = NULL, alphaK = 0.04, alphaJ = 0.01) ## S3 method for class 'gmmTests' print(x, digits = 5, ...)
KTest(obj, theta0 = NULL, alphaK = 0.04, alphaJ = 0.01) ## S3 method for class 'gmmTests' print(x, digits = 5, ...)
obj |
Object of class "gmm" returned by |
theta0 |
The null hypothesis being tested. See details. |
alphaK , alphaJ
|
The size of the J and K tests when combining the two. The overall size is alphaK+alphaJ. |
x |
An object of class |
digits |
The number of digits to be printed |
... |
Other arguments when |
The function produces the J-test and K-statistics which are robust to weak identification. The test is either , in which case theta0 must be provided, or
, where
, and
is assumed to be identified. In the latter case, theta0 is NULL and obj is a restricted estimation in which
is fixed to
. See
gmm
and the option "eqConst" for more details.
Tests and p-values
Keibergen, F. (2005), Testing Parameters in GMM without assuming that they are identified. Econometrica, 73, 1103-1123,
library(mvtnorm) sig <- matrix(c(1,.5,.5,1),2,2) n <- 400 e <- rmvnorm(n,sigma=sig) x4 <- rnorm(n) w <- exp(-x4^2) + e[,1] y <- 0.1*w + e[,2] h <- cbind(x4, x4^2, x4^3, x4^6) g3 <- y~w res <- gmm(g3,h) # Testing the whole vector: KTest(res,theta0=c(0,.1)) # Testing a subset of the vector (See \code{\link{gmm}}) res2 <- gmm(g3, h, eqConst=matrix(c(2,.1),1,2)) res2 KTest(res2)
library(mvtnorm) sig <- matrix(c(1,.5,.5,1),2,2) n <- 400 e <- rmvnorm(n,sigma=sig) x4 <- rnorm(n) w <- exp(-x4^2) + e[,1] y <- 0.1*w + e[,2] h <- cbind(x4, x4^2, x4^3, x4^6) g3 <- y~w res <- gmm(g3,h) # Testing the whole vector: KTest(res,theta0=c(0,.1)) # Testing a subset of the vector (See \code{\link{gmm}}) res2 <- gmm(g3, h, eqConst=matrix(c(2,.1),1,2)) res2 KTest(res2)
It produces the summary table of marginal effects for GLM estimation with GEL. Only implemented for ATEgel.
## S3 method for class 'ategel' marginal(object, ...)
## S3 method for class 'ategel' marginal(object, ...)
object |
An object of class |
... |
Other arguments for other methods |
It returns a matrix with the marginal effects, the standard errors based on the Delta method when the link is nonlinear, the t-ratios, and the pvalues.
Owen, A.B. (2001), Empirical Likelihood. Monographs on Statistics and Applied Probability 92, Chapman and Hall/CRC
## We create some artificial data with unbalanced groups and binary outcome genDat <- function(n) { eta=c(-1, .5, -.25, -.1) Z <- matrix(rnorm(n*4),ncol=4) b <- c(27.4, 13.7, 13.7, 13.7) bZ <- c(Z%*%b) Y1 <- as.numeric(rnorm(n, mean=210+bZ)>220) Y0 <- as.numeric(rnorm(n, mean=200-.5*bZ)>220) etaZ <- c(Z%*%eta) pZ <- exp(etaZ)/(1+exp(etaZ)) T <- rbinom(n, 1, pZ) Y <- T*Y1+(1-T)*Y0 X1 <- exp(Z[,1]/2) X2 <- Z[,2]/(1+exp(Z[,1])) X3 <- (Z[,1]*Z[,3]/25+0.6)^3 X4 <- (Z[,2]+Z[,4]+20)^2 data.frame(Y=Y, cbind(X1,X2,X3,X4), T=T) } dat <- genDat(200) res <- ATEgel(Y~T, ~X1+X2+X3+X4, data=dat, type="ET", family="logit") summary(res) marginal(res)
## We create some artificial data with unbalanced groups and binary outcome genDat <- function(n) { eta=c(-1, .5, -.25, -.1) Z <- matrix(rnorm(n*4),ncol=4) b <- c(27.4, 13.7, 13.7, 13.7) bZ <- c(Z%*%b) Y1 <- as.numeric(rnorm(n, mean=210+bZ)>220) Y0 <- as.numeric(rnorm(n, mean=200-.5*bZ)>220) etaZ <- c(Z%*%eta) pZ <- exp(etaZ)/(1+exp(etaZ)) T <- rbinom(n, 1, pZ) Y <- T*Y1+(1-T)*Y0 X1 <- exp(Z[,1]/2) X2 <- Z[,2]/(1+exp(Z[,1])) X3 <- (Z[,1]*Z[,3]/25+0.6)^3 X4 <- (Z[,2]+Z[,4]+20)^2 data.frame(Y=Y, cbind(X1,X2,X3,X4), T=T) } dat <- genDat(200) res <- ATEgel(Y~T, ~X1+X2+X3+X4, data=dat, type="ET", family="logit") summary(res) marginal(res)
It estimates a model which is caracterized by the method getModel
(see details).
## S3 method for class 'baseGmm.twoStep' momentEstim(object, ...) ## S3 method for class 'baseGmm.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'sysGmm.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'tsls.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.iterative.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.iterative' momentEstim(object, ...) ## S3 method for class 'baseGmm.cue.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.cue' momentEstim(object, ...) ## S3 method for class 'baseGmm.eval' momentEstim(object, ...) ## S3 method for class 'baseGel.mod' momentEstim(object, ...) ## S3 method for class 'baseGel.modFormula' momentEstim(object, ...) ## S3 method for class 'baseGel.eval' momentEstim(object, ...)
## S3 method for class 'baseGmm.twoStep' momentEstim(object, ...) ## S3 method for class 'baseGmm.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'sysGmm.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'tsls.twoStep.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.iterative.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.iterative' momentEstim(object, ...) ## S3 method for class 'baseGmm.cue.formula' momentEstim(object, ...) ## S3 method for class 'baseGmm.cue' momentEstim(object, ...) ## S3 method for class 'baseGmm.eval' momentEstim(object, ...) ## S3 method for class 'baseGel.mod' momentEstim(object, ...) ## S3 method for class 'baseGel.modFormula' momentEstim(object, ...) ## S3 method for class 'baseGel.eval' momentEstim(object, ...)
object |
An object created by the method |
... |
Other arguments when |
It returns an object of class determined by the argument "TypeGMM" of gmm
. By default, it is of class baseGmm.res
. It estimates the model and organize the results that will be finalized by the method FinRes
. More methods can be created in order to use other GMM methods not yet included in the package.
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
Hansen, L.P. and Heaton, J. and Yaron, A.(1996), Finit-Sample Properties of Some Alternative GMM Estimators. Journal of Business and Economic Statistics, 14 262-280.
This data was collected to evaluate the National Supported Work (NSW) Demonstration project in Lalonde (1986).
data(nsw)
data(nsw)
A data frame containing 9 variables.
Treatment assignment
Age
Years of Education
1 if Black, 0 otherwise
1 if Hispanic 0 otherwise
1 if married 0 otherwise
1 if no college degree 0 otherwise
1975 earnings
1978 earnings
The dataset was obtained from the ATE package (see reference).
"NSW Data Files" from Rajeev Dehejia's website. URL: http://users.nber.org/~rdehejia/data/.nswdata2.html
"National Supported Work Evaluation Study, 1975-1979: Public Use Files." from the Interuniversity Consortium for Political and Social Research. URL: http://www.icpsr.umich.edu/icpsrweb/ICPSR/studies/7865
Lalonde, R. (1986). "Evaluating the Econometric Evaluations of Training Programs," American Economic Review, 76(4), 604-620.
Dehejia R. and Wahba S. (1999). "Causal Effects in Non-Experimental Studies: Re-Evaluating the Evaluation of Training Programs," JASA 94 (448), 1053-1062.
Asad Haris and Gary Chan (2015). ATE: Inference for Average Treatment Effects using Covariate Balancing. R package version 0.2.0. https://CRAN.R-project.org/package=ATE
It is a plot method for gel
or gmm
objects.
## S3 method for class 'gel' plot(x, which = c(1L:4), main = list("Residuals vs Fitted values", "Normal Q-Q", "Response variable and fitted values","Implied probabilities"), panel = if(add.smooth) panel.smooth else points, ask = prod(par("mfcol")) < length(which) && dev.interactive(), ..., add.smooth = getOption("add.smooth")) ## S3 method for class 'gmm' plot(x, which = c(1L:3), main = list("Residuals vs Fitted values", "Normal Q-Q", "Response variable and fitted values"), panel = if(add.smooth) panel.smooth else points, ask = prod(par("mfcol")) < length(which) && dev.interactive(), ..., add.smooth = getOption("add.smooth"))
## S3 method for class 'gel' plot(x, which = c(1L:4), main = list("Residuals vs Fitted values", "Normal Q-Q", "Response variable and fitted values","Implied probabilities"), panel = if(add.smooth) panel.smooth else points, ask = prod(par("mfcol")) < length(which) && dev.interactive(), ..., add.smooth = getOption("add.smooth")) ## S3 method for class 'gmm' plot(x, which = c(1L:3), main = list("Residuals vs Fitted values", "Normal Q-Q", "Response variable and fitted values"), panel = if(add.smooth) panel.smooth else points, ask = prod(par("mfcol")) < length(which) && dev.interactive(), ..., add.smooth = getOption("add.smooth"))
x |
|
which |
if a subset of the plots is required, specify a subset of
the numbers |
main |
Vector of titles for each plot. |
panel |
panel function. The useful alternative to
|
ask |
logical; if |
... |
other parameters to be passed through to plotting functions. |
add.smooth |
logical indicating if a smoother should be added to
most plots; see also |
It is a beta version of a plot method for gel
objects. It is a modified version of plot.lm
. For now, it is available only for linear models expressed as a formula. Any suggestions are welcome regarding plots or options to include.
The first two plots are the same as the ones provided by plot.lm
, the third is the dependant variable with its mean
(the fitted values) and the last plots the implied probabilities with the empirical density
.
# GEL # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n,list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) plot(res, which = 3) plot(res, which = 4) # GMM # res <- gmm(g, x) plot(res, which = 3)
# GEL # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n,list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) plot(res, which = 3) plot(res, which = 4) # GMM # res <- gmm(g, x) plot(res, which = 3)
It is a printing method for gmm
or gel
objects.
## S3 method for class 'gmm' print(x, digits = 5, ...) ## S3 method for class 'gel' print(x, digits = 5, ...) ## S3 method for class 'sysGmm' print(x, digits = 5, ...)
## S3 method for class 'gmm' print(x, digits = 5, ...) ## S3 method for class 'gel' print(x, digits = 5, ...) ## S3 method for class 'sysGmm' print(x, digits = 5, ...)
x |
An object of class |
digits |
The number of digits to be printed |
... |
Other arguments when print is applied to an other class object |
It prints some results from the estimation like the coefficients and the value of the objective function.
# GMM # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x) print(res) # GEL # t0 <- c(0,.5,.5) res <- gel(g,x,t0) print(res)
# GMM # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x) print(res) # GEL # t0 <- c(0,.5,.5) res <- gel(g,x,t0) print(res)
Method to extract the residuals of the model estimated by gmm
or gel
.
## S3 method for class 'gel' residuals(object, ...) ## S3 method for class 'gmm' residuals(object, ...)
## S3 method for class 'gel' residuals(object, ...) ## S3 method for class 'gmm' residuals(object, ...)
object |
An object of class |
... |
Other arguments when |
It returns the matrix of residuals in
g=y~x
as it is done by residuals.lm
.
# GEL can deal with endogeneity problems n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) e <- residuals(res) plot(e, type = 'l', main = "Residuals from an ARMA fit using GEL") # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) plot(x, residuals(res), main = "Residuals of an estimated model with GMM")
# GEL can deal with endogeneity problems n = 200 phi<-c(.2,.7) thet <- 0.2 sd <- .2 set.seed(123) x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gel(g, x, c(0,.3,.6)) e <- residuals(res) plot(e, type = 'l', main = "Residuals from an ARMA fit using GEL") # GMM is like GLS for linear models without endogeneity problems set.seed(345) n = 200 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- 10 + 5*rnorm(n) + x res <- gmm(y ~ x, x) plot(x, residuals(res), main = "Residuals of an estimated model with GMM")
It applies the required kernel smoothing to the moment function in order for the GEL estimator to be valid. It is used by the gel
function.
smoothG(x, bw = bwAndrews, prewhite = 1, ar.method = "ols", weights = weightsAndrews, kernel = c("Bartlett", "Parzen", "Truncated", "Tukey-Hanning"), approx = c("AR(1)", "ARMA(1,1)"), tol = 1e-7)
smoothG(x, bw = bwAndrews, prewhite = 1, ar.method = "ols", weights = weightsAndrews, kernel = c("Bartlett", "Parzen", "Truncated", "Tukey-Hanning"), approx = c("AR(1)", "ARMA(1,1)"), tol = 1e-7)
x |
a |
bw |
The method to compute the bandwidth parameter. By default, it uses the bandwidth proposed by Andrews(1991). As an alternative, we can choose bw=bwNeweyWest (without "") which is proposed by Newey-West(1996). |
prewhite |
logical or integer. Should the estimating functions
be prewhitened? If |
ar.method |
character. The |
weights |
The smoothing weights can be computed by |
approx |
a character specifying the approximation method if the
bandwidth has to be chosen by |
tol |
numeric. Weights that exceed |
kernel |
The choice of kernel |
The sample moment conditions is replaced by:
, where
,
where
is a truncated parameter that depends on the bandwidth and
are normalized weights so that they sum to 1.
If the vector of weights is provided, it gives only one side weights. For exemple, if you provide the vector (1,.5,.25), will become
smoothx: A matrix containing an estimator of the asymptotic variance of
, where
is
vector with typical element
. This function is called by
gel
but can also be used by itself.
kern_weights
: Vector of weights used for the smoothing.
Anatolyev, S. (2005), GMM, GEL, Serial Correlation, and Asymptotic Bias. Econometrica, 73, 983-1002.
Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica, 59, 817–858.
Kitamura, Yuichi (1997), Empirical Likelihood Methods With Weakly Dependent Processes. The Annals of Statistics, 25, 2084-2102.
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
g <- function(tet, x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) gt <- g(c(0, phi), x) sgt <- smoothG(gt)$smoothx plot(gt[,1]) lines(sgt[,1])
g <- function(tet, x) { n <- nrow(x) u <- (x[7:n] - tet[1] - tet[2]*x[6:(n-1)] - tet[3]*x[5:(n-2)]) f <- cbind(u, u*x[4:(n-3)], u*x[3:(n-4)], u*x[2:(n-5)], u*x[1:(n-6)]) return(f) } n = 500 phi<-c(.2, .7) thet <- 0.2 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2, 0, 1), ar = phi, ma = thet, sd = sd)), ncol = 1) gt <- g(c(0, phi), x) sgt <- smoothG(gt)$smoothx plot(gt[,1]) lines(sgt[,1])
Generic function for testing the specification of estimated models. It computes the J-test from gmm
objects and J-test, LR-test and LM-test from
gel
objects.
## S3 method for class 'gmm' specTest(x, ...) ## S3 method for class 'gel' specTest(x, ...) ## S3 method for class 'specTest' print(x, digits = 5, ...) specTest(x, ...)
## S3 method for class 'gmm' specTest(x, ...) ## S3 method for class 'gel' specTest(x, ...) ## S3 method for class 'specTest' print(x, digits = 5, ...) specTest(x, ...)
x |
A fitted model object. |
digits |
The number of digits to be printed. |
... |
Arguments passed to methods. |
Tests and p-values
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
Smith, R. J. (2004), GEL Criteria for Moment Condition Models. CeMMAP working papers, Institute for Fiscal Studies
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) specTest(res) ################### res <- gmm(g, x) specTest(res)
################# n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n=n,list(order=c(2,0,1),ar=phi,ma=thet,sd=sd)),ncol=1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H t0 <- c(0,.5,.5) res <- gel(g, x, t0) specTest(res) ################### res <- gmm(g, x) specTest(res)
It presents the results from the gmm
or gel
estimation in the same fashion as summary
does for the lm
class objects for example. It also compute the tests for overidentifying restrictions.
## S3 method for class 'gmm' summary(object, ...) ## S3 method for class 'sysGmm' summary(object, ...) ## S3 method for class 'gel' summary(object, ...) ## S3 method for class 'ategel' summary(object, robToMiss = TRUE, ...) ## S3 method for class 'tsls' summary(object, vcov = NULL, ...) ## S3 method for class 'summary.gmm' print(x, digits = 5, ...) ## S3 method for class 'summary.sysGmm' print(x, digits = 5, ...) ## S3 method for class 'summary.gel' print(x, digits = 5, ...) ## S3 method for class 'summary.tsls' print(x, digits = 5, ...)
## S3 method for class 'gmm' summary(object, ...) ## S3 method for class 'sysGmm' summary(object, ...) ## S3 method for class 'gel' summary(object, ...) ## S3 method for class 'ategel' summary(object, robToMiss = TRUE, ...) ## S3 method for class 'tsls' summary(object, vcov = NULL, ...) ## S3 method for class 'summary.gmm' print(x, digits = 5, ...) ## S3 method for class 'summary.sysGmm' print(x, digits = 5, ...) ## S3 method for class 'summary.gel' print(x, digits = 5, ...) ## S3 method for class 'summary.tsls' print(x, digits = 5, ...)
object |
An object of class |
x |
An object of class |
digits |
The number of digits to be printed |
vcov |
An alternative covariance matrix computed with
|
robToMiss |
If |
... |
Other arguments when summary is applied to another class object |
It returns a list with the parameter estimates and their standard deviations, t-stat and p-values. It also returns the J-test and p-value for the null hypothesis that
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
Hansen, L.P. and Heaton, J. and Yaron, A.(1996), Finit-Sample Properties of Some Alternative GMM Estimators. Journal of Business and Economic Statistics, 14 262-280.
Anatolyev, S. (2005), GMM, GEL, Serial Correlation, and Asymptotic Bias. Econometrica, 73, 983-1002.
Kitamura, Yuichi (1997), Empirical Likelihood Methods With Weakly Dependent Processes. The Annals of Statistics, 25, 2084-2102.
Newey, W.K. and Smith, R.J. (2004), Higher Order Properties of GMM and Generalized Empirical Likelihood Estimators. Econometrica, 72, 219-255.
# GMM # set.seed(444) n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] ym3 <- x[4:(n-3)] ym4 <- x[3:(n-4)] ym5 <- x[2:(n-5)] ym6 <- x[1:(n-6)] g <- y ~ ym1 + ym2 x <- ~ym3+ym4+ym5+ym6 res <- gmm(g, x) summary(res) # GEL # t0 <- res$coef res <- gel(g, x, t0) summary(res) # tsls # res <- tsls(y ~ ym1 + ym2,~ym3+ym4+ym5+ym6) summary(res)
# GMM # set.seed(444) n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n, list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] ym3 <- x[4:(n-3)] ym4 <- x[3:(n-4)] ym5 <- x[2:(n-5)] ym6 <- x[1:(n-6)] g <- y ~ ym1 + ym2 x <- ~ym3+ym4+ym5+ym6 res <- gmm(g, x) summary(res) # GEL # t0 <- res$coef res <- gel(g, x, t0) summary(res) # tsls # res <- tsls(y ~ ym1 + ym2,~ym3+ym4+ym5+ym6) summary(res)
Functions to estimate a system of equations based on GMM.
sysGmm(g, h, wmatrix = c("optimal","ident"), vcov=c("MDS", "HAC", "CondHom", "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, model=TRUE, X=FALSE, Y=FALSE, centeredVcov = TRUE, weightsMatrix = NULL, data, crossEquConst = NULL, commonCoef = FALSE) five(g, h, commonCoef = FALSE, data = NULL) threeSLS(g, h, commonCoef = FALSE, data = NULL) sur(g, commonCoef = FALSE, data = NULL) randEffect(g, data = NULL)
sysGmm(g, h, wmatrix = c("optimal","ident"), vcov=c("MDS", "HAC", "CondHom", "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, model=TRUE, X=FALSE, Y=FALSE, centeredVcov = TRUE, weightsMatrix = NULL, data, crossEquConst = NULL, commonCoef = FALSE) five(g, h, commonCoef = FALSE, data = NULL) threeSLS(g, h, commonCoef = FALSE, data = NULL) sur(g, commonCoef = FALSE, data = NULL) randEffect(g, data = NULL)
g |
A possibly named list of formulas |
h |
A formula if the same instruments are used in each equation or a list of formulas. |
wmatrix |
Which weighting matrix should be used in the objective function. By default, it is the inverse of the covariance matrix of |
vcov |
Assumption on the properties of the moment vector. By default, it is a martingale difference sequence. "HAC" is for weakly dependent processes and "CondHom" implies conditional homoscedasticity. The option "TrueFixed" is used only when the matrix of weights is provided and it is the optimal one. |
kernel |
type of kernel used to compute the covariance matrix of the vector of sample moment conditions (see |
crit |
The stopping rule for the iterative GMM. It can be reduce to increase the precision. |
bw |
The method to compute the bandwidth parameter. By default it is |
prewhite |
logical or integer. Should the estimating functions be prewhitened? If |
ar.method |
character. The |
approx |
A character specifying the approximation method if the bandwidth has to be chosen by |
tol |
Weights that exceed |
model , X , Y
|
logical. If |
centeredVcov |
Should the moment function be centered when computing its covariance matrix. Doing so may improve inference. |
weightsMatrix |
It allows users to provide |
data |
A data.frame or a matrix with column names (Optional). |
commonCoef |
If true, coefficients accross equations are the same |
crossEquConst |
Only used if the number of regressors are the same
in each equation. It is a vector which indicates which coefficient are
constant across equations. The order is 1 for Intercept and 2 to k as
it is formulated in the formulas |
This set of functions implement the estimation of system of equations as presented in Hayashi (2000)
'sysGmm' returns an object of 'class' '"sysGmm"'
The functions 'summary' is used to obtain and print a summary of the results. It also compute the J-test of overidentying restriction
The object of class "sysGmm" is a list containing at least:
coefficients |
list of vectors of coefficients for each equation |
residuals |
list of the residuals for each equation. |
fitted.values |
list of the fitted values for each equation. |
vcov |
the covariance matrix of the stacked coefficients |
objective |
the value of the objective function |
terms |
The list of |
call |
the matched call. |
y |
If requested, a list of response variables. |
x |
if requested, a list of the model matrices. |
model |
if requested (the default), a list of the model frames. |
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16. URL doi:10.18637/jss.v016.i09.
Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica, 59, 817–858.
Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica, 55, 703–708.
Newey WK & West KD (1994), Automatic Lag Selection in Covariance Matrix Estimation. Review of Economic Studies, 61, 631-653.
Hayashi, F. (2000), Econometrics. Princeton University Press.
data(wage) eq1 <- LW~S+IQ+EXPR eq2 <- LW80~S80+IQ+EXPR80 g2 <- list(Wage69=eq1, WAGE80=eq2) h2 <- list(~S+EXPR+MED+KWW, ~S80+EXPR80+MED+KWW) res <- sysGmm(g2, h2, data=wage, commonCoef=TRUE) summary(res) res2 <- sysGmm(g2, h2, data=wage) summary(res2) five(g2, h2, data=wage) threeSLS(g2, h2[[1]], data=wage) sur(g2, data=wage) randEffect(g2, data=wage) ## Cross-Equation restrictions ## All but the intercept are assumed to be the same res <- sysGmm(g2, h2, data=wage, crossEquConst = 2:4) summary(res)
data(wage) eq1 <- LW~S+IQ+EXPR eq2 <- LW80~S80+IQ+EXPR80 g2 <- list(Wage69=eq1, WAGE80=eq2) h2 <- list(~S+EXPR+MED+KWW, ~S80+EXPR80+MED+KWW) res <- sysGmm(g2, h2, data=wage, commonCoef=TRUE) summary(res) res2 <- sysGmm(g2, h2, data=wage) summary(res2) five(g2, h2, data=wage) threeSLS(g2, h2[[1]], data=wage) sur(g2, data=wage) randEffect(g2, data=wage) ## Cross-Equation restrictions ## All but the intercept are assumed to be the same res <- sysGmm(g2, h2, data=wage, crossEquConst = 2:4) summary(res)
Function to estimate a linear model by the two stage least squares method.
tsls(g,x,data)
tsls(g,x,data)
g |
A formula describing the linear regression model (see details below). |
x |
The matrix of instruments (see details below). |
data |
A data.frame or a matrix with column names (Optionnal). |
The function just calls gmm
with the option vcov="iid". It just simplifies the the implementation of 2SLS. The users don't have to worry about all the options offered in gmm
. The model is
In the first step, lm
is used to regress on the set of instruments
. The second step also uses
lm
to regress on the fitted values of the first step.
'tsls' returns an object of 'class' '"tsls"' which inherits from class '"gmm"'.
The functions 'summary' is used to obtain and print a summary of the results. It also compute the J-test of overidentying restriction
The object of class "gmm" is a list containing at least:
coefficients |
|
residuals |
the residuals, that is response minus fitted values if "g" is a formula. |
fitted.values |
the fitted mean values if "g" is a formula. |
vcov |
the covariance matrix of the coefficients |
objective |
the value of the objective function |
terms |
the |
call |
the matched call. |
y |
if requested, the response used (if "g" is a formula). |
x |
if requested, the model matrix used if "g" is a formula or the data if "g" is a function. |
model |
if requested (the default), the model frame used if "g" is a formula. |
algoInfo |
Information produced by either |
Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,
n <- 1000 e <- arima.sim(n,model=list(ma=.9)) C <- runif(n,0,5) Y <- rep(0,n) Y[1] = 1 + 2*C[1] + e[1] for (i in 2:n){ Y[i] = 1 + 2*C[i] + 0.9*Y[i-1] + e[i] } Yt <- Y[5:n] X <- cbind(C[5:n],Y[4:(n-1)]) Z <- cbind(C[5:n],Y[3:(n-2)],Y[2:(n-3)],Y[1:(n-4)]) res <- tsls(Yt~X,~Z) res
n <- 1000 e <- arima.sim(n,model=list(ma=.9)) C <- runif(n,0,5) Y <- rep(0,n) Y[1] = 1 + 2*C[1] + e[1] for (i in 2:n){ Y[i] = 1 + 2*C[i] + 0.9*Y[i-1] + e[i] } Yt <- Y[5:n] X <- cbind(C[5:n],Y[4:(n-1)]) Z <- cbind(C[5:n],Y[3:(n-2)],Y[2:(n-3)],Y[1:(n-4)]) res <- tsls(Yt~X,~Z) res
It extracts the matrix of variances and covariances from gmm
or gel
objects.
## S3 method for class 'gmm' vcov(object, ...) ## S3 method for class 'gel' vcov(object, lambda = FALSE, ...) ## S3 method for class 'tsls' vcov(object, type=c("Classical","HC0","HC1","HAC"), hacProp = list(), ...) ## S3 method for class 'ategel' vcov(object, lambda = FALSE, robToMiss = TRUE, ...)
## S3 method for class 'gmm' vcov(object, ...) ## S3 method for class 'gel' vcov(object, lambda = FALSE, ...) ## S3 method for class 'tsls' vcov(object, type=c("Classical","HC0","HC1","HAC"), hacProp = list(), ...) ## S3 method for class 'ategel' vcov(object, lambda = FALSE, robToMiss = TRUE, ...)
object |
An object of class |
lambda |
If set to TRUE, the covariance matrix of the Lagrange multipliers is produced. |
type |
Type of covariance matrix for the meat |
hacProp |
A list of arguments to pass to |
robToMiss |
If |
... |
Other arguments when |
For tsls(), if vcov is set to a different value thand "Classical", a sandwich covariance matrix is computed.
A matrix of variances and covariances
# GMM # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n,list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x) vcov(res) ## GEL ## t0 <- c(0,.5,.5) res <- gel(g, x, t0) vcov(res) vcov(res, lambda = TRUE)
# GMM # n = 500 phi<-c(.2,.7) thet <- 0 sd <- .2 x <- matrix(arima.sim(n = n,list(order = c(2,0,1), ar = phi, ma = thet, sd = sd)), ncol = 1) y <- x[7:n] ym1 <- x[6:(n-1)] ym2 <- x[5:(n-2)] H <- cbind(x[4:(n-3)], x[3:(n-4)], x[2:(n-5)], x[1:(n-6)]) g <- y ~ ym1 + ym2 x <- H res <- gmm(g, x) vcov(res) ## GEL ## t0 <- c(0,.5,.5) res <- gel(g, x, t0) vcov(res) vcov(res, lambda = TRUE)
Data used to measure return to education by Griliches (1976)
data(wage)
data(wage)
A data frame containing 20 cross-sectional vectors.
Age in 1969 and 1980 respetively
Working experience in 1969 and 1980 respetively
IQ measure of the individual
A test score
Log wage in 1969 and 1980 respectively
Mother education
Schooling in 1969 and 1980 respetively
Tenure in 1969 and 1980 respetively
http://fhayashi.fc2web.com/datasets.htm