data(simData)
## Unrestricted model
model1 <- momentModel(y~x1+x2+x3, ~x2+x3+z1+z2+z3, data=simData, vcov="MDS")
res1 <- gmmFit(model1)
## Wald test
R <- c("x1=0.5","x2=x3")
hypothesisTest(object.u=res1, R=R)
## LR tests
rmodel1 <- restModel(model1, R)
res2 <- gmmFit(rmodel1)
hypothesisTest(object.u=res1, object.r=res2, type="LR")
### LR and Wald should be the same as long as the same weighting
### matrix if used for both GMM fits, for the LR and Wald as well
# Unrestricted model and save the weights
res1 <- gmmFit(model1)
w <- res1@wObj
# estimate models with the same weights
res2 <- gmmFit(rmodel1, weights=w)
# LR test with the same weights
hypothesisTest(res1, res2, type="LR", wObj=w)
# Wald test with vcov based on the same weights (or the bread)
hypothesisTest(object.u=res1, R=R, breadOnly=TRUE)
### Another example with real data
data(Mroz)
model <- momentModel(log(wage)~educ+exper+I(exper^2),
~exper+I(exper^2)+fatheduc+motheduc, vcov="MDS",
data=Mroz, centeredVcov=FALSE)
R <- c("educ=0","I(exper^2)=0")
rmodel <- restModel(model, R)
res1 <- gmmFit(model)
res2 <- gmmFit(rmodel, weights=res1@wObj)
hypothesisTest(object.u=res1, object.r=res2, type="LR", wObj=res1@wObj)
hypothesisTest(object.u=res1, object.r=res2, type="Wald",
vcov=vcov(res1, breadOnly=TRUE))
## LM test (identical to the other two tests as well)
hypothesisTest(object.r=res2)
# or
hypothesisTest(object.u=res1, object.r=res2, type="LM")
## Wald with the 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")
rNLmodel <- restModel(NLmodel, R1)
res.u <- gmmFit(NLmodel)
res.r <- gmmFit(rNLmodel)
hypothesisTest(object.u=res.u, R=R1)
## LM
hypothesisTest(object.r=res.r)
## LR
hypothesisTest(object.r=res.r, object.u=res.u, type="LR")
Run the code above in your browser using DataLab