例子来自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)