predict_gamm: Make predictions with or without random effects

Description Usage Arguments Details Value See Also Examples

View source: R/predict_gamm.R

Description

Use predict in an lme4 style on gam/bam objects from mgcv.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
predict_gamm(
  model,
  newdata,
  re_form = NULL,
  se = FALSE,
  include = NULL,
  exclude = NULL,
  keep_prediction_data = FALSE,
  ...
)

Arguments

model

A gam class model from the mgcv package.

newdata

Data on which to predict on. Empty by default.

re_form

NULL, NA, or character string. If NULL (default), all random effects will be used. If NA, no random effects will be used. If character, must be of the form "s(varname)", where varname would be the name of the grouping variable pertaining to the random effect. Appended to include.

se

Logical. Include standard errors or not. Default is FALSE.

include

Which random effects to include in prediction. See predict.gam for details.

exclude

Which random effects to exclude in prediction. See predict.gam for details.

keep_prediction_data

Keep the model frame or newdata that was used in the prediction in final output? Default is FALSE.

...

Other arguments for predict.gam.

Details

This is a wrapper for predict.gam. The goal is to have similar functionality with predict function in lme4, which makes it easy to drop all random effects or include specific ones. Some of this functionality is not yet available for class bam.

Value

A data frame of predictions and possibly standard errors.

See Also

predict.gam

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(lme4)
library(mgcv)
lmer_model <- lmer(Reaction ~ Days + (Days || Subject), data = sleepstudy)
ga_model <- gam(Reaction ~ Days + s(Subject, bs = "re") + s(Days, Subject, bs = "re"),
  data = sleepstudy,
  method = "REML"
)

head(
  data.frame(
    lmer = predict(lmer_model),
    gam = predict_gamm(ga_model)
  )
)

head(
  cbind(
    lmer = predict(lmer_model, re.form = NA),
    gam1 = predict_gamm(ga_model, re_form = NA),
    gam2 = predict_gamm(ga_model,
      exclude = c("s(Subject)", "s(Days,Subject)")
    )
  )
)

head(predict_gamm(ga_model, se = TRUE))

m-clark/gammit documentation built on Oct. 22, 2020, 6:53 p.m.