# NOT RUN {
data(simdat)
# Separate ACF for each time series:
acf_n_plots(simdat$Y, split_by=list(simdat$Subject, simdat$Trial))
# Average ACF per participant:
acf_n_plots(simdat$Y, split_by=list(simdat$Subject))
# }
# NOT RUN {
# Data treated as single time series. Plot is added to current window.
# Note: 1 time series results in 1 plot.
acf_n_plots(simdat$Y, add=TRUE)
# Plot 4 ACF plots doesn't work without splitting data:
acf_n_plots(simdat$Y, add=TRUE, n=4)
# Plot ACFs of 4 randomly selected time series:
acf_n_plots(simdat$Y, random=TRUE, n=4, add=TRUE,
split_by=list(simdat$Subject, simdat$Trial))
# }
# NOT RUN {
#---------------------------------------------
# When using model residuals
#---------------------------------------------
# }
# NOT RUN {
# add missing values to simdat:
simdat[sample(nrow(simdat), 15),]$Y <- NA
# simple linear model:
m1 <- lm(Y ~ Time, data=simdat)
# This will generate an error:
# acf_n_plots(resid(m1), split_by=list(simdat$Subject, simdat$Trial))
# This should work:
el.na <- missing_est(m1)
acf_n_plots(resid(m1),
split_by=list(simdat[-el.na,]$Subject, simdat[-el.na,]$Trial))
# This should also work:
simdat$res <- NA
simdat[!is.na(simdat$Y),]$res <- resid(m1)
acf_n_plots(simdat$res, split_by=list(simdat$Subject, simdat$Trial))
# }
# NOT RUN {
# see the vignette for examples:
vignette('acf', package='itsadug')
# }
Run the code above in your browser using DataLab