[R] nls confidence intervals

Torsten Hothorn hothorn at ci.tuwien.ac.at
Thu Aug 14 18:15:51 CEST 2003


On Thu, 14 Aug 2003, Spencer Graves wrote:

> This seems to identify a possible bug in R 1.7.1 under Windows 2000:
> 
>  > tstDf <- data.frame(y = 1:11, x=1:11)
>  > fit <- nls(y~a/x, data=tstDf, start=list(a=1))
>  > predict(fit, se.fit=TRUE)
>   [1] 7.0601879 3.5300939 2.3533960 1.7650470 1.4120376 1.1766980 1.0085983
>   [8] 0.8825235 0.7844653 0.7060188 0.6418353
> 

?predict.nls states:

	At present `se.fit' and `interval' are ignored.

and therefore works as advertised.

Torsten

> The same code in S-Plus 6.1 produces the following:
> 
>  > predict(fit, se.fit = TRUE)
> $fit:
>   [1] 7.0601876 3.5300938 2.3533959 1.7650469 1.4120375 1.1766979 
> 1.0085982 0.8825234
>   [9] 0.7844653 0.7060188 0.6418352
> 
> $se.fit:
>   [1] 5.2433042 2.6216521 1.7477681 1.3108261 1.0486608 0.8738840 
> 0.7490435 0.6554130
>   [9] 0.5825894 0.5243304 0.4766640
> 
> $residual.scale:
> [1] 6.544753
> 
> $df:
> [1] 10
> 
> Unfortunately, I'm not in a position to fix the problem, but this toy 
> example might make it easier for someone else to fix it.
> 
> spencer graves
> p.s.  The following command in S-Plus 6.1 seems to work fine but 
> produces an error in R 1.7.1:
> 
> nls(y~a, data=tstDf, start=list(a=1))
> Error in nlsModel(formula, mf, start) : singular gradient matrix at 
> initial parameter estimates
> #############################################################
> Enrique Portilla wrote:
> > Hi, 
> > Does anyone know how to compute the confidence prediction intervals for
> > a nonlinear least squares models (nls)?
> > 
> > I was trying to use the function 'predict' as I usually do for other
> > models fitting (glm, lm, gams...), but it seems that se.fit, and
> > interval computation is not implemented for the nls...
> > 
> > Cheers
> > 
> > Enrique
> > 
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Fisheries Research Services,
> > Marine Laboratory,
> > Victoria Road,
> > Torry,
> > Aberdeen, UK.
> > Tel. 44 (0) 1224 295314
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>




More information about the R-help mailing list