【发布时间】:2013-06-12 18:40:45
【问题描述】:
在 NLS 回归中是否有任何函数可以计算 Newey-West 估计量和 R 中的 White 标准误差。三明治和汽车套餐可以,但他们需要 lm 对象来计算误差。
【问题讨论】:
标签: r
在 NLS 回归中是否有任何函数可以计算 Newey-West 估计量和 R 中的 White 标准误差。三明治和汽车套餐可以,但他们需要 lm 对象来计算误差。
【问题讨论】:
标签: r
来自Achim Zeleis's April 2013 r-help posting 的示例(顺便说一下,这是第一次在谷歌上搜索“nls 三明治”):
## from ?nls:
x <- -(1:100)/10
y <- 100 + 10 * exp(x / 2) + rnorm(x)/10
suppressWarnings(nlmod <- nls(y ~ Const + A * exp(B * x)))
vcov(nlmod)
sqrt(diag(vcov(nlmod)))
来自阿奇姆的回答:
## the sandwich (aka HC0) covariance matrix and standard errors
library("sandwich")
sandwich(nlmod)
sqrt(diag(sandwich(nlmod)))
## associated coefficient tests
library("lmtest")
coeftest(nlmod)
coeftest(nlmod, vcov = sandwich)
【讨论】: