R:标准错误

use*_*382 2 r

在NLS回归中是否有任何函数来计算Newey-West估计和R中的White的标准误差.三明治和汽车包装都可以,但他们需要一个lm物体来计算误差.

Ben*_*ker 5

例子来自Achim Zeleis 2013年4月的r-help帖子(顺便说一下,谷歌搜索"nls sandwich" 的第一个帖子):

 ## 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)))
Run Code Online (Sandbox Code Playgroud)

从Achim的回答:

 ## 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)
Run Code Online (Sandbox Code Playgroud)