Plot Cross Correlation Function (CCF)
CCF.RdCompute and optionally visualize the cross-correlation function between two time series.
Usage
CCF(
ts1,
ts2,
lag.max = length(ts1),
na.action = na.fail,
title = NULL,
plot = TRUE,
save = FALSE,
dir = NULL,
prefix = NULL,
times = NULL
)Arguments
- ts1
First numeric vector or time-series object (Reference).
- ts2
Second numeric vector or time-series object (Shifted).
- lag.max
Maximum lag to compute. Default is length of `ts1`.
- na.action
NA handling function. Default is `na.fail`.
- title
Optional plot title.
- plot
Logical. If TRUE (default), return a ggplot2 object.
- save
Logical. If TRUE, save plot as 'CCF.pdf'. Default is FALSE.
- dir
Optional directory to save plot (currently ignored unless customized in `savefig()`).
- prefix
Optional prefix for filename (currently ignored unless used in `savefig()`).
- times
Optional numeric vector used to convert inputs into ts objects if not already.
Value
A list containing:
- ccf_res
The CCF computation result with added `white95ci`.
- ind_max
Index of lag with highest absolute cross-correlation.
- ccf_max
Value of maximum absolute cross-correlation.
- lag_max
Lag at which maximum absolute cross-correlation occurs.
- plot
ggplot2 object, only if `plot = TRUE`.