add_partial_residuals: Add partial residuals

add_partial_residualsR Documentation

Add partial residuals

Description

Add partial residuals

Usage

add_partial_residuals(data, model, ...)

## S3 method for class '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

load_mgcv()

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)")


gavinsimpson/gratia documentation built on April 13, 2024, 10:56 p.m.