Learn R Programming

momentfit (version 0.5)

getRestrict-methods: ~~ Methods for Function getRestrict in Package momentfit ~~

Description

It computes the matrices related to linear and nonlinear contraints. Those matrices are used to perform hypothesis tests.

Usage

# S4 method for rlinearModel
getRestrict(object, theta)

# S4 method for rslinearModel getRestrict(object, theta)

# S4 method for rsnonlinearModel getRestrict(object, theta)

# S4 method for rnonlinearModel getRestrict(object, theta)

# S4 method for rformulaModel getRestrict(object, theta)

# S4 method for momentModel getRestrict(object, theta, R, rhs=NULL)

# S4 method for sysModel getRestrict(object, theta, R, rhs=NULL)

# S4 method for rfunctionModel getRestrict(object, theta)

Arguments

object

Object of class included in momentModel, rmomentModel, and rsysModel.

theta

A vector of coefficients for the unrestricted model (see examples).

R

A matrix, character or list of formulas that specifies the contraints to impose on the coefficients. See restModel for more details.

rhs

The right hand side for the restriction on the coefficients. See restModel for more details. It is ignored for objects of class "nonlinearModel".

Methods

signature(object = "momentModel")

A restricted model is created from the constraints, and the restriction matrices are returned. The methods is applied to linear and nonlinear models in a regression form.

signature(object = "sysModel")

A restricted model is created from the constraints, and the restriction matrices are returned. The methods is applied to systems of linear and nonlinear models.

signature(object = "rlinearModel")

The restriction matrices are evaluated at the coefficient vector theta of the unrestricted representation.

signature(object = "rslinearModel")

The restriction matrices are evaluated at the coefficient vector theta of the unrestricted representation.

signature(object = "rsnonlinearModel")

The restriction matrices are evaluated at the coefficient vector theta of the unrestricted representation.

signature(object = "rnonlinearModel")

The restriction matrices are evaluated at the coefficient vector theta of the unrestricted representation.

signature(object = "rfunctionModel")

The restriction matrices are evaluated at the coefficient vector theta of the unrestricted representation.

Examples

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

## Unrestricted model
model1 <- momentModel(y~x1+x2+x3+z1, ~x1+x2+z1+z2+z3+z4, data=simData)

## The restricted model
R1 <- c("x1","2*x2+z1=2", "4+x3*5=3")
res <- gmmFit(model1)
rest <- getRestrict(model1, coef(res), R1)

## it allows to test the restriction
g <- rest$R-rest$q
v <- rest$dR%*%vcov(res)%*%t(rest$dR)
(test <- crossprod(g, solve(v, g)))
(pv <- 1-pchisq(test, length(rest$R)))


## Delta Method:
## To impose nonlinear restrictions, we need to convert
## the linear model into a nonlinear one
NLmodel <- as(model1, "nonlinearModel")
R1 <- c("theta2=2", "theta3=theta4^2")
res <- gmmFit(NLmodel)
rest <- getRestrict(NLmodel, coef(res), R1)

g <- rest$R-rest$q
v <- rest$dR%*%vcov(res)%*%t(rest$dR)
(test <- crossprod(g, solve(v, g)))
(pv <- 1-pchisq(test, length(rest$R)))

## See hypothesisTest method for an easier approach.

Run the code above in your browser using DataLab