Dataplot Vol 1 Vol 2

# LJUNG-BOX TEST

Name:
LJUNG-BOX TEST
Type:
Analysis Command
Purpose:
Perform a Ljung-Box test for randomness.
Description:
There are a large number of tests of randomness (e.g., the runs tests). Autocorrelation plots are one common method test for randomness. The Ljung-Box test is based on the autocorrelation plot. However, instead of testing randomness at each distinct lag, it tests the "overall" randomness based on a number of lags. For this reason, it is often referred to as a "portmanteau" test.

More formally, the Ljung-Box test can be defined as follows.

 H0: The data are random. Ha: The data are not random. Test Statistic: The test statistic is: $$Q_{LB} = n(n+2) \sum_{j=1}^{h}{\frac{\rho^{2}(j)}{n-j}}$$ where n is the sample size, $$\rho_{j}$$ is the autocorrelation at lag j, and h is the number of lags being tested. Significance Level: $$\alpha$$ Critical Region: The hypothesis of randomness is rejected if $$Q_{LB} = \chi_{1-\alpha;h}^{2}$$ where $$\chi^{2}$$ is the percent point function of the chi-square distribution.

The Ljung-Box test is commonly used in ARIMA modeling. Note that it is applied to the residuals of a fitted ARIMA model, not the original series.

Syntax:
LJUNG-BOX TEST <y>       <SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable being tested;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Examples:
LJUNG-BOX TEST RES
LJUNG-BOX TEST Y1 SUBSET TAG > 1
Note:
The number of lags to test can be set by entering any of the following command (before entering the LJUNG-BOX command):

LET LAGS = <value>
LET LAG = <value>
LET NUMLAG = <value>

By default, Dataplot will use the same number of lags as the autocorrelation plot. Typically, you will want to test fewer lags. Although the choice is somewhat arbitrary, 25 is a reasonable number for many series.

Note:
The following statistic is also supported:

LET A = LJUNG BOX TEST Y

In addition to the above LET command, built-in statistics are supported for about 20+ different commands (enter HELP STATISTICS for details).

Default:
None
Synonyms:
LJUNG TEST and LJUNG-BOX are synonyms for LJUNG-BOX TEST.
Related Commands:
 AUTOCORRELATION PLOT = Generate an autocorrelation plot. RUNS TEST = Perform a runs test for randomness. ARMA = Perform an ARIMA fit.
Reference:
G. M. Ljung and G. E. P. Box (1978), "On a Measure of a Lack of Fit in Time Series Models," Biometrika, Vol. 65, pp. 297-303.

Peter Brockwell and Richard Davis 2002, "Introduction to Time Series and Forecasting," 2nd. Ed., Springer, p. 36.

Applications:
ARIMA Modeling
Implementation Date:
2003/2
Program:

ARMA Y 2 1 0
LET NUMLAG = 25
SET WRITE DECIMALS 4
LJUNG-BOX TEST RES

Dataplot generates the following output for the Ljung-Box test:

Ljung-Box Test for Randomness

Response Variable: RES

H0: The Data Are Random
Ha: The Data Are Not Random

Summary Statistics:
Number of Observations:                  559
Lag Tested:                              24
Lag 1 Autocorrelation:                   -0.0010
Lag 2 Autocorrelation:                   0.0062
Lag 3 Autocorrelation:                   0.0052

Ljung-Box Test Statistic:                31.9107
CDF Value:                               0.8708
P-Value:                                 0.1292

Conclusions (Upper One-Tailed Test)

------------------------------------------------------------------------
Null
Null     Confidence           Test       Critical     Hypothesis
Hypothesis          Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------------------
Random          0.0%         31.9107         0.0000         REJECT
Random          50.0%        31.9107        23.3367         REJECT
Random          75.0%        31.9107        28.2412         REJECT
Random          90.0%        31.9107        33.1962         ACCEPT
Random          95.0%        31.9107        36.4150         ACCEPT
Random          97.5%        31.9107        39.3641         ACCEPT
Random          99.0%        31.9107        42.9798         ACCEPT
Random          99.9%        31.9107        51.1786         ACCEPT


NIST is an agency of the U.S. Commerce Department.

Date created: 3/10/2003
Last updated: 10/31/2016