Formula: \(Q = n(n+2) \sum_{k=1}^{m} r_k^2 / (n-k)\), referred to
chi-square on lags - fitdf degrees of freedom. The
\((n+2)/(n-k)\) factor is a variance correction for \(r_k\),
whose exact null variance is \((n-k)/(n(n+2))\) rather than
\(1/n\); \(r_k\) uses the biased normalisation of
stats::acf.
References
Ljung and Box (1978), On a measure of lack of fit in time series models, Biometrika 65:297-303. Paywalled at JSTOR (HTTP 403); the statistic was taken from R's own stats::Box.test (src/library/stats/R/ts-tests.R), the canonical reference implementation.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
Ljungbox(V)
#> $statistic
#> [1] 4.464286
#>
#> $p_value
#> [1] 0.03461056
#>
#> $df
#> [1] 1
#>
#> $acf
#> [1] 0.625
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Ljung-Box Q test"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
