lme4 (version 1.0-5)

predict.merMod: Predictions from a model at new data values

Description

predict method for merMod objects

Usage

## S3 method for class 'merMod':
predict(object, newdata = NULL,
    REform = NULL, terms = NULL,
    type = c("link", "response"), allow.new.levels = FALSE,
    na.action = na.pass, ...)

Arguments

object
a fitted model object
newdata
data frame for which to evaluate predictions
REform
formula for random effects to include. If NULL, include all random effects; if NA, include no random effects
terms
a terms object - not used at present
type
character string - either "link", the default, or "response" indicating the type of prediction object returned
allow.new.levels
(logical) if FALSE (default), then any new levels (or NA values) detected in newdata will trigger an error; if TRUE, then the prediction will use the unconditional (population-level) values for data with previously unobserved levels (
na.action
function determining what should be done with missing values for fixed effects in newdata. The default is to predict NA: see na.pass.
...
optional additional parameters. None are used at present.

Value

  • a numeric vector of predicted values

Examples

Run this code
(gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 |herd), cbpp, binomial))
str(p0 <- predict(gm1))            # fitted values
str(p1 <- predict(gm1,REform=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,REform=NA)) # new data, level-0
str(p4 <- predict(gm1,newdata,REform=~(1|herd))) # explicitly specify RE

Run the code above in your browser using DataCamp Workspace