Alternative interface for
This function generates predictions for
merMod models, but
with the ability to get standard errors as well.
predict_merMod( object, newdata = NULL, se.fit = FALSE, use.re.var = FALSE, allow.new.levels = FALSE, type = c("link", "response", "terms"), na.action = na.pass, re.form = NULL, boot = FALSE, sims = 100, prog.arg = "none", ... )
a fitted model object
data frame for which to evaluate predictions.
Include standard errors with the predictions? Note that these standard errors by default include only fixed effects variance. See details for more info. Default is FALSE.
se.fitis TRUE, include random effects variance in standard errors? Default is FALSE.
logical if new levels (or NA values) in
newdataare allowed. If FALSE (default), such new values in
newdatawill trigger an error; if TRUE, then the prediction will use the unconditional (population-level) values for data with previously unobserved levels (or NAs).
character string - either
"link", the default, or
"response"indicating the type of prediction object returned.
NA) specify which random effects to condition on when predicting. If
NULL, include all random effects; if
~0, include no random effects.
Use bootstrapping (via
lme4::bootMer()) to estimate variance for
se.fit? Default is FALSE
bootis TRUE, how many simulations should be run? Default is 100.
se.fitare TRUE, a character string - type of progress bar to display. Default is "none"; the function will look for a relevant *ProgressBar function, so "txt" will work in general; "tk" is available if the tcltk package is loaded; or "win" on Windows systems. Progress bars are disabled (with a message) for parallel operation.
se.fitare TRUE, any additional arguments are passed to
The developers of lme4 omit an
se.fit argument for a
reason, which is that it's not perfectly clear how best to estimate
the variance for these models. This solution is a logical one, but perhaps
not perfect. Bayesian models are one way to do better.
The method used here is based on the one described here: http://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#predictions-andor-confidence-or-prediction-intervals-on-predictions