# NOT RUN {
data(simdat)
# add missing values to simdat:
simdat[sample(nrow(simdat), 15),]$Y <- NA
# }
# NOT RUN {
# Run GAMM model:
m1 <- bam(Y ~ te(Time, Trial)+s(Subject, bs='re'), data=simdat)
# Using a list to split the data:
acf_resid(m1, split_pred=list(simdat$Subject, simdat$Trial))
# ...or using model predictors:
acf_resid(m1, split_pred=c('Subject', 'Trial'))
# Calling acf_n_plots:
acf_resid(m1, split_pred=c('Subject', 'Trial'), n=4)
# add some arguments:
acf_resid(m1, split_pred=c('Subject', 'Trial'), n=4, max_lag=10)
# This does not work...
m2 <- lm(Y ~ Time, data=simdat)
acf_resid(m2, split_pred=c('Subject', 'Trial'))
# ... but this is ok:
acf_resid(m2, split_pred=list(simdat$Subject, simdat$Trial))
# Using AR.start column:
simdat <- start_event(simdat, event=c('Subject', 'Trial'))
r1 <- start_value_rho(m1)
m3 <- bam(Y ~ te(Time, Trial)+s(Subject, bs='re'), data=simdat,
rho=r1, AR.start=simdat$start.event)
acf_resid(m3, split_pred='AR.start')
# this is the same:
acf_resid(m3, split_pred=c('Subject', 'Trial'))
# Note: use model comparison to find better value for rho
# }
# NOT RUN {
# see the vignette for examples:
vignette('acf', package='itsadug')
# }
Run the code above in your browser using DataLab