This function calculates the autocorrelation for a given time series data. It estimates the autocorrelation coefficients, standard errors, test statistics, and p-values for each lag up to a specified maximum lag.

auto_corr(x, lag, alpha = 0.05)

Arguments

x

A numeric vector representing the time series data.

lag

The maximum lag for which autocorrelation is to be calculated.

alpha

The significance level for hypothesis tests. Default is 0.05.

Value

A data frame containing the lag, autocorrelation coefficients (ar), standard errors (se), test statistics (statistic), p-values (p_z and p_t), overall standard errors (se_all), Ljung-Box test statistic (q_lb), and p-value for the Ljung-Box test (p_all).

References

Bartlett, M. S. (1946). On the theoretical specification and sampling properties of autocorrelated time-series. Supplement to the Journal of the Royal Statistical Society, 8(1), 27-41.

Ljung, G. M., & Box, G. E. P. (1978). On a measure of lack of fit in time series models. Biometrika, 65(2), 297-303.

https://de.wikipedia.org/wiki/Korrelogramm

http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/xegbohtmlnode39.html

https://en.wikipedia.org/wiki/Ljung%E2%80%93Box_test

Examples

data <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
auto_corr(data, lag = 3)
#>   lag         ar        se statistic       p_z       p_t   se_all     q_lb
#> 1   1  0.4000000 0.3162278  1.264911 0.2059032 0.3333333 0.619795 7.568044
#> 2   2 -0.1212121 0.4046879 -0.299520 0.7645433 0.7928034 0.619795 7.568044
#> 3   3 -0.5515152 0.4391284 -1.255931 0.2091409 0.3359751 0.619795 7.568044
#>        p_all
#> 1 0.05583564
#> 2 0.05583564
#> 3 0.05583564