Ljung-Box

Ljung-Box test

Overview

The Ljung-Box test checks the “overall” randomnes of a time series using a given number of autocorrelations.
It tests wether any of a group of autocorrelations of a time series are significantly different from 0.

Algorithm

We consider the autocorrelations $\hat\gamma_l, \cdots, \hat\gamma_{l\cdot k}$. Typically, $l=1$ when testing the independence of the series or $l=freq$ when testing seasonality.

The value of the test is defined by

It is asymptotically distributed as a $\chi \left(k\right)$

Implementation

This test is implemented in the class demetra.stats.tests.LjungBoxTest

Example

    int N=100;
    DataBlock sample=DataBlock.make(N);
    Random rnd=new Random();
    LjungBoxTest lb=new LjungBoxTest(sample);
    StatisticalTest test = lb
             .lag(3)
             .autoCorrelationsCount(10)
             .build();