The function `tsacf` computes (and by default plots) estimates of the autocorrelation function. Function pacf is the function used for the partial autocorrelations, and function tsacov computes the autocovariance function.
## Autocorrelation Function (ACF)
tsacf(
x, y = NULL, lag.max = 8,
type = c("correlation", "covariance", "partial",
"cross-correlation", "cross-covariance"),
show.plot = TRUE, na.action = na.omit,
demean = TRUE, alpha = 0.05,
x.name = NULL, title = NULL,
prewhiten = list(order = c(0L, 0L, 0L),
seasonal = c(0L, 0L, 0L),
period = NA))## Partial Autocorrelation Function (PACF)
tspacf(...)
## Autocovariance (ACOV)
tsacov(...)
## cross-correlation (CCF)
tsccf(...)
## cross-ovariance (CCOV)
tsccov(...)
# S3 method for tsacf
print(x, digits = max(3L, getOption("digits") - 3L), ...)
# S3 method for tsacf
plot(x, title = NULL, ...)
An object of class "tsacf", which is a list with the following elements:
bar chart of the estimated ACF/PACF/ACOV. Only available if save.plot is TRUE.
An array with the same dimensions as lag containing the estimated ACF/PACF/ACOV/CCF/CCOV.
upper limits of the estimated confidence intervals for each lag. Since confidence intervals are symmetrical around 0, the lower limits are simply the negative values of clim.
type of correlation (same as the type argument).
number of observations in the time series.
lags at which the acf is estimated.
name of the time series for which forecasts was requested.
significance level.
univariate time series object(s) or a numeric vector(s) or matrix/matrices, or a `tsacf` object.
maximum lag at which to calculate the acf. Default is 8. Will be automatically limited to one less than the number of observations in the series. If the series has less than 8 observations.
character string giving the type of acf to be computed. Allowed values are "correlation" (the default), "covariance", "partial", "cross-correlation", or "cross-covariance". Will be partially matched.
logical. If TRUE, the acf/pacf/acov will be plotted. Default is TRUE.
function to be called to handle missing values. Default is na.omit.
logical. If TRUE, the covariances will be about the sample means. Default is TRUE.
significance level. (1 - alpha) indicates is the confidence level of the prediction interval. Default is 0.05.
name of the series. If omitted here, the series name found by tsname() will be taken over here. If tsname() is NULL, the variable name will be used instead. Default is NULL.
character string indicating the plot title.
a list of seasonal ARIMA orders to prewhiten x and y for cross-correlation or cross-covariance. Only applicable if type = "cross-correlation" or type = "cross-covariance".
other printing or plotting parameters.
number of decimal digits displayed in the results.
Ka Yui Karl Wu
For type = "correlation" and "covariance", the estimates are based on the sample covariance of \(x_t\) and \(x_{t-k}\) (lag 0 autocorrelation is fixed at 1 by convention.). For "cross-correlation" and "cross-covariance", the estimates are based on the sample covariance of \(x_t\) and \(y_{t-k}\).
By default, no missing values are allowed. However, by default, na.action = na.omit, the covariances are computed only from complete cases. This means that the estimate computed may well not be a valid autocorrelation sequence, and may contain missing values. Missing values are not allowed when computing the PACF of a multivariate time series.
The partial correlation coefficient is estimated by fitting autoregressive models of successively higher orders up to lag.max.
The lag is returned and plotted in units of time, and not numbers of observations.
Different from acf, the lags here are not converted based on the seasonal cycle length. It simply reflects the time lag \(k\) between \(X_t\) and \(X_{t-k}\). Furthermore, the ACF/PACF/ACOV/CCF/CCOV plots are created using ggplot2.
The generic functions plot and print have both methods for objects of class "tsacf".
For `cross-correlation` and `cross-covariance`, positive lags indicate that y is shifted forward in time relative to x, while negative lags indicate y is shifted backward.
Box, G. E. P., & Jenkins, G. M. (1970). Time series analysis: Forecasting and control. Holden-Day.
Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts.
https://otexts.com/fpp3/
Venables, W. N., & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer-Verlag.
# Autocorrelation (ACF)
airport.acf <- tsacf(airport$Travellers, lag.max = 24, show.plot = FALSE)
print(airport.acf, digits = 4)
plot(airport.acf)
# Partial Autocorrelation (PACF)
tspacf(airport$Travellers, lag.max = 24)
# Autocovariance (ACOV)
tsacov(airport$Travellers, lag.max = 24, show.plot = FALSE)
# Cross-Correlation (CCF)
tsccf(airport$AvgRain, airport$Travellers, lag.max = 24)
# Cross-Covariance (CCOV)
tsccov(airport$AvgRain, airport$Travellers, lag.max = 24)
Run the code above in your browser using DataLab