predict_gam: Get predictions from a GAM model.

View source: R/utils.R

predict_gamR Documentation

Get predictions from a GAM model.

Description

[Superseded]

This function is from the superseded package tidymv. Please, use the tidygam package instead.

It returns a tibble with the predictions from all the terms in a gam or bam model.

If you simply want to return a tibble with the predicted values of the response/outcome variable based on all terms (minus excluded smooth terms), set type = "link" (the default). Note that if type = "link", parametric terms cannot be excluded from the prediction, due to limitations of mgcv. If you want to return a tibble with the predicted values of the response/outcome variable for each term in the model separately, set type = "terms". This type can be helpful if you want more flexibility in plotting.

Usage

predict_gam(
  model,
  exclude_terms = NULL,
  length_out = 50,
  values = NULL,
  type = "link"
)

Arguments

model

A gam or bam model object.

exclude_terms

Terms to be excluded from the prediction. Term names should be given as they appear in the model summary (for example, "s(x0,x1)").

length_out

An integer indicating how many values along the numeric predictors to use for predicting the outcome term (the default is 50).

values

User supplied values for specific terms as a named list. If the value is NULL, the first value of the term is selected (useful when excluding terms).

type

Either "link" or "terms". See Details below.

Value

A tibble with predictions from a gam or bam model.

Examples

## Not run: 
library(mgcv)
set.seed(10)
data <- gamSim(4)
model <- gam(y ~ fac + s(x2) + s(x2, by = fac) + s(x0), data = data)

# get predictions
p <- predict_gam(model)

# get predictions excluding x0 (the coefficient of x0 is set to 0);
# setting the value for the excluded term to NULL with the argument 'values'
# reduces computation time
p_2 <- predict_gam(model, exclude_terms = "s(x0)", values = list(x0 = NULL))

# get predictions with chosen values of x0

p_3 <- predict_gam(model, values = list(x0 = c(0.250599, 0.503313, 0.756028)))

## End(Not run)

stefanocoretta/tidymv documentation built on May 12, 2023, 1:57 p.m.