predict.nlme.Rd
The predictions at level \(i\) are obtained by adding together the
contributions from the estimated fixed effects and the estimated
random effects at levels less or equal to \(i\) and evaluating the
model function at the resulting estimated parameters. If group values
not included in the original grouping factors are present in
newdata
, the corresponding predictions will be set to
NA
for levels greater or equal to the level at which the
unknown groups occur.
# S3 method for class 'nlme'
predict(object, newdata, level = Q, asList = FALSE,
na.action = na.fail, naPattern = NULL, ...)
an object inheriting from class "nlme"
,
representing a fitted nonlinear mixed-effects model.
an optional data frame to be used for obtaining the predictions. All variables used in the nonlinear model, the fixed and the random effects models, as well as the grouping factors, must be present in the data frame. If missing, the fitted values are returned.
an optional integer vector giving the level(s) of grouping
to be used in obtaining the predictions. Level values increase from
outermost to innermost grouping, with level zero corresponding to the
population predictions. Defaults to the highest or innermost level of
grouping (and is object$dims$Q
).
an optional logical value. If TRUE
and a single
value is given in level
, the returned object is a list with
the predictions split by groups; else the returned value is
either a vector or a data frame, according to the length of
level
.
a function that indicates what should happen when
newdata
contains NA
s. The default action
(na.fail
) causes the function to print an error message and
terminate if there are any incomplete observations.
an expression or formula object, specifying which returned values are to be regarded as missing.
some methods for this generic require additional arguments. None are used in this method.
if a single level of grouping is specified in level
, the
returned value is either a list with the predictions split by groups
(asList = TRUE
) or a vector with the predictions
(asList = FALSE
); else, when multiple grouping levels are
specified in level
, the returned object is a data frame with
columns given by the predictions at different levels and the grouping
factors.
head(Loblolly) # groupedData w/ 'Seed' is grouping variable :
#> Grouped Data: height ~ age | Seed
#> height age Seed
#> 1 4.51 3 301
#> 15 10.89 5 301
#> 29 28.72 10 301
#> 43 41.74 15 301
#> 57 52.70 20 301
#> 71 60.92 25 301
## Grouped Data: height ~ age | Seed
## height age Seed
## 1 4.51 3 301
## 15 10.89 5 301
## .. ..... . ...
fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly,
fixed = Asym + R0 + lrc ~ 1,
random = Asym ~ 1, ## <---grouping---> Asym ~ 1 | Seed
start = c(Asym = 103, R0 = -8.5, lrc = -3.3))
fm1
#> Nonlinear mixed-effects model fit by maximum likelihood
#> Model: height ~ SSasymp(age, Asym, R0, lrc)
#> Data: Loblolly
#> Log-likelihood: -114.7428
#> Fixed: Asym + R0 + lrc ~ 1
#> Asym R0 lrc
#> 101.449600 -8.627331 -3.233751
#>
#> Random effects:
#> Formula: Asym ~ 1 | Seed
#> Asym Residual
#> StdDev: 3.650642 0.7188625
#>
#> Number of Observations: 84
#> Number of Groups: 14
age. <- seq(from = 2, to = 30, by = 2)
newLL.301 <- data.frame(age = age., Seed = 301)
newLL.329 <- data.frame(age = age., Seed = 329)
(p301 <- predict(fm1, newLL.301, level = 0:1))
#> Seed predict.fixed predict.Seed
#> 1 301 -0.2843099 -0.1318218
#> 2 301 7.4263714 7.7197901
#> 3 301 14.5526398 14.9763077
#> 4 301 21.1387895 21.6828346
#> 5 301 27.2257576 27.8810562
#> 6 301 32.8513783 33.6094982
#> 7 301 38.0506184 38.9037665
#> 8 301 42.8557944 43.7967683
#> 9 301 47.2967734 48.3189165
#> 10 301 51.4011589 52.4983192
#> 11 301 55.1944622 56.3609540
#> 12 301 58.7002611 59.9308295
#> 13 301 61.9403462 63.2301347
#> 14 301 64.9348567 66.2793769
#> 15 301 67.7024054 69.0975089
(p329 <- predict(fm1, newLL.329, level = 0:1))
#> Seed predict.fixed predict.Seed
#> 1 329 -0.2843099 -0.7061314
#> 2 329 7.4263714 6.6146994
#> 3 329 14.5526398 13.3806651
#> 4 329 21.1387895 19.6338204
#> 5 329 27.2257576 25.4130326
#> 6 329 32.8513783 30.7542231
#> 7 329 38.0506184 35.6905906
#> 8 329 42.8557944 40.2528179
#> 9 329 47.2967734 44.4692619
#> 10 329 51.4011589 48.3661305
#> 11 329 55.1944622 51.9676451
#> 12 329 58.7002611 55.2961915
#> 13 329 61.9403462 58.3724586
#> 14 329 64.9348567 61.2155672
#> 15 329 67.7024054 63.8431892
## Prediction are the same at level 0 :
all.equal(p301[,"predict.fixed"],
p329[,"predict.fixed"])
#> [1] TRUE
## and differ by the 'Seed' effect at level 1 :
p301[,"predict.Seed"] -
p329[,"predict.Seed"]
#> [1] 0.5743096 1.1050907 1.5956426 2.0490142 2.4680236 2.8552752 3.2131759
#> [8] 3.5439504 3.8496546 4.1321888 4.3933089 4.6346380 4.8576761 5.0638096
#> [15] 5.2543197