[R] nls confidence intervals

Duncan Murdoch dmurdoch at pair.com
Thu Aug 14 18:43:25 CEST 2003


On Thu, 14 Aug 2003 09:08:26 -0700, Spencer Graves
<spencer.graves at pdf.com> 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
>
>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

I think that's a documented difference, rather than a bug.  The
?predict.nls says near the top that at present, se.fit is ignored.
I can see in the log that this comment was added in 1999; a
contribution of code to actually do this would probably be welcomed!

Perhaps the description below of what se.fit is supposed to do should
be modified. 

>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

This looks like a bug in numericDeriv, which finds a derivative of 0
rather than 1 for da/da.  I've cc'd the author.

Duncan




More information about the R-help mailing list