I am learning about time series analysis and want to perform Box-Ljung tests of the residuals of my fitted models, e.g.
Box.test(res, lag=h, fitdf=K, type = "Lj")
However, I cannot find a way to calculate $K$. The only heuristics I have thus far are:
- $K$ is equal to the number of parameters in the model.
- If the residuals are calculated on raw data, $K = 0$.
- If the model has no parameters, $K = 0$.
I found a formula for the number of parameters in a non-seasonal ARIMA model for a time series, stating $n = p + q + k + 1$, where $k$ is an indicator function for the constant $c$, that is, $c = k = 0$ if $d \ge 1$, but in the examples I have found, this formula doesn't agree with the $K$ used in the Box-Ljung test.
Can anybody help me count the parameters?