# [R] gnls or nlme : how to obtain confidence intervals of fitted values

Spencer Graves spencer.graves at pdf.com
Sat Oct 2 17:19:02 CEST 2004

```      Pinhiero and Bates (2000) Mixed-Effects Models in S and S-Plus
(Springer) describe the use of "intervals" for that.  In library(nlme),
R 1.9.1 for Windows, I found documentation for intervals, intervals.gls,
intervals.lme, intervals.lmList, and gnls.  To an example in the
documentation for gnls, I added intervals:

>      data(Soybean)
>      # variance increases with a power of the absolute fitted values
>      fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean,
+                  weights = varPower())
>      summary(fm1)
Generalized nonlinear least squares fit
Model: weight ~ SSlogis(Time, Asym, xmid, scal)
Data: Soybean
AIC      BIC    logLik
983.7947 1003.900 -486.8974

Variance function:
Structure: Power of variance covariate
Formula: ~fitted(.)
Parameter estimates:
power
0.8815437

Coefficients:
Value Std.Error  t-value p-value
Asym 17.35682 0.5226885 33.20682       0
xmid 51.87232 0.5916820 87.66925       0
scal  7.62053 0.1390958 54.78617       0

Correlation:
Asym  xmid
xmid 0.787
scal 0.485 0.842

Standardized residuals:
Min           Q1          Med           Q3          Max
-2.309670367 -0.646844555 -0.004897024  0.498606088  4.986727281

Residual standard error: 0.3662752
Degrees of freedom: 412 total; 409 residual
> intervals(fm1)
Approximate 95% confidence intervals

Coefficients:
lower      est.     upper
Asym 16.329331 17.356822 18.384313
xmid 50.709200 51.872317 53.035434
scal  7.347094  7.620525  7.893957
attr(,"label")
[1] "Coefficients:"

Variance function:
lower      est.    upper
power 0.8369085 0.8815437 0.926179
attr(,"label")
[1] "Variance function:"

Residual standard error:
lower      est.     upper
0.3373374 0.3649392 0.3947995

Is this what you want?
hope this helps.
spencer graves

Pierre MONTPIED wrote:

> Hi
>
> I use gnls to fit non linear models of the form y = alpha * x**beta
> (alpha and beta being linear functions of a 2nd regressor z i.e.
> alpha=a1+a2*z and beta=b1+b2*z) with variance function
> varPower(fitted(.)) which sounds correct for the data set I use.
>
> My purpose is to use the fitted models for predictions with other sets
> of regressors x, z than those used in fitting. I therefore need to
> estimate y with (95%) confidence intervals.
>
> Does any body knows how to do this with R ?
>
> Thanks
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

--
Spencer Graves, PhD, Senior Development Engineer
O:  (408)938-4420;  mobile:  (408)655-4567

```

More information about the R-help mailing list