The function ACF computes an estimate of the autocorrelation function of a (possibly multivariate) tsibble. Function PACF computes an estimate of the partial autocorrelation function of a (possibly multivariate) tsibble. Function CCF computes the cross-correlation or cross-covariance of two columns from a tsibble.

ACF(.data, ..., lag_max = NULL, demean = TRUE,
  type = c("correlation", "covariance", "partial"))

PACF(.data, ..., lag_max = NULL)

CCF(.data, ..., lag_max = NULL, type = c("correlation", "covariance"))

Arguments

.data

A tsibble

...

The column(s) from the tsibble used to compute the ACF, PACF or CCF.

lag_max

maximum lag at which to calculate the acf. Default is 10*log10(N/m) where N is the number of observations and m the number of series. Will be automatically limited to one less than the number of observations in the series.

demean

logical. Should the covariances be about the sample means?

type

character string giving the type of acf to be computed. Allowed values are "correlation" (the default), "covariance" or "partial". Will be partially matched.

Value

The ACF, PACF and CCF functions return objects of class "tbl_cf", which is a tibble containing the correlations computed.

Details

The functions improve the acf, pacf and ccf functions. The main differences are that ACF does not plot a spike at lag 0 when type=="correlation" (which is redundant) and the horizontal axes show lags in time units rather than seasonal units.

The tapered versions implement the ACF and PACF estimates and plots described in Hyndman (2015), based on the banded and tapered estimates of autocovariance proposed by McMurry and Politis (2010).

References

Hyndman, R.J. (2015). Discussion of ``High-dimensional autocovariance matrices and optimal linear prediction''. Electronic Journal of Statistics, 9, 792-796.

McMurry, T. L., & Politis, D. N. (2010). Banded and tapered estimates for autocovariance matrices and the linear process bootstrap. Journal of Time Series Analysis, 31(6), 471-482.

See also

Examples

library(tsibble) library(tsibbledata) library(dplyr)
#> #> Attaching package: ‘dplyr’
#> The following object is masked from ‘package:tsibble’: #> #> id
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
aus_elec %>% ACF(Temperature)
#> # A tsibble: 235 x 3 [30m] #> # Key: State [5] #> State lag acf #> <chr> <lag> <dbl> #> 1 New South Wales 30m 0.992 #> 2 New South Wales 60m 0.978 #> 3 New South Wales 90m 0.959 #> 4 New South Wales 120m 0.935 #> 5 New South Wales 150m 0.908 #> 6 New South Wales 180m 0.878 #> 7 New South Wales 210m 0.847 #> 8 New South Wales 240m 0.814 #> 9 New South Wales 270m 0.781 #> 10 New South Wales 300m 0.748 #> # … with 225 more rows
aus_elec %>% PACF(Temperature)
#> # A tsibble: 235 x 3 [30m] #> # Key: State [5] #> State lag pacf #> <chr> <lag> <dbl> #> 1 New South Wales 30m 0.992 #> 2 New South Wales 60m -0.444 #> 3 New South Wales 90m -0.202 #> 4 New South Wales 120m -0.116 #> 5 New South Wales 150m -0.0657 #> 6 New South Wales 180m -0.0309 #> 7 New South Wales 210m 0.000787 #> 8 New South Wales 240m 0.0180 #> 9 New South Wales 270m 0.0102 #> 10 New South Wales 300m 0.0179 #> # … with 225 more rows
global_economy %>% filter(Country == "Australia") %>% CCF(GDP, Population)
#> # A tsibble: 29 x 3 [1Y] #> # Key: Country [1] #> Country lag ccf #> <fct> <lag> <dbl> #> 1 Australia -14Y 0.0315 #> 2 Australia -13Y 0.0673 #> 3 Australia -12Y 0.108 #> 4 Australia -11Y 0.152 #> 5 Australia -10Y 0.203 #> 6 Australia -9Y 0.268 #> 7 Australia -8Y 0.321 #> 8 Australia -7Y 0.389 #> 9 Australia -6Y 0.472 #> 10 Australia -5Y 0.563 #> # … with 19 more rows