Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

add_residuals.gam

Add residuals from a GAM to a data frame


Description

Add residuals from a GAM to a data frame

Usage

## S3 method for class 'gam'
add_residuals(data, model, value = ".residual", type = "deviance", ...)

Arguments

data

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

model

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

value

character; the name of the variable in which model predictions will be stored.

type

character; the type of residuals to return. See mgcv::residuals.gam() for options.

...

additional arguments passed to mgcv::residuals.gam().

Value

A data frame (tibble) formed from data and residuals from model.

Examples

load_mgcv()

df <- gamSim(eg = 1, verbose = FALSE)
df <- df[, c("y","x0","x1","x2","x3")]
m <-  gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = 'REML')

##
add_residuals(df, m)

gratia

Graceful 'ggplot'-Based Graphics and Other Functions for GAMs Fitted Using 'mgcv'

v0.6.0
MIT + file LICENSE
Authors
Gavin L. Simpson [aut, cre] (<https://orcid.org/0000-0002-9084-8413>), Henrik Singmann [ctb] (<https://orcid.org/0000-0002-4842-3657>)
Initial release
2021-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.