As said in the help(predict.nls), when se.fit=TRUE,the standard errors of the predictions should be calculated. However, my codes in the following do not display that, but only the predictions.
alloy <- data.frame(x=c(10,30,51,101,203,405,608,810,1013,2026,4052,6078,
8104,10130),
y=c(0.3561333,0.3453,0.3355,0.327453,0.3065299,0.2839316,
0.2675214,0.2552821,0.2455726,0.2264957,0.2049573,
0.1886496,0.1755897,0.1651624))
model <- nls(y ~ a * x^(-b), data=alloy, start=list(a=.5, b=.1))
predict(model, se=TRUE)
What's wrong with my codes? Thank you!
Nothing. The last line of the
Description
section of?predict.nls
says:Perhaps the
deltaMethod
function in thecar
package would help. (Results oflibrary("sos"); findFn("{delta method} nls")
...)update: I didn't get it work with
car::deltaMethod
on my first try. Here's an attempt to use thedeltavar
function from theemdbook
package. Theattach()/detach()
stuff is a horrible hack, but it's what I could get to work quickly (awith
-based solution didn't work because of non-standard evaluation). Improvements welcome.)Caveats: