predict.merMod {lme4} | R Documentation |
Predictions from a model at new data values
Description
The predict
method for merMod
objects, i.e. results of lmer()
, glmer()
, etc.
Usage
## S3 method for class 'merMod'
predict(object, newdata = NULL, newparams = NULL,
re.form = NULL,
random.only=FALSE, terms = NULL,
type = c("link", "response"), allow.new.levels = FALSE,
na.action = na.pass,
se.fit = FALSE,
...)
Arguments
object |
a fitted model object |
newdata |
data frame for which to evaluate predictions. |
newparams |
new parameters to use in evaluating predictions,
specified as in the |
re.form |
(formula, |
random.only |
(logical) ignore fixed effects, making predictions only using random effects? |
terms |
a |
type |
character string - either |
allow.new.levels |
logical if new levels (or NA values) in
|
na.action |
|
se.fit |
(Experimental) A logical value indicating whether the standard errors should be included or not. Default is FALSE. |
... |
optional additional parameters. None are used at present. |
Details
If any random effects are included in
re.form
(i.e. it is not~0
orNA
),newdata
must contain columns corresponding to all of the grouping variables and random effects used in the original model, even if not all are used in prediction; however, they can be safely set toNA
in this case.There is no option for computing standard errors of predictions because it is difficult to define an efficient method that incorporates uncertainty in the variance parameters; we recommend
bootMer
for this task.
Value
a numeric vector of predicted values
Examples
(gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 |herd), cbpp, binomial))
str(p0 <- predict(gm1)) # fitted values
str(p1 <- predict(gm1,re.form=NA)) # fitted values, unconditional (level-0)
newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd)))
str(p2 <- predict(gm1,newdata)) # new data, all RE
str(p3 <- predict(gm1,newdata,re.form=NA)) # new data, level-0
str(p4 <- predict(gm1,newdata,re.form= ~(1|herd))) # explicitly specify RE
stopifnot(identical(p2, p4))