momentModel: Constructor for '"momentModel"' classes

View source: R/momentModel.R

momentModelR Documentation

Constructor for "momentModel" classes

Description

It builds an object class "momentModel", which is a union class for "linearModel", "nonlinearModel", "formulaModel" and "functionModel" classes. These are classes for moment based models. This is the first step before running any estimation algorithm.

Usage

momentModel(g, x=NULL, theta0=NULL,grad=NULL,
            vcov = c("iid", "HAC", "MDS", "CL"),
            vcovOptions=list(), centeredVcov = TRUE, data=parent.frame(),
            na.action="na.omit", survOptions=list(), smooth=FALSE)

Arguments

g

A function of the form g(\theta,x) and which returns a n \times q matrix with typical element g_i(\theta,x_t) for i=1,...q and t=1,...,n. This matrix is then used to build the q sample moment conditions. It can also be a formula if the model is linear (see detailsbelow).

x

The matrix or vector of data from which the function g(\theta,x) is computed. If "g" is a formula, it is an n \times Nh matrix of instruments or a formula (see details below).

theta0

A k \times 1 vector of starting values. It is required only when "g" is a function because only then a numerical algorithm is used to minimize the objective function. If the dimension of \theta is one, see the argument "optfct".

grad

A function of the form G(\theta,x) which returns a q\times k matrix of derivatives of \bar{g}(\theta) with respect to \theta. By default, the numerical algorithm numericDeriv is used. It is of course strongly suggested to provide this function when it is possible. This gradient is used to compute the asymptotic covariance matrix of \hat{\theta} and to obtain the analytical gradient of the objective function if the method is set to "CG" or "BFGS" in optim and if "type" is not set to "cue". If "g" is a formula, the gradiant is not required (see the details below).

vcov

Assumption on the properties of the moment conditions. By default, they are weakly dependant processes. For MDS, we assume that the conditions are martingale difference sequences, which implies they are serially uncorrelated, but may be heteroscedastic. There is a difference between iid and MDS only when g is a formula. In that case, residuals are assumed homoscedastic as well as serially uncorrelated. For type CL, clustered covariance matrix is computed. The options are then included in vcovOptions (see meatCL).

vcovOptions

A list of options for the covariance matrix of the moment conditions. See vcovHAC for the default values.

centeredVcov

Should the moment function be centered when computing its covariance matrix. Doing so may improve inference.

data

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

na.action

Action to take for missing values. If missing values are present and the option is set to "na.pass", the model won't be estimable.

survOptions

If needed, a list with the type of survey weights and the weights as a numeric vector, data.frame or formula. The type is either "sampling" or "fequency".

smooth

If TRUE, the moment function is smoothed using a kernel method.

Value

'momentModel' returns an object of one of the subclasses of "momentModel".

References

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.

Examples

data(simData)
theta <- c(beta0=1,beta1=2)

## A linearModel
model1 <- momentModel(y~x1, ~z1+z2, data=simData)

## A nonlinearModel
g <- y~beta0+x1^beta1
h <- ~z1+z2
model2 <- momentModel(g, h, c(beta0=1, beta1=2), data=simData)

## A functionModel
fct <- 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)
    }
dfct <- 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)
        }
model3 <- momentModel(fct, simData$x3, theta0=c(beta0=1, beta1=2), grad=dfct)

momentfit documentation built on Sept. 20, 2023, 3:01 a.m.