Last chance! 50% off unlimited learning
Sale ends in
Generate N ACF plots of individual or aggregated time series.
acf_n_plots(x, n = 5, split_by = NULL, cond = NULL, max_lag = NULL,
fun = mean, plot = TRUE, random = F, mfrow = NULL, add = FALSE,
print.summary = getOption("itsadug_print"), ...)
A vector with time series data, typically residuals of a regression model.
The number of plots to generate.
List of vectors (each with equal length as x
) that
group the values of x
into trials or timeseries events.
Generally other columns from the same data frame.
Named list with a selection of the time series events
specified in split_by
. Default is NULL, indicating that
all time series are being processed, rather than a selection.
Maximum lag at which to calculate the acf. Default is the maximum for the longest time series.
The function used when aggregating over time series
(depending on the value of split_by
).
Logical: whether or not to produce plot. Default is TRUE.
Logical: determine randomly which n
(aggregated) time
series are plotted, or use the quantile
function to find a
range of different time series to plot. Default is FALSE (not random).
A vector of the form c(nr, nc). The figures will be drawn in an nr-by-nc array on the device by rows.
Logical: whether to add the plots to an exiting plot window or not. Default is FALSE.
Logical: whether or not to print summary.
Default set to the print info messages option
(see infoMessages
).
Other arguments for plotting, see par
.
n
ACF plots providing information about the autocorrelation
in x
.
Use acf
for the original ACF function,
and acf_plot
for an ACF that takes into account time series
in the data.
Other functions for model criticism: acf_plot
,
acf_resid
, derive_timeseries
,
resid_gam
, start_event
,
start_value_rho
# 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