Learn R Programming

itsadug (version 0.8)

check_resid: Inspect residuals of regression models.

Description

Inspect residuals of regression models.

Usage

check_resid(model, AR_start = NULL, split_by = NULL)

Arguments

model
A regression model, resulting from the functions gam or bam, or lm, glm, lmer, or glmer.
AR_start
Defaults to NULL. Only use this when the model was run in an old versions of package mgcv and the function cannot retrieve the used AR.start values from the model. When an error is shown with newer versions of mgcv,
split_by
A names list indicating time series in the data.

Note

In the ACF plots, black lines indicate ACF of standard residuals, red vertical lines indicate the ACF for the residuals corrected for the AR1 model included.

Examples

Run this code
data(simdat)

# Add start event column:
simdat <- start_event(simdat, event=c("Subject", "Trial"))
head(simdat)
# bam model with AR1 model (toy example, not serious model):
m1 <- bam(Y ~ Group + te(Time, Trial, by=Group),
   data=simdat, rho=.5, AR.start=simdat$start.event)
# No time series specified:
check_resid(m1)
# Time series specified:
check_resid(m1, split_by=list(Subject=simdat$Subject, Trial=simdat$Trial))
# Note: residuals do not look very good.

# This does not work (see acf_resid for similar examples):
check_resid(m1, split_by=c("Subject", "Trial"))
# However, it does work for included predictors:
check_resid(m1, split_by=c("Group"))

Run the code above in your browser using DataLab