2

I am using Ljung-box test after fitting an ARIMA model to a time series to investigate whether residuals do look like white noise or not. For this purpose I need to define the degree of freedom in the ljung_box function in R. I am not sure how we extract the number of parameters, is the sum of p, q and the Seasonal P & Q in case we have a seasonal ARIMA model? As an example imagine we have a regression model with ARIMA errors like this:

fit <- vic_elec_daily %>%
  model(ARIMA(Demand ~ Temperature + I(Temperature^2) + 
    (Day_Type == "Weekday")))

Resulting in:

fit

A mable: 1 x 1

ARIMA(Demand ~ Temperature + I(Temperature^2) + (Day_Type == \n &quot;Weekday&quot;)) <model> 1 <LM w/ ARIMA(2,1,2)(2,0,0)[7] errors>

The degree of the freedom specified by the Dr. Hyndman is 9 in this case but I am not sure how one should do it.

Any help is appreciated in advance.

2 Answers2

0

Let $\hat \rho = [\hat \rho_1 \ \dots \ \hat \rho_p]'$ be the estimated correlation coefficients for $p$ lags. Under the null of no correlation it holds that $\hat \rho \sim \mathcal{N}(0,I_p)$, where $I_p$ is the $p \times p$ identity matrix (proof needed). The Ljung-Box test (similar to the Box-Pierce test) uses the statistic $\hat \rho ' \hat \rho \sim \chi^2_p$, which is chi-squared distributed with $p$ degrees of freedom. Hence the degrees of freedom of a Ljung-Box test refers to the degrees of freedom of the $\chi^2$ distribution, which refers to the number of lags tested for autocorrelation.

PaulG
  • 1,267
  • 1
    This holds for raw data but not for residuals from an ARMA model. Thus the answer may be misleading. – Richard Hardy Apr 18 '22 at 06:21
  • I second the comment by @RichardHardy. After parameter estimation the degrees of freedom must be reduced accordingly. – statmerkur Apr 18 '22 at 06:28
  • Thank you for your response, but still I haven't understood clearly how I can discern the degree of freedom when we have a model as I mentioned in the question. – Anoushiravan R Apr 18 '22 at 09:29
0

the degree of freedom should be the number of parameter estimates. As stated in this book - "To be sure, we use a Ljung-Box test, being careful to set the degrees of freedom to match the number of parameters in the model." (see section 9.9 here https://otexts.com/fpp3/seasonal-arima.html). So, for a non-seasonal ARIMA model dof will be p+q. For a seasonal ARIMA model, the dof should p+q+P+Q. Hope this helps.

Paul
  • 1