On Sat, May 7, 2011 at 12:17 AM, Penny Bilton <pennybil...@xnet.co.nz> wrote: > I am trying to find a confidence band for a fitted non-linear curve. I see > that the predict.nls function has an interval argument, but a previous post > indicates that this argument has not been implemented. Is this still true? > I have tried various ways to extract the interval information from the model > object without success. My code is: > > Model.predict <- predict(My.nls.model, se.fit=TRUE, interval = > "confidence", level = 0.95) , > > where My.nls.model is an nls object, I was able to extract the predictions > okay. >
You can get these intervals using nls2. The as.lm function has an nls method which returns the lm model tangent to an nls model and use can use predict.lm on that. > library(nls2) > fm <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD) > predict(as.lm(fm), interval = "confidence") fit lwr upr 1 7.887451 3.701701 12.07320 2 12.524979 8.219483 16.83047 3 15.251674 11.813306 18.69004 4 16.854870 13.668094 20.04164 5 17.797489 14.026668 21.56831 6 18.677578 13.393630 23.96153 > predict(as.lm(fm), interval = "prediction") fit lwr upr 1 7.887451 -0.3349547 16.10986 2 12.524979 4.2409738 20.80898 3 15.251674 7.3833942 23.11995 4 16.854870 9.0932340 24.61651 5 17.797489 9.7783530 25.81663 6 18.677578 9.8453897 27.50977 Warning message: In predict.lm(as.lm(fm), interval = "prediction") : Predictions on current data refer to _future_ responses -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.