R gmm包使用精确识别的瞬间条件

时间:2015-06-17 04:31:42

标签: r

对于精确识别的时刻,无论初始起始值如何,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))) 

我的设置有问题吗?

1 个答案:

答案 0 :(得分:1)

gmm包裹作者Pierre Chausse非常友好地回应了我的询问。

对于线性模型,他建议使用公式方法:

gmm(rm ~ rf, ~rf, data=x)

对于非线性模型,他强调起始值确实很关键。在精确识别模型的情况下,他建议将fnscale设置为一个较小的数字,以迫使优化最小化器收敛到接近0.此外,他认为BFGS算法在GMM中效果更好。

summary(gmm(g, x, t0=rep(0,2), method = "BFGS", control=list(fnscale=1e-8)))

这两个解决方案都适用于此示例。谢谢皮埃尔!