glmmTMB (version 0.2.3)

predict.glmmTMB: prediction

Description

prediction

Usage

# S3 method for glmmTMB
predict(object, newdata = NULL, se.fit = FALSE,
  re.form, allow.new.levels = FALSE, type = c("link", "response",
  "conditional", "zprob", "zlink"), zitype = NULL, na.action = na.pass,
  debug = FALSE, ...)

Arguments

object

a glmmTMB object

newdata

new data for prediction

se.fit

return the standard errors of the predicted values?

re.form

(not yet implemented) specify which random effects to condition on when predicting. To compute population-level predictions for a given grouping variable (i.e., setting all random effects for that grouping variable to zero), set the group value to NA.

allow.new.levels

allow previously unobserved levels in random-effects variables? see details.

type

Denoting \(mu\) as the mean of the conditional distribution and p as the zero-inflation probability, the possible choices are:

"link"

conditional mean on the scale of the link function, or equivalently the linear predictor of the conditional model

"response"

expected value; this is \(mu*(1-p)\) for zero-inflated models and mu otherwise

"conditional"

mean of the conditional response; mu for all models (i.e., synonymous with "response" in the absence of zero-inflation

"zprob"

the probability of a structural zero (gives an error for non-zero-inflated models)

"zlink"

predicted zero-inflation probability on the scale of the logit link function

zitype

deprecated: formerly used to specify type of zero-inflation probability. Now synonymous with type

na.action

how to handle missing values in newdata (see na.action); the default (na.pass) is to predict NA

debug

(logical) return the TMBStruc object that will be used internally for debugging?

unused - for method compatibility

Details

  • Prediction of new random effect levels is possible as long as the model specification (fixed effects and parameters) is kept constant. However, to ensure intentional usage, a warning is triggered if allow.new.levels=FALSE (the default).

  • Prediction using "data-dependent bases" (variables whose scaling or transformation depends on the original data, e.g. poly, ns, or poly) should work properly; however, users are advised to check results extra-carefully when using such variables. Models with different versions of the same data-dependent basis type in different components (e.g. formula= y ~ poly(x,3), dispformula= ~poly(x,2)) will probably not produce correct predictions.

Examples

Run this code
# NOT RUN {
data(sleepstudy,package="lme4")
g0 <- glmmTMB(Reaction~Days+(Days|Subject),sleepstudy)
predict(g0, sleepstudy)
## Predict new Subject
nd <- sleepstudy[1,]
nd$Subject <- "new"
predict(g0, newdata=nd, allow.new.levels=TRUE)
## population-level prediction
nd_pop <- data.frame(Days=unique(sleepstudy$Days),
                     Subject=NA)
predict(g0, newdata=nd_pop)
# }

Run the code above in your browser using DataLab