data(simData)
theta <- c(beta0=1,beta1=2)
model1 <- momentModel(y~x1, ~z1+z2, data=simData)
gbar <- evalMoment(model1, theta)
gbar <- colMeans(gbar)
### Objective function of GMM with identity matrix
wObj <- evalWeights(model1, w="ident")
quadra(wObj, gbar)
### Objective function of GMM with efficient weights
wObj <- evalWeights(model1, theta)
quadra(wObj, gbar)
### Linearly dependent instruments
simData$z3 <- simData$z1+simData$z2
model2 <- momentModel(y~x1, ~z1+z2+z3, data=simData)
gbar2 <- evalMoment(model2, theta)
gbar2 <- colMeans(gbar2)
## A warning is printed about the singularity of the weighting matrix
wObj <- evalWeights(model2, theta)
## The regular inverse using the QR decomposition:
quadra(wObj)
## The regular inverse using the generalized inverse:
quadra(wObj, genInv=TRUE)
Run the code above in your browser using DataLab