代写辅导接单-Generalized Method of Moments and Generalized Empirical Likelihood

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top

Package ‘gmm’

October 13, 2022

Version1.7

Date2022-07-30

TitleGeneralized Method of Moments and Generalized Empirical

Likelihood

AuthorPierre Chausse

MaintainerPierre Chausse

Description

It is a complete suite to estimate models based on moment conditions. It includes the two step Gen-

eralized method of moments (Hansen 1982; ), the iterated GMM and con-

tinuous updated estimator (Hansen, Eaton and Yaron 1996; ) and sev-

eral methods that belong to the Generalized Empirical Likelihood family of estima-

tors (Smith 1997; , Kita-

mura 1997; , Newey and Smith 2004;

0262.2004.00482.x>, and Anatolyev 2005 ).

DependsR (>= 2.10.0), sandwich

NeedsCompilationyes

Suggestsknitr, mvtnorm, car, stabledist, MASS, timeDate, timeSeries

Importsstats, methods, grDevices, graphics

LicenseGPL (>= 2)

VignetteBuilderknitr

RepositoryCRAN

Repository/R-Forge/Projectgmm

Repository/R-Forge/Revision203

Repository/R-Forge/DateTimeStamp2022-08-12 02:50:41

Date/Publication2022-08-12 12:40:02 UTC

Rtopics documented:

ATEgel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

bread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

1

2ATEgel

bwWilhelm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6

charStable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

coef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

confint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

estfun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Finance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

FinRes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

fitted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

gel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

getDat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

getImpProb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

getLamb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

getModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

gmm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Growth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

KTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

marginal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

momentEstim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

nsw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

smoothG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

specTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

sysGmm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

tsls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

vcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

wage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Index56

ATEgelATE with Generalized Empirical Likelihood estimation

Description

Function to estimate the average treatment effect with the sample being balanced by GEL.

Usage

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,

ATEgel3

Lambdacontrol = list(),

model = TRUE, X = FALSE, Y = FALSE, ...)

checkConv(obj, tolConv=1e-4, verbose=TRUE, ...)

Arguments

gA formula asy~z, where codey is the response andzthe treatment indicator. If

there is more than one treatment, more indicators can be added orzcan be set

as a factor. It can also be of the formg(theta, y, z)for non-linear models. It

is however, not implemented yet.

objObject of class"ategel"produced yATEgel

balmA formula for the moments to be balanced between the treated and control

groups (see details)

yThe response variable whengis a function. Not implemented yet

treatThe treatment indicator whengis a function. Not implemented yet

wA formula to add covariates to the main regression. WhenNULL, the default

value, the main regression only include treatment indicators.

tet0A3×1vector of starting values. If not provided, they are obtained using an

OLS regression

momTypeHow 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)

popMomA 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.

familyBy 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 continu-

ous 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 prob-

abilities are bounded below by zero. In that case, an analytical Kuhn-Tucker

method is used to find the solution.

tol_lamTolerance forλbetween two iterations. The algorithm stops when‖λ

i

−λ

i−1

reachestol_lamb(seegetLamb)

maxiterlamThe algorithm to computeλstops if there is no convergence after "maxiterlam"

iterations (seegetLamb).

tol_objTolerance for the gradiant of the objective function to computeλ(seegetLamb).

optfctAlgorithm used for the parameter estimates

tol_momIt is the tolerance for the moment condition

n

t=1

p

t

g(θ(x

t

) = 0, wherep

t

=

1

n

Dρ(< g

t

,λ >)is the implied probability. It adds a penalty if the solution

diverges from its goal.

4ATEgel

optlamAlgorithm used to solve for the lagrange multiplier ingetLamb. The algorithm

Wu is only fortype="EL". The value ofoptlamis ignored for "CUE" because

in that case, the analytical solution exists.

dataA data.frame or a matrix with column names (Optional).

LambdacontrolControls for the optimization of the vector of Lagrange multipliers used by either

optim,nlminborconstrOptim

model, X, Ylogicals. IfTRUEthe corresponding components of the fit (the model frame, the

model matrix, the response) are returned if g is a formula.

verboseIf TRUE, a summary of the convergence is printed

tolConvThe tolerance for comparing moments between groups

...More options to give tooptimornlminb. IncheckConv, they are options passed

togetImpProb.

Details

We want to estimate the modelY

t

1

2

treat+

t

, whereθ

2

is the treatment effect. GEL is

used to balance the sample based on the argumentxabove.

For example, if we want the sample mean ofx1andx2to be balanced between the treated and

control, we setxto~x1+x2. If we want the sample mean ofx1,x2,x1*x2,x1^2andx2^2, we set

xto~x1*x2 + I(x1^2) + I(x2^2).

Value

’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 classgel.

References

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 Like-

lihood 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.

Examples

data(nsw)

# Scale income

nsw$re78 <- nsw$re78/1000

nsw$re75 <- nsw$re75/1000

bread5

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)

breadBread for sandwiches

Description

Computes the bread of the sandwich covariance matrix

Usage

## S3 method for class'gmm'

bread(x, ...)

## S3 method for class'gel'

bread(x, ...)

## S3 method for class'tsls'

bread(x, ...)

Arguments

xA fitted model of classgmmorgel.

...Other arguments whenbreadis applied to another class object

Details

When the weighting matrix is not the optimal one, the covariance matrix of the estimated coeffi-

cients is:(G

WG)

−1

G

WV WG(G

WG)

−1

, whereG=d ̄g/dθ,Wis the matrix of weights, and

Vis the covariance matrix of the moment function. Therefore, the bread is(G

WG)

−1

, which is

the second derivative of the objective function.

The method if not yet available forgelobjects.

Value

Ak×kmatrix (see details).

References

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.Journal of Statistical Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

6bwWilhelm

Examples

# 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))

bwWilhelmWilhelm (2015) bandwidth selection

Description

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.

Usage

bwWilhelm(x, order.by = NULL, kernel = c("Quadratic Spectral",

"Bartlett", "Parzen", "Tukey-Hanning"), approx = c("AR(1)", "ARMA(1,1)"),

weights = NULL, prewhite = 1, ar.method = "ols", data = list())

Arguments

xAn object of classgmm.

order.byEither 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).

bwWilhelm7

kerneltype of kernel used to compute the covariance matrix of the vector of sample

moment conditions (seekernHACfor more details)

approxA character specifying the approximation method if the bandwidth has to be

chosen bybwAndrews.

weightsnumeric. 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)

prewhitelogical or integer. Should the estimating functions be prewhitened? IfTRUEor

greater than 0 a VAR model of orderas.integer(prewhite)is fitted viaar

with method"ols"anddemean = FALSE.

ar.methodcharacter. Themethodargument passed toarfor prewhitening.

dataan optional data frame containing the variables in the ’order.by’ model.

Value

The function ’bwWilhelm’ returns the optimal bandwidth.

Note

The function was written by Daniel Wilhelm and is based on bwAndrews.

References

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 Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

Examples

data(Finance)

f1 <- Finance[1:300, "rm"]

f2 <- Finance[1:300, "hml"]

f3 <- Finance[1:300, "smb"]

y <- Finance[1:300,"WMK"]

## Silly example just to make it over-identified

###############################################

res <- gmm(y ~ f1, ~ f1 + f2 + f3)

summary(res)

## 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

8charStable

###################################################################

res3 <- gmm(y ~ f1, ~ f1 + f2 + f3, bw=bwWilhelm)

summary(res3)

charStableThe characteristic function of a stable distribution

Description

It computes the theoretical characteristic function of a stable distribution for two different parametriza-

tions. It is used in the vignette to illustrate the estimation of the parameters using GMM.

Usage

charStable(theta, tau, pm = 0)

Arguments

thetaVector of parameters of the stable distribution. See details.

tauA vector of numbers at which the function is evaluated.

pmThe type of parametization. It takes the values 0 or 1.

Details

The function returns the vectorΨ(θ,τ,pm)defined asE(e

ixτ

, whereτis a vector of real numbers,i

is the imaginary number,xis a stable random variable with parametersθ=(α,β,γ,δ)andpmis 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:α∈(0,2],

β∈[−1,1]andγ >0. For mode details see Nolan(2009).

Value

It returns a vector of complex numbers with the dimension equals tolength(tau).

References

Nolan J. P. (2020), Univariate Stable Distributions - Models for Heavy Tailed Data.Springer Se-

ries in Operations Research and Financial Engineering. URLhttps://edspace.american.edu/

jpnolan/stable/.

coef9

Examples

# 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)

coefCoefficients of GEL or GMM

Description

It extracts the coefficients fromgelorgmmobjects.

Usage

## S3 method for class'gmm'

coef(object, ...)

## S3 method for class'gel'

coef(object, lambda = FALSE, ...)

Arguments

objectAn object of classgelorgmmreturned by the functiongelorgmm

lambdaIf set to TRUE, the lagrange multipliers are extracted instead of the vector of

coefficients

...Other arguments whencoefis applied to an other class object

Value

Vector of coefficients

Examples

#################

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)]

10confint

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)

confintConfidence intervals for GMM or GEL

Description

It produces confidence intervals for the coefficients fromgelorgmmestimation.

Usage

## 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, ...)

Arguments

objectAn object of classgelorgmmreturned by the functiongelorgmm

parmA 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 consid-

ered.

levelThe confidence level

lambdaIf set to TRUE, the confidence intervals for the Lagrange multipliers are pro-

duced.

type’Wald’ is the usual symetric confidence interval. The thee others are based on

the inversion of the LR, LM, and J tests.

confint11

factThis 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.

corrThis 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)

xAn object of classconfintproduced byconfint.gelandconfint.gmm

digitsThe number of digits to be printed

robToMissIfTRUE, the confidence interval is based on the standard errors that are robust to

misspecification

...Other arguments whenconfintis applied to another classe object

Value

It returns a matrix with the first column being the lower bound and the second the upper bound.

References

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,

14262-280. Owen, A.B. (2001), Empirical Likelihood.Monographs on Statistics and Applied

Probability 92, Chapman and Hall/CRC

Examples

#################

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)

12estfun

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")

estfunExtracts the empirical moment function

Description

It extracts the matrix of empirical moments so that it can be used by thekernHACfunction.

Usage

## 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, ...)

Arguments

xA function of the formg(θ,y)or an×qmatrix with typical elementg

i

(θ,y

t

)for

i= 1,...qandt= 1,...,nor an object of classgmm. Seegmmfor more details.

Fortsls, it is an object of classtsls.

estfun13

objectAn object of classtsls.

yThe matrix or vector of data from which the functiong(θ,y)is computed ifgis

a function.

thetaVector of parameters ifgis a function.

...Other arguments whenestfunis applied to another class object

Details

Forestfun.gmmFct, it returns an×qmatrix with typical elementg

i

(θ,y

t

)fori= 1,...qand

t= 1,...,n. It is only used bygmmto obtain the estimates.

Forestfun.gmm, it returns the matrix of first order conditions ofmin

θ

̄g

W ̄g/2, which is an×k

matrix with thet

th

row beingg(θ,y

t

)WG, whereGisd ̄g/dθ. It allows to compute the sandwich

covariance matrix usingkernHACorvcovHACwhenWis not the optimal matrix.

The method if not yet available forgelobjects.

For tsls, model.matrix and estfun are used byvcov()to compute different covariance matrices

using thesandwichpackage. Seevcov.tsls.model.matrixreturns the fitted values frin the first

stage regression andesfunthe residuals.

Value

An×qmatrix (see details).

References

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.Journal of Statistical Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

Examples

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)

14Finance

foc[1:5,]

foc2[1:5,]

FinanceReturns on selected stocks

Description

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

Usage

data(Finance)

Format

A data frame containing 24 time series. Dates are reported as rownames(). In the following descrip-

tion, company symboles are used.

WMKReturns of WEIS MARKETS INC

UISReturns of UNISYS CP NEW

ORBReturns of ORBITAL SCIENCES CP

MATReturns of Mattel, Inc.

ABAXReturns of ABAXIS, Inc.

TReturns of AT&T INC.

EMRReturns of EMERSON ELEC CO

JCSReturns of Communications Systems Inc.

VOXXReturns of Audiovox Corp.

ZOOMReturns of ZOOM Technologies Inc.

TDWReturns of TIDEWATER INC

ROGReturns of Rogers Corporation

GGGReturns of Graco Inc.

PCReturns of Panasonic Corporation

GCOReturns of Genesco Inc.

EBFReturns of ENNIS, INC

FReturns of FORD MOTOR CO

FNMReturns of FANNIE MAE

NHPReturns of NATIONWIDE HLTH PROP

AAReturns of ALCOA INC

rfRisk-free rate of Fama-French

rmReturn of the market portfolio of Fama-French

hmlFactor High-Minus-Low of Fama-French

smbFactor Small-Minus-Big of Fama-French

FinRes15

Source

Yahoo Finance andhttps://mba.tuck.dartmouth.edu/pages/faculty/ken.french/

FinResMethod to finalize the result of the momentEstim method

Description

It computes the final results that will be needed to create the object of classgmm.).

Usage

## S3 method for class'baseGmm.res'

FinRes(z, object, ...)

Arguments

zAn object of class determined by the methodmomentEstim.

objectAn object produced mygetModel

...Other argument to be passed to otherFinResmethods.

Value

It returns an object of classgmm. Seegmmfor more details.

References

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,14262-280.

fittedFitted values of GEL and GMM

Description

Method to extract the fitted values of the model estimated bygelorgmm.

Usage

## S3 method for class'gel'

fitted(object, ...)

## S3 method for class'gmm'

fitted(object, ...)

16fitted

Arguments

objectAn object of classgelorgelreturned by the functiongelorgmm

...Other arguments whenfittedis applied to an other class object

Value

It returns a matrix of the estimated meanˆying=y~xas it is done byfitted.lm.

Examples

# 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))

formula17

formulaFormula method for gel and gmm objects

Description

Method to extract the formula fromgelorgmmobjects.

Usage

## S3 method for class'gel'

formula(x, ...)

## S3 method for class'gmm'

formula(x, ...)

Arguments

xAn object of classgelorgmmreturned by the functiongelorgmm

...Other arguments to pass to other methods

Examples

## 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

18gel

res <- gmm(y ~ x, x)

formula(res)

gelGeneralized Empirical Likelihood estimation

Description

Function to estimate a vector of parameters based on moment conditions using the GEL method as

presented by Newey-Smith(2004) and Anatolyev(2005).

Usage

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, ...)

Arguments

gA function of the formg(θ,x)and which returns an×qmatrix with typical

elementg

i

(θ,x

t

)fori= 1,...qandt= 1,...,n. This matrix is then used to

build the q sample moment conditions. It can also be a formula if the model is

linear (see details below).

tet0Ak×1vector of starting values. If the dimension ofθis one, see the argument

"optfct". In the linear case, if tet0=NULL, the 2-step gmm estimator is used as

starting value. However, it has to be provided when eqConst is not NULL

xThe matrix or vector of data from which the functiong(θ,x)is computed. If "g"

is a formula, it is ann×Nhmatrix of instruments (see details below).

gel19

gradvA function of the formG(θ,x)which returns aq×kmatrix of derivatives of ̄g(θ)

with respect toθ. By default, the numerical algorithmnumericDerivis used.

It is of course strongly suggested to provide this function when it is possible.

This gradiant is used compute the asymptotic covariance matrix of

ˆ

θ. If "g" is a

formula, the gradiant is not required (see the details below).

smoothIf set to TRUE, the moment function is smoothed as proposed by Kitamura(1997)

type"EL" for empirical likelihood, "ET" for exponential tilting, "CUE" for continu-

ous 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 prob-

abilities are bounded below by zero. In that case, an analytical Kuhn-Tucker

method is used to find the solution.

kerneltype of kernel used to compute the covariance matrix of the vector of sample

moment conditions (seekernHACfor more details) and to smooth the moment

conditions if "smooth" is set to TRUE. Only two types of kernel are available.

The truncated implies a Bartlett kernel for the HAC matrix and the Bartlett im-

plies a Parzen kernel (see Smith 2004).

bwThe method to compute the bandwidth parameter. By default it isbwAndrews

which is proposed by Andrews (1991). The alternative isbwNeweyWestof

Newey-West(1994).

prewhitelogical or integer. Should the estimating functions be prewhitened? IfTRUEor

greater than 0 a VAR model of orderas.integer(prewhite)is fitted viaar

with method"ols"anddemean = FALSE.

ar.methodcharacter. Themethodargument passed toarfor prewhitening.

approxa character specifying the approximation method if the bandwidth has to be

chosen bybwAndrews.

tol_weightsnumeric. Weights that exceedtolare used for computing the covariance matrix,

all other weights are treated as 0.

tol_lamTolerance forλbetween two iterations. The algorithm stops when‖λ

i

−λ

i−1

reachestol_lamb(seegetLamb)

maxiterlamThe algorithm to computeλstops if there is no convergence after "maxiterlam"

iterations (seegetLamb).

tol_objTolerance for the gradiant of the objective function to computeλ(seegetLamb).

optfctOnly when the dimension ofθis 1, you can choose between the algorithmoptim

oroptimize. In that case, the former is unreliable. Ifoptimizeis chosen, "t0"

must be1×2which represents the interval in which the algorithm seeks the

solution.It is also possible to choose thenlminbalgorithm. In that case, borns

for the coefficients can be set by the optionsupper=andlower=.

constraintIf set to TRUE, the constraint optimization algorithm is used. SeeconstrOptim

to learn how it works. In particular, if you choose to use it, you need to provide

"ui" and "ci" in order to impose the constraintuiθ−ci≥0.

tol_momIt is the tolerance for the moment condition

n

t=1

p

t

g(θ(x

t

) = 0, wherep

t

=

1

n

Dρ(< g

t

,λ >)is the implied probability. It adds a penalty if the solution

diverges from its goal.

20gel

optlamAlgorithm used to solve for the lagrange multiplier ingetLamb. The algorithm

Wu is only fortype="EL". The value ofoptlamis ignored for "CUE" because

in that case, the analytical solution exists.

dataA data.frame or a matrix with column names (Optional).

LambdacontrolControls for the optimization of the vector of Lagrange multipliers used by either

optim,nlminborconstrOptim

model, X, Ylogicals. IfTRUEthe corresponding components of the fit (the model frame, the

model matrix, the response) are returned if g is a formula.

TypeGelThe name of the class object created by the methodgetModel. It allows devel-

opers to extand the package and create other GEL methods.

alphaRegularization coefficient for discrete CGEL estimation (experimental). By set-

ting alpha to any value, the model is estimated by CGEL of type specified by

the optiontype. See Chausse (2011)

eqConstEither a named vector (if "g" is a function), a simple vector for the nonlinear

case indicating which of theθ

0

is restricted, or a qx2 vector defining equality

constraints of the formθ

i

=c

i

. Seegmmfor an example.

eqConstFullVcov

If FALSE, the constrained coefficients are assumed to be fixed and only the co-

variance of the unconstrained coefficients is computed. If TRUE, the covariance

matrix of the full set of coefficients is computed.

onlyCoefficients

IfTRUE, only the vector of coefficients and Lagrange multipliers are returned

...More options to give tooptim,optimizeorconstrOptim.

Details

If we want to estimate a model likeY

t

1

+X

2t

θ

2

+...+X

k

θ

k

+

t

using the moment conditions

Cov(

t

H

t

) = 0, whereH

t

is a vector ofNhinstruments, than we can define "g" like we do forlm.

We would haveg = y~x2+x3+...+xkand the argument "x" above would become the matrix H of

instruments. As forlm,Y

t

can be aNy×1vector which would imply thatk=Nh×Ny. The

intercept is included by default so you do not have to add a column of ones to the matrixH. You do

not need to provide the gradiant in that case since in that case it is embedded ingel. 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

n

t=1

g(θ,x

t

)is replaced by:

n

t=1

g

k

(θ,x

t

),

whereg

k

(θ,x

t

) =

r

i=−r

k(i)g(θ,x

t+i

), whereris a truncated parameter that depends on the

bandwidth andk(i)are normalized weights so that they sum to 1.

The method solves

ˆ

θ= arg min

[

arg max

λ

1

n

n

t=1

ρ(< g(θ,x

t

),λ >)−ρ(0)

]

evalGelgenerates 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.

gel21

Value

’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:

coefficientsk×1vector of parameters

residualsthe residuals, that is response minus fitted values if "g" is a formula.

fitted.valuesthe fitted mean values if "g" is a formula.

lambdaq×1vector of Lagrange multipliers.

vcov_parthe covariance matrix of "coefficients"

vcov_lambdathe covariance matrix of "lambda"

ptThe implied probabilities

objectivethe value of the objective function

conv_lambdaConvergence code for "lambda" (seegetLamb)

conv_mesConvergence message for "lambda" (seegetLamb)

conv_parConvergence code for "coefficients" (seeoptim,optimizeorconstrOptim)

termsthetermsobject used when g is a formula.

callthe matched call.

yif requested, the response used (if "g" is a formula).

xif requested, the model matrix used if "g" is a formula or the data if "g" is a

function.

modelif requested (the default), the model frame used if "g" is a formula.

References

Anatolyev, S. (2005), GMM, GEL, Serial Correlation, and Asymptotic Bias.Econometrica,73,

983-1002.

Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Esti-

mation.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 Auto-

correlation 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.

22gel

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 Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

Chausse (2010), Computing Generalized Method of Moments and Generalized Empirical Likeli-

hood 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.

Examples

# 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

getDat23

res <- gel(g, x, c(0, .3, .6))

summary(res)

# Using evalGel to create the object without estimation

res <- evalGel(g, x, res$coefficients)

getDatExtracting data from a formula

Description

It extract the data from a formula y~z with instrument h and put everything in a matrix. It helps

redefine the functiong(θ,x)that is required bygmmandgel.

Usage

getDat(formula, h, data, error=TRUE)

Arguments

formulaA formula that defines the linear model to be estimated (see details).

hAn×nhmatrix of intruments(see details).

dataA data.frame or a matrix with colnames (Optionnal).

errorIf FALSE, the data is generated without giving any error message

Details

The model to be estimated is based on the moment conditions< h,(y−zθ)>= 0. 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 forsysGmmwith common coefficients because the check is only valid for equation

by equation identification.

Value

x: An×lmatrix, wherel=ncol(y) +ncol(z) +ncol(h) + 2if "intercept" is TRUE and

ncol(y) +ncol(z) +xcol(h)if "intercept" is FALSE.

nh: dimension of h

k: dimension of z

ny: dimension of y

24getImpProb

Examples

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)

getImpProbImplied Probabilities

Description

It computes the implied probabilities from objects of classgelwith additional options.

Usage

## S3 method for class'gel'

getImpProb(object, posProb=TRUE, normalize=TRUE,

checkConv=FALSE,...)

Arguments

objectObject of classgel.

posProbShould the implied probabilities be transformed into positive probabilities?

normalizeShould we normalize the probabilities so that they sum to one?

checkConvShould 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

Value

A vector af implied probabilities.

References

Newey, W.K. and Smith, R.J. (2004), Higher Order Properties of GMM and Generalized Empirical

Likelihood Estimators.Econometrica,72, 219-255.

getLamb25

Examples

#################

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)

getLambSolving for the Lagrange multipliers of Generalized Empirical Likeli-

hood (GEL)

Description

It computes the vector of Lagrange multipliers, which maximizes the GEL objective function, using

an iterative Newton method.

Usage

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())

Arguments

gtAn×qmatrix with typical elementg

i

(θ,x

t

)

l0Vector of starting values for lambda

type"EL" for empirical likelihood, "ET" for exponential tilting, "CUE" for continu-

ous updated estimator, and "HD" for Hellinger Distance. See details for "ETEL"

and "ETHD". "RCUE" is a restricted version of "CUE" in which the probabili-

ties are bounded below by zero. In that case, an analytical Kuhn-Tucker method

is used to find the solution.

tol_lamTolerance forλbetween two iterations. The algorithm stops when‖λ

i

−λ

i−1

reachestol_lam

26getLamb

maxiterlamThe algorithm stops if there is no convergence after "maxiterlam" iterations.

tol_objTolerance for the gradiant of the objective function. The algorithm returns a

non-convergence message ifmax(|gradiant|)does not reachtol_obj. It helps

thegelalgorithm to select the right space to look forθ

kIt represents the ratio k1/k2, wherek1 =

−∞

k(s)dsandk2 =

−∞

k(s)

2

ds.

See Smith(2004).

methodThe iterative procedure uses a Newton method for solving the FOC. It i however

recommended to useoptimornlminb. If type is set to "EL" and method to

"optim",constrOptimis called to preventlog(1−gt

λ)from producing NA.

The gradient and hessian is provided tonlminbwhich speed up the convergence.

The latter is therefore the default value. "Wu" is for "EL" only. It uses the

algorithm of Wu (2005). The value ofmethodis ignored for "CUE" because in

that case, the analytical solution exists.

controlControls to send tooptim,nlminborconstrOptim

Details

It solves the problemmax

λ

1

n

n

t=1

ρ(gt

λ). For the type "ETEL", it is only used bygel. In

that caseλis obtained by maximizing

1

n

n

t=1

ρ(gt

λ), usingρ(v) =−expv(so ET) andθby

minimizing the same equation but withρ(v)−log (1−v). To avoid NA’s,constrOptimis used

with the restrictionλ

g

t

<1. The type "ETHD" is experimental and proposed by Antoine-Dovonon

(2015). The paper is not yet available.

Value

lambda: Aq×1vector of Lagrange multipliers which solve the system of equations given above.

conv: Details on the type of convergence.

References

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.

Examples

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

getModel27

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")

getModelMethod for setting the properties of a model

Description

It collects what is needed by the methodmomentEstim(see details).

Usage

## 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, ...)

Arguments

objectAn object of classbaseGmm

...Other arguments whengetModelis applied to another class object

Value

It returns an object of the right class which determines how the methodmomentEstimwill treat it.

For example, ifgis a formula andtypeis set to "cue", it creates an object of classbaseGmm.cue.formula.

It this case,momentEstim, applied to this object, computes the continuously updated GMM of a lin-

ear 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

associatedmomentEstimemethod.

28gmm

gmmGeneralized method of moment estimation

Description

Function to estimate a vector of parameters based on moment conditions using the GMM method

of Hansen(82).

Usage

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)

Arguments

gA function of the formg(θ,x)and which returns an×qmatrix with typical

elementg

i

(θ,x

t

)fori= 1,...qandt= 1,...,n. This matrix is then used to

build the q sample moment conditions. It can also be a formula if the model is

linear (see details below).

xThe matrix or vector of data from which the functiong(θ,x)is computed. If

"g" is a formula, it is ann×Nhmatrix of instruments or a formula (see details

below).

t0Ak×1vector of starting values. It is required only when "g" is a function

because only then a numerical algorithm is used to minimize the objective func-

tion. If the dimension ofθis one, see the argument "optfct".

tetwAk×1vector to compute the weighting matrix.

gradvA function of the formG(θ,x)which returns aq×kmatrix of derivatives of ̄g(θ)

with respect toθ. By default, the numerical algorithmnumericDerivis used.

It is of course strongly suggested to provide this function when it is possible.

This gradient is used to compute the asymptotic covariance matrix of

ˆ

θand to

obtain the analytical gradient of the objective function if the method is set to

"CG" or "BFGS" inoptimand if "type" is not set to "cue". If "g" is a formula,

the gradiant is not required (see the details below).

gmm29

typeThe 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)

wmatrixWhich weighting matrix should be used in the objective function. By default, it

is the inverse of the covariance matrix ofg(θ,x). The other choice is the identity

matrix which is usually used to obtain a first step estimate ofθ

vcovAssumption 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.

kerneltype of kernel used to compute the covariance matrix of the vector of sample

moment conditions (seekernHACfor more details)

critThe stopping rule for the iterative GMM. It can be reduce to increase the preci-

sion.

bwThe method to compute the bandwidth parameter in the HAC weighting matrix.

The default islink{bwAndrews}(as proposed in Andrews (1991)), which mini-

mizes the MSE of the weighting matrix. Alternatives arelink{bwWilhelm}(as

proposed in Wilhelm (2015)), which minimizes the mean-square error (MSE) of

the resulting GMM estimator, andlink{bwNeweyWest}(as proposed in Newey-

West(1994)).

prewhitelogical or integer. Should the estimating functions be prewhitened? IfTRUEor

greater than 0 a VAR model of orderas.integer(prewhite)is fitted viaar

with method"ols"anddemean = FALSE.

ar.methodcharacter. Themethodargument passed toarfor prewhitening.

approxA character specifying the approximation method if the bandwidth has to be

chosen bybwAndrews.

tolWeights that exceedtolare used for computing the covariance matrix, all other

weights are treated as 0.

itermaxThe maximum number of iterations for the iterative GMM. It is unlikely that the

algorithm does not converge but we keep it as a safety.

optfctOnly when the dimension ofθis 1, you can choose between the algorithmoptim

oroptimize. In that case, the former is unreliable. Ifoptimizeis chosen,

"t0" must be1×2which represents the interval in which the algorithm seeks

the solution. It is also possible to choose thenlminbalgorithm. In that case,

boundaries for the coefficients can be set by the optionsupper=andlower=.

TheconstrOptimis only available for nonlinear models for now. The standard

errors may have to be corrected if the estimtes reach the boundary set by ui and

ci.

model, X, Ylogical. IfTRUEthe corresponding components of the fit (the model frame, the

model matrix, the response) are returned if g is a formula.

TypeGmmThe name of the class object created by the methodgetModel. It allows devel-

opers to extend the package and create other GMM methods.

centeredVcovShould the moment function be centered when computing its covariance matrix.

Doing so may improve inference.

30gmm

weightsMatrixIt allows users to providegmmwith a fixed weighting matrix. This matrix must

beq×q, symmetric and strictly positive definite. When provided, thetype

option becomes irrelevant.

traceIterTracing information for GMM of type "iter"

dataA data.frame or a matrix with column names (Optional).

eqConstEither a named vector (if "g" is a function), a simple vector for the nonlinear

case indicating which of theθ

0

is restricted, or a qx2 vector defining equality

constraints of the formθ

i

=c

i

. See below for an example.

which, valueThe 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.

objObject of class "gmm"

eqConstFullVcov

If FALSE, the constrained coefficients are assumed to be fixed and only the co-

variance of the unconstrained coefficients is computed. If TRUE, the covariance

matrix of the full set of coefficients is computed.

mustarIf 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 toTRUE, the function only returns the coefficient estimates. It may be of

interest when the standard errors are not needed

...More options to give tooptim.

Details

If we want to estimate a model likeY

t

1

+X

2t

θ

2

+···+X

k

θ

k

+

t

using the moment conditions

Cov(

t

H

t

) = 0, whereH

t

is a vector ofNhinstruments, than we can define "g" like we do forlm.

We would haveg=y ̃x2 +x3 +···+xkand the argument "x" above would become the matrix H

of instruments. As forlm,Y

t

can be aNy×1vector which would imply thatk=Nh×Ny. The

intercept is included by default so you do not have to add a column of ones to the matrixH. You do

not need to provide the gradiant in that case since in that case it is embedded ingmm. 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

{1,z

1

,z

2

,z

3

}, we can set "x" to ̃z1 +z2 +z3. By default, a column of ones is added. To remove

it, set "x" to ̃z1 +z2 +z3−1.

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 condi-

tions:

m

1

=μ−x

i

m

2

2

−(x

i

−μ)

2

m

3

=x

3

i

−μ(μ

2

+ 3σ

2

)

gmm31

m

1

,m

2

can be directly obtained by the definition of(μ,σ). The third moment condition comes

from the third derivative of the moment generating function (MGF)

M

X

(t) =exp

(

μt+

σ

2

t

2

2

)

evaluated at(t= 0).

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):

10

−2μ+ 2x2σ

−3μ

2

−3σ

2

−6μσ

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.,

Value

’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:

coefficientsk×1vector of coefficients

residualsthe residuals, that is response minus fitted values if "g" is a formula.

fitted.valuesthe fitted mean values if "g" is a formula.

vcovthe covariance matrix of the coefficients

objectivethe value of the objective function‖var( ̄g)

−1/2

̄g‖

2

termsthetermsobject used when g is a formula.

callthe matched call.

yif requested, the response used (if "g" is a formula).

xif requested, the model matrix used if "g" is a formula or the data if "g" is a

function.

modelif requested (the default), the model frame used if "g" is a formula.

algoInfoInformation produced by eitheroptimornlminbrelated to the convergence if

"g" is a function. It is printed by thesummary.gmmmethod.

32gmm

References

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.Journal of Statistical Soft-

ware,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 Esti-

mation.Econometrica,59, 817–858.

Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Auto-

correlation 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,14262-280.

Examples

## 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

gmm33

## 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)

34gmm

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.

Growth35

######################################

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)

GrowthGrowth Data

Description

Panel of Macroeconomic data for 125 countries from 1960 to 1985 constructed by Summers and

Heston (1991))

Usage

data(Growth)

Format

A data frame containing 9 vectors.

Country_IDCountry identification number

COM1 if the country is in a communist regime, 0 otherwise

OPEC1 if the country is part of the OPEC, 0 otherwise

YearYear

GDPPer capita GDP (in thousands) in 1985 U.S. dollars.

LagGDPGDP of the previous period

SavRateSaving rate measured as the ratio of real investment to real GDP

LagSavRateSavRate of the previous period

CountryCountry names

PopPopulation in thousands

LagPopPopulation of the previous period

36KTest

Source

http://fhayashi.fc2web.com/datasets.htm

KTestCompute the K statistics of Kleibergen

Description

The test is proposed by Kleibergen (2005). It is robust to weak identification.

Usage

KTest(obj, theta0 = NULL, alphaK = 0.04, alphaJ = 0.01)

## S3 method for class'gmmTests'

print(x, digits = 5, ...)

Arguments

objObject of class "gmm" returned bygmm

theta0The null hypothesis being tested. See details.

alphaK, alphaJThe size of the J and K tests when combining the two. The overall size is

alphaK+alphaJ.

xAn object of classgmmTestsreturned byKTest

digitsThe number of digits to be printed

...Other arguments whenprintis applied to another class object

Details

The function produces the J-test and K-statistics which are robust to weak identification. The test is

eitherH0 :θ=theta

0

, in which case theta0 must be provided, orβ=β

0

, 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β

0

. Seegmmand the option "eqConst" for more details.

Value

Tests and p-values

References

Keibergen, F. (2005), Testing Parameters in GMM without assuming that they are identified.Econo-

metrica,73, 1103-1123,

marginal37

Examples

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)

marginalMarginal effects Summary

Description

It produces the summary table of marginal effects for GLM estimation with GEL. Only imple-

mented for ATEgel.

Usage

## S3 method for class'ategel'

marginal(object, ...)

Arguments

objectAn object of classategelreturned by the functionATEgel

...Other arguments for other methods

Value

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.

38momentEstim

References

Owen, A.B. (2001), Empirical Likelihood.Monographs on Statistics and Applied Probability 92,

Chapman and Hall/CRC

Examples

## 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)

momentEstimMethod for estimating models based on moment conditions

Description

It estimates a model which is caracterized by the methodgetModel(see details).

Usage

## 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'

nsw39

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, ...)

Arguments

objectAn object created by the methodgetModel

...Other arguments whenmomentEstimis applied to an other class object

Value

It returns an object of class determined by the argument "TypeGMM" ofgmm. By default, it is of

classbaseGmm.res. It estimates the model and organize the results that will be finalized by the

methodFinRes. More methods can be created in order to use other GMM methods not yet included

in the package.

References

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,14262-280.

nswLalonde subsample of the National Supported Work Demonstration

Data (NSW)

Description

This data was collected to evaluate the National Supported Work (NSW) Demonstration project in

Lalonde (1986).

40nsw

Usage

data(nsw)

Format

A data frame containing 9 variables.

treatTreatment assignment

ageAge

edYears of Education

black1 if Black, 0 otherwise

hisp1 if Hispanic 0 otherwise

married1 if married 0 otherwise

nodeg1 if no college degree 0 otherwise

re751975 earnings

re781978 earnings

Details

The dataset was obtained from the ATE package (see reference).

Source

"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

References

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

plot41

plotPlot Diagnostics for gel and gmm objects

Description

It is a plot method forgelorgmmobjects.

Usage

## 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"))

Arguments

x gelorgmmobject, typically result ofgelorgmm.

whichif a subset of the plots is required, specify a subset of the numbers1:4forgel

or1:3forgmm.

mainVector of titles for each plot.

panelpanel function. The useful alternative topoints,panel.smoothcan be chosen

byadd.smooth = TRUE.

asklogical; ifTRUE, the user isasked before each plot, seepar(ask=.).

...other parameters to be passed through to plotting functions.

add.smoothlogical indicating if a smoother should be added to most plots; see alsopanel

above.

Details

It is a beta version of a plot method forgelobjects. It is a modified version ofplot.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 byplot.lm, the

third is the dependant variableywith its meanˆy(the fitted values) and the last plots the implied

probabilities with the empirical density1/T.

42print

Examples

# 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)

printPrinting a gmm or gel object

Description

It is a printing method forgmmorgelobjects.

Usage

## 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, ...)

Arguments

xAn object of classgmmorgelreturned by the functiongmmorgel

digitsThe number of digits to be printed

...Other arguments when print is applied to an other class object

residuals43

Value

It prints some results from the estimation like the coefficients and the value of the objective function.

Examples

# 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)

residualsResiduals of GEL or GMM

Description

Method to extract the residuals of the model estimated bygmmorgel.

Usage

## S3 method for class'gel'

residuals(object, ...)

## S3 method for class'gmm'

residuals(object, ...)

Arguments

objectAn object of classgmmorgelreturned by the functiongmmorgel

...Other arguments whenresidualsis applied to an other classe object

44smoothG

Value

It returns the matrix of residuals(y−ˆy)ing=y~xas it is done byresiduals.lm.

Examples

# 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")

smoothGKernel smoothing of a matrix of time series

Description

It applies the required kernel smoothing to the moment function in order for the GEL estimator to

be valid. It is used by thegelfunction.

smoothG45

Usage

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)

Arguments

xan×qmatrix of time series, where n is the sample size.

bwThe method to compute the bandwidth parameter. By default, it uses the band-

width proposed by Andrews(1991). As an alternative, we can choose bw=bwNeweyWest

(without "") which is proposed by Newey-West(1996).

prewhitelogical or integer. Should the estimating functions be prewhitened? IfTRUEor

greater than 0 a VAR model of orderas.integer(prewhite)is fitted viaar

with method"ols"anddemean = FALSE.

ar.methodcharacter. Themethodargument passed toarfor prewhitening.

weightsThe smoothing weights can be computed byweightsAndrewsof it can be pro-

vided manually. If provided, it has to be ar×1vector (see details).

approxa character specifying the approximation method if the bandwidth has to be

chosen bybwAndrews.

tolnumeric. Weights that exceedtolare used for computing the covariance matrix,

all other weights are treated as 0.

kernelThe choice of kernel

Details

The sample moment conditions

n

t=1

g(θ,x

t

)is replaced by:

n

t=1

g

k

(θ,x

t

), whereg

k

(θ,x

t

) =

r

i=−r

k(i)g(θ,x

t+i

), whereris a truncated parameter that depends on the bandwidth andk(i)

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),k(i)will become(.25,.5,1,.5,.25)/(.25 +.5 + 1 +.5 +.25) = (.1,.2,.4,.2,.1)

Value

smoothx: Aq×qmatrix containing an estimator of the asymptotic variance of

n ̄x, where ̄xis

q×1vector with typical element ̄x

i

=

1

n

n

j=1

x

ji

. This function is called bygelbut can also be

used by itself.

kern_weights: Vector of weights used for the smoothing.

References

Anatolyev, S. (2005), GMM, GEL, Serial Correlation, and Asymptotic Bias.Econometrica,73,

983-1002.

Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Esti-

mation.Econometrica,59, 817–858.

Kitamura, Yuichi (1997), Empirical Likelihood Methods With Weakly Dependent Processes.The

Annals of Statistics,25, 2084-2102.

46specTest

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.Journal of Statistical Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

Examples

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])

specTestCompute tests of specification

Description

Generic function for testing the specification of estimated models. It computes the J-test fromgmm

objects and J-test, LR-test and LM-test fromgelobjects.

Usage

## 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, ...)

Arguments

xA fitted model object.

digitsThe number of digits to be printed.

...Arguments passed to methods.

Value

Tests and p-values

summary47

References

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, Insti-

tute for Fiscal Studies

Examples

#################

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)

summaryMethod for object of class gmm or gel

Description

It presents the results from thegmmorgelestimation in the same fashion assummarydoes for the

lmclass objects for example. It also compute the tests for overidentifying restrictions.

Usage

## S3 method for class'gmm'

summary(object, ...)

## S3 method for class'sysGmm'

summary(object, ...)

## S3 method for class'gel'

summary(object, ...)

48summary

## 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, ...)

Arguments

objectAn object of classgmmorgelreturned by the functiongmmorgel

xAn object of classsummary.gmmorsummary.gelreturned by the functionsummary.gmm

summary.gel

digitsThe number of digits to be printed

vcovAn alternative covariance matrix computed withvcov.tsls

robToMissIfTRUE, it computes the robust to misspecification covariance matrix

...Other arguments when summary is applied to another class object

Value

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 thatE(g(θ,X) = 0

References

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,14262-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.

Examples

# GMM #

set.seed(444)

n = 500

sysGmm49

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)

sysGmmGeneralized method of moment estimation for system of equations

Description

Functions to estimate a system of equations based on GMM.

Usage

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)

50sysGmm

Arguments

gA possibly named list of formulas

hA formula if the same instruments are used in each equation or a list of formulas.

wmatrixWhich weighting matrix should be used in the objective function. By default, it

is the inverse of the covariance matrix ofg(θ,x). The other choice is the identity

matrix.

vcovAssumption on the properties of the moment vector. By default, it is a martin-

gale difference sequence. "HAC" is for weakly dependent processes and "Cond-

Hom" implies conditional homoscedasticity. The option "TrueFixed" is used

only when the matrix of weights is provided and it is the optimal one.

kerneltype of kernel used to compute the covariance matrix of the vector of sample

moment conditions (seekernHACfor more details)

critThe stopping rule for the iterative GMM. It can be reduce to increase the preci-

sion.

bwThe method to compute the bandwidth parameter. By default it isbwAndrews

which is proposed by Andrews (1991). The alternative isbwNeweyWestof

Newey-West(1994).

prewhitelogical or integer. Should the estimating functions be prewhitened? IfTRUEor

greater than 0 a VAR model of orderas.integer(prewhite)is fitted viaar

with method"ols"anddemean = FALSE.

ar.methodcharacter. Themethodargument passed toarfor prewhitening.

approxA character specifying the approximation method if the bandwidth has to be

chosen bybwAndrews.

tolWeights that exceedtolare used for computing the covariance matrix, all other

weights are treated as 0.

model, X, Ylogical. IfTRUEthe corresponding components of the fit (the model frame, the

model matrix, the response) are returned if g is a formula.

centeredVcovShould the moment function be centered when computing its covariance matrix.

Doing so may improve inference.

weightsMatrixIt allows users to providegmmwith a fixed weighting matrix. This matrix must

beq×q, symmetric and strictly positive definite. When provided, thetype

option becomes irrelevant.

dataA data.frame or a matrix with column names (Optional).

commonCoefIf true, coefficients accross equations are the same

crossEquConstOnly 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 formulasg. Setting it to1:kis

equivalent to setting commonCoef to TRUE.

Details

This set of functions implement the estimation of system of equations as presented in Hayashi

(2000)

sysGmm51

Value

’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:

coefficientslist of vectors of coefficients for each equation

residualslist of the residuals for each equation.

fitted.valueslist of the fitted values for each equation.

vcovthe covariance matrix of the stacked coefficients

objectivethe value of the objective function‖var( ̄g)

−1/2

̄g‖

2

termsThe list oftermsobjects for each equation

callthe matched call.

yIf requested, a list of response variables.

xif requested, a list of the model matrices.

modelif requested (the default), a list of the model frames.

References

Zeileis A (2006), Object-oriented Computation of Sandwich Estimators.Journal of Statistical Soft-

ware,16(9), 1–16. URL doi:10.18637/jss.v016.i09.

Andrews DWK (1991), Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Esti-

mation.Econometrica,59, 817–858.

Newey WK & West KD (1987), A Simple, Positive Semi-Definite, Heteroskedasticity and Auto-

correlation 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.

Examples

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)

52tsls

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)

tslsTwo stage least squares estimation

Description

Function to estimate a linear model by the two stage least squares method.

Usage

tsls(g,x,data)

Arguments

gA formula describing the linear regression model (see details below).

xThe matrix of instruments (see details below).

dataA data.frame or a matrix with column names (Optionnal).

Details

The function just callsgmmwith the option vcov="iid". It just simplifies the the implementation of

2SLS. The users don’t have to worry about all the options offered ingmm. The model is

Y

i

=X

i

β+u

i

In the first step,lmis used to regressX

i

on the set of instrumentsZ

i

. The second step also useslm

to regressY

i

on the fitted values of the first step.

Value

’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:

vcov53

coefficientsk×1vector of coefficients

residualsthe residuals, that is response minus fitted values if "g" is a formula.

fitted.valuesthe fitted mean values if "g" is a formula.

vcovthe covariance matrix of the coefficients

objectivethe value of the objective function‖var( ̄g)

−1/2

̄g‖

2

termsthetermsobject used when g is a formula.

callthe matched call.

yif requested, the response used (if "g" is a formula).

xif requested, the model matrix used if "g" is a formula or the data if "g" is a

function.

modelif requested (the default), the model frame used if "g" is a formula.

algoInfoInformation produced by eitheroptimornlminbrelated to the convergence if

"g" is a function. It is printed by thesummary.gmmmethod.

References

Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators.

Econometrica,50, 1029-1054,

Examples

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

vcovVariance-covariance matrix of GMM or GEL

Description

It extracts the matrix of variances and covariances fromgmmorgelobjects.

54vcov

Usage

## 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, ...)

Arguments

objectAn object of classgmmorgmmreturned by the functiongmmorgel

lambdaIf set to TRUE, the covariance matrix of the Lagrange multipliers is produced.

typeType of covariance matrix for the meat

hacPropA list of arguments to pass tokernHAC

robToMissIfTRUE, it computes the robust to misspecification covariance matrix

...Other arguments whenvcovis applied to another class object

Details

For tsls(), if vcov is set to a different value thand "Classical", a sandwich covariance matrix is

computed.

Value

A matrix of variances and covariances

Examples

# 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)

wage55

## GEL ##

t0 <- c(0,.5,.5)

res <- gel(g, x, t0)

vcov(res)

vcov(res, lambda = TRUE)

wageLabor Data

Description

Data used to measure return to education by Griliches (1976)

Usage

data(wage)

Format

A data frame containing 20 cross-sectional vectors.

AGE, AGE80Age in 1969 and 1980 respetively

EXPR, EXPR80Working experience in 1969 and 1980 respetively

IQIQ measure of the individual

KWWA test score

LW, LW80Log wage in 1969 and 1980 respectively

MEDMother education

MRT, MRT80

RNS, RNS80

S, S80Schooling in 1969 and 1980 respetively

SMSA, SMSA80

TENURE, TENURE80Tenure in 1969 and 1980 respetively

YEAR

Source

http://fhayashi.fc2web.com/datasets.htm

Index

∗datasets

Finance, 14

Growth, 35

nsw, 39

wage, 55

ar,7,19,29,45,50

ATEgel, 2,37

bread, 5

bwAndrews,7,19,50

bwNeweyWest,19,50

bwWilhelm, 6

charStable, 8

checkConv(ATEgel), 2

coef, 9

confint, 10

constrOptim,4,19–21,26,29

estfun, 12

evalGel,20

evalGel(gel), 18

evalGmm(gmm), 28

Finance, 14

FinRes, 15

fitted, 15

five(sysGmm), 49

formula, 17

gel,4,9, 10,15–17, 18,20,23,26,41–43,45,

48,54

getDat, 23

getImpProb,4, 24

getLamb,3, 4,19–21, 25

getModel, 27

gmm,9, 10,12,15–17,20,23, 28,30,36,39,

41–43,48,52,54

gmmWithConst(gmm), 28

Growth, 35

kernHAC,7,12, 13,19,29,50,54

KTest, 36

lm,20,30,52

marginal, 37

model.matrix.tsls(estfun), 12

momentEstim, 38

nlminb,4,19, 20,26,29,31,53

nsw, 39

optim,4,19–21,26,28–31,53

optimize,19–21,29

panel.smooth,41

par,41

plot, 41

points,41

print, 42

print.confint(confint), 10

print.gmmTests(KTest), 36

print.specTest(specTest), 46

print.summary.gel(summary), 47

print.summary.gmm(summary), 47

print.summary.sysGmm(summary), 47

print.summary.tsls(summary), 47

randEffect(sysGmm), 49

residuals, 43

sandwich,13

smoothG, 44

specTest, 46

summary, 47

summary.ategel(summary), 47

summary.gel,48

summary.gel(summary), 47

summary.gmm,48

summary.gmm(summary), 47

summary.sysGmm(summary), 47

56

INDEX57

summary.tsls(summary), 47

sur(sysGmm), 49

sysGmm,23, 49

terms,21,31,51,53

threeSLS(sysGmm), 49

tsls,12, 52

vcov, 53

vcov.tsls,13

vcovHAC,13

wage, 55

weightsAndrews,45

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: Fudaojun0228