Skip to contents

Estimate the sample autocorrelation function of a numeric vector.

Usage

acf_vec(x, lag_max = 24, ...)

Arguments

x

Numeric vector.

lag_max

Integer. Maximum lag for which the autocorrelation is estimated.

...

Further arguments passed to stats::acf().

Value

A numeric vector containing the sample autocorrelations for lags 1 to lag_max.

Details

acf_vec() is a small wrapper around stats::acf(). It returns the sample autocorrelations as a numeric vector and removes lag 0 from the output, because lag 0 is always equal to 1 and is usually not needed for diagnostics.

Examples

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

x <- M4_monthly_data |>
  filter(series == first(series)) |>
  pull(value)

acf_vec(
  x = x,
  lag_max = 12
)
#>  [1] 0.9929581 0.9868445 0.9807885 0.9746906 0.9692508 0.9631796 0.9573904
#>  [8] 0.9512882 0.9460969 0.9404290 0.9346511 0.9292045