get_prediction-method: Compute predicted value of formula for linear (mixed) model

Description Usage Arguments Details Value Examples

Description

Compute predicted value of formula for linear (mixed) model for with lm or lmer

Usage

1
2
3
4
5
6
7
get_prediction(fit, formula)

## S4 method for signature 'lmerMod'
get_prediction(fit, formula)

## S4 method for signature 'lm'
get_prediction(fit, formula)

Arguments

fit

model fit with lm or lmer

formula

formula of fixed and random effects to predict

Details

Similar motivation as lme4:::predict.merMod(), but that function cannot use just a subset of the fixed effects: it either uses none or all. Note that the intercept is included in the formula by default. To exclude it from the prediction use ~ 0 + ... syntax

Value

Predicted values from formula using parameter estimates from fit linear (mixed) model

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(lme4)

# Linear model
fit <- lm(Reaction ~ Days, sleepstudy)

# prediction of intercept
get_prediction( fit, ~ 1)

# prediction of Days without intercept
get_prediction( fit, ~ 0 + Days)

# Linear mixed model

# fit model
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

# predict Days, but exclude intercept
get_prediction( fm1, ~ 0 + Days)

# predict Days and (Days | Subject) random effect, but exclude intercept
get_prediction( fm1, ~ 0 + Days +  (Days | Subject))

variancePartition documentation built on Nov. 8, 2020, 5:18 p.m.