Learn R Programming

gratia (version 0.9.0)

add_partial_residuals: Add partial residuals

Description

Add partial residuals

Usage

add_partial_residuals(data, model, ...)

# S3 method for gam add_partial_residuals(data, model, select = NULL, partial_match = FALSE, ...)

Arguments

data

a data frame containing values for the variables used to fit the model. Passed to stats::residuals() as newdata.

model

a fitted model for which a stats::residuals() method is available. S3 method dispatch is performed on the model argument.

...

arguments passed to other methods.

select

character, logical, or numeric; which smooths to plot. If NULL, the default, then all model smooths are drawn. Numeric select indexes the smooths in the order they are specified in the formula and stored in object. Character select matches the labels for smooths as shown for example in the output from summary(object). Logical select operates as per numeric select in the order that smooths are stored.

partial_match

logical; should smooths be selected by partial matches with select? If TRUE, select can only be a single string to match against.

Examples

Run this code
load_mgcv()
# \dontshow{
op <- options(pillar.sigfig = 3, cli.unicode = FALSE)
# }
df <- data_sim("eg1", seed = 1)
df <- df[, c("y", "x0", "x1", "x2", "x3")]
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = "REML")

## add partial residuals
add_partial_residuals(df, m)

## add partial residuals for selected smooths
add_partial_residuals(df, m, select = "s(x0)")
# \dontshow{
options(op)
# }

Run the code above in your browser using DataLab