On Fri, 5 Apr 2013, Nilesh Gupta wrote:
> Hello
>
> Is there any function to calculate White's standard errors in R in an
> NLS regression. The sandwich and car package do it but they need an lm
> object to calculate the error's.
The infrastructure in "sandwich" is object-oriented and _not_ limited
to
"lm" objects, see: vignette("sandwich-OOP", package =
"sandwich")
The vcovHC() function is limited to models with a certain structure (in
particular with a model matrix) and hence cannot be applied to "nls"
models. However, the sandwich() function can be easily applied. In linear
models the sandwich() estimator corresponds to vcovHC(..., type =
"HC0").
> Does anyone have idea how to do it for an NLS object ?
## Run examples from manual page
example("nls")
## the usual covariance matrix and associated standard errors
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)
> Regards
> The woods are lovely, dark and deep
> But I have promises to keep
> And miles before I go to sleep
> And miles before I go to sleep
> -----
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>