Learn R Programming

itsadug (version 2.4.1)

check_resid: Inspect residuals of regression models.

Description

Inspect residuals of regression models.

Usage

check_resid(
  model,
  AR_start = NULL,
  split_pred = NULL,
  ask = TRUE,
  select = 1:4
)

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, please check the column provided as values of AR.start. when using old versions of package mgcv. Function will give error when it cannot find AR.start.

split_pred

A names list indicating time series in the data.

ask

Logical: whether or not to show the plots one by one. Defaults to TRUE. When set to FALSE, make sure to have specified sufficient rows and columns to show the X plots. Alternatively, use select to plot only specific plots.

select

Vector or numeric value indicating which plots to return (see Notes). Defaults to 1:4 (all).

See Also

Other Model evaluation: diagnostics(), plot_modelfit()

Examples

Run this code
# NOT RUN {
data(simdat)

# }
# NOT RUN {
# 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)

# Warning, no time series specified:
check_resid(m1)

# Time series specified, results in a 'standard' ACF plot, 
# treating all residuals as single time seriesand,
# and an ACF plot with the average ACF over time series:
check_resid(m1, split_pred=list(Subject=simdat$Subject, Trial=simdat$Trial))
# Note: residuals do not look very good.
# Alternative (results in the same, see help(acf_resid) ):
check_resid(m1, split_pred='AR.start')

# Define larger plot window (choose which line you need):
dev.new(width=8, height=8) # on windows or mac
quartz(,8,8)               # on mac
x11(width=8, height=8)     # on linux or mac

par(mfrow=c(2,2), cex=1.1)
check_resid(m1, split_pred='AR.start', ask=FALSE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab