2

When reading ?Box.test, I learned about a rarely mentioned parameter fitdf, which specified the "number of degrees of freedom to be subtracted if x is a series of residuals". It seems that when applying this function on residuals, we should pass this parameter to Box.test.

Details

These tests are sometimes applied to the residuals from an ARMA(p, q) fit, in which case the references suggest a better approximation to the null-hypothesis distribution is obtained by setting fitdf = p+q, provided of course that lag > fitdf.

However, many appear to ignore this suggestion. Here is the source code of an implementation of the S3 method tsdiag. Note that Box.test didn't get fitdf.

> getS3method("tsdiag", "Arima")
function (object, gof.lag = 10, ...) 
{
    oldpar <- par(mfrow = c(3, 1))
    on.exit(par(oldpar))
    rs <- object$residuals
    stdres <- rs/sqrt(object$sigma2)
    plot(stdres, type = "h", main = "Standardized Residuals", 
        ylab = "")
    abline(h = 0)
    acf(object$residuals, plot = TRUE, main = "ACF of Residuals", 
        na.action = na.pass)
    nlag <- gof.lag
    pval <- numeric(nlag)
    for (i in 1L:nlag) pval[i] <- Box.test(rs, i, type = "Ljung-Box")$p.value
    plot(1L:nlag, pval, xlab = "lag", ylab = "p value", ylim = c(0, 
        1), main = "p values for Ljung-Box statistic")
    abline(h = 0.05, lty = 2, col = "blue")
}
<bytecode: 0x7fad483ad6c8>
<environment: namespace:stats>

Is this OK?

nalzok
  • 1,385
  • 12
  • 24
  • 1
    This is not OK. See my comments under the answer of javlacalle in [this thread](https://stats.stackexchange.com/questions/148004/) and my answer in [this thread](https://stats.stackexchange.com/questions/136116/). – Richard Hardy Jun 04 '19 at 07:16

0 Answers0