对于精确识别的时刻,无论初始值如何,GMM 结果都应该相同。然而情况似乎并非如此。
library(gmm)
data(Finance)
x <- data.frame(rm=Finance[1:500,"rm"], rf=Finance[1:500,"rf"])
# want to solve for coefficients theta[1], theta[2] in exactly identified
# system
g <- function(theta, x)
{
m.1 <- x[,"rm"] - theta[1] - theta[2]*x[,"rf"]
m.z <- (x[,"rm"] - theta[1] - theta[2]*x[,"rf"])*x[,"rf"]
f <- cbind(m.1, m.z)
return(f)
}
# gmm coefficient result should be identical to ols regressing rm on rf
# since two moments are E[u]=0 and E[u*rf]=0
model.lm <- lm(rm ~ rf, data=x)
model.lm
# gmm is consistent with lm given correct starting values
summary(gmm(g, x, t0=model.lm$coefficients))
# problem is that using different starting values leads to different
# coefficients
summary(gmm(g, x, t0=rep(0,2)))
我的设置有问题吗?
gmm
软件包作者 Pierre Chausse 很友善地回复了我的询问。
对于线性模型,他建议使用公式方法:
gmm(rm ~ rf, ~rf, data=x)
对于非线性模型,他强调起始值确实很关键。在精确识别模型的情况下,他建议将
fnscale
设置为较小的数字,以迫使 optim
最小化器收敛到更接近 0。此外,他认为 BFGS 算法与 GMM 配合使用效果更好。
summary(gmm(g, x, t0=rep(0,2), method = "BFGS", control=list(fnscale=1e-8)))
两种解决方案都适用于本示例。谢谢皮埃尔!