ccf_boot  R Documentation 
Account for possible autocorrelation of time series when assessing the statistical significance of their crosscorrelation. A sieve bootstrap approach is used to generate multiple copies of the time series with the same autoregressive dependence, under the null hypothesis of the two time series under investigation being uncorrelated. The significance of crosscorrelation coefficients is assessed based on the distribution of their bootstrapped counterparts. Both Pearson and Spearman types of coefficients are obtained, but a plot is provided for only one type, with significant correlations shown using filled circles (see Examples).
ccf_boot(
x,
y,
lag.max = NULL,
plot = c("Pearson", "Spearman", "none"),
level = 0.95,
B = 1000,
smooth = FALSE,
cl = 1L,
...
)
x, y 
univariate numeric timeseries objects or numeric vectors for which to
compute crosscorrelation. Different time attributes in 
lag.max 
maximum lag at which to calculate the crosscorrelation. Will be
automatically limited as in 
plot 
choose whether to plot results for Pearson correlation (default, or use

level 
confidence level, from 0 to 1. Default is 0.95, that is, 95% confidence. 
B 
number of bootstrap simulations to obtain empirical critical values. Default is 1000. 
smooth 
logical value indicating whether the bootstrap confidence bands
should be smoothed across lags.
Default is 
cl 
parameter to specify computer cluster for bootstrapping passed to
the package

... 
other parameters passed to the function 
Note that the smoothing of confidence bands is implemented purely for the look.
This smoothing is different from the
smoothing methods that can be applied to adjust bootstrap performance
\insertCiteDeAngelis_Young_1992funtimes.
For correlations close to the significance bounds, the setting of smooth
might
affect the decision on the statistical significance.
In this case, it is recommended to keep smooth = FALSE
and set a higher B
.
A data frame with the following columns:
Lag 
lags for which the following values were obtained. 
r_P 
observed Pearson correlations. 
lower_P, upper_P 
lower and upper confidence bounds (for the confidence level set by 
r_S 
observed Spearman correlations. 
lower_S, upper_S 
lower and upper confidence bounds (for the confidence level set by 
Vyacheslav Lyubchich
ARest
, ar
, ccf
,
HVK
## Not run:
# Fix seed for reproducible simulations:
set.seed(1)
# Example 1
# Simulate independent normal time series of same lengths
x < rnorm(100)
y < rnorm(100)
# Default CCF with parametric confidence band
ccf(x, y)
# CCF with bootstrap
tmp < ccf_boot(x, y)
# One can extract results for both Pearson and Spearman correlations
tmp$rP
tmp$rS
# Example 2
# Simulated ts objects of different lengths and starts (incomplete overlap)
x < arima.sim(list(order = c(1, 0, 0), ar = 0.5), n = 30)
x < ts(x, start = 2001)
y < arima.sim(list(order = c(2, 0, 0), ar = c(0.5, 0.2)), n = 40)
y < ts(y, start = 2020)
# Show how x and y are aligned
ts.plot(x, y, col = 1:2, lty = 1:2)
# The usual CCF
ccf(x, y)
# CCF with bootstrap confidence intervals
ccf_boot(x, y, plot = "Spearman")
# Notice that only +7 lags can be calculated in both cases because of the small
# overlap of the time series. If we save these time series as plain vectors, the time
# information would be lost, and the time series will be misaligned.
ccf(as.numeric(x), as.numeric(y))
# Example 3
# Box & Jenkins time series of sales and a leading indicator, see ?BJsales
plot.ts(cbind(BJsales.lead, BJsales))
# Each of the BJ time series looks as having a stochastic linear trend, so apply differences
plot.ts(cbind(diff(BJsales.lead), diff(BJsales)))
# Get crosscorrelation of the differenced series
ccf_boot(diff(BJsales.lead), diff(BJsales), plot = "Spearman")
# The leading indicator "stands out" with significant correlations at negative lags,
# showing it can be used to predict the sales 23 time steps ahead (that is,
# diff(BJsales.lead) at times t2 and t3 is strongly correlated with diff(BJsales) at
# current time t).
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.