After estimating an ARIMA model in fable, how do I extract the model degrees of freedom (to match the number of parameters in the model) without inputting dof manually, as in?
An alternative to counting the number of of AR and MA terms, plus the constant if there is a drift, you can extract the number of estimated coefficients from fit_arima with:
I am a bit confused. Amarjit's cement example is taken from the "Comparing ARIMA( ) and ETS( ) on seasonal data" section of fpp3 Chapter 9. The selected ARIMA model is (1, 0, 1)(2, 1, 1)[4] w/ drift, and dof = 6 for ljung_box. I assumed this was 5 for the ARMA terms plus one for the constant for drift. An earlier example for Central African Republic exports selected ARIMA(3, 1, 0) with no drift and used dof = 3 for ljung_box.
I may need to change some lecture notes and an exercise!
I recently discovered that the original Ljung-Box paper did not count the constant in the degrees of freedom, and Achim Zeileis pointed out at Degrees-of-freedom adjustment in Ljung-Box test in checkresiduals() · Issue #908 · robjhyndman/forecast · GitHub that it should be excluded. In addition, when the LB test is applied to other models, it is not clear what dof should be used. So we updated the book to reflect this. I thought I had fixed all the examples, but I missed this one. It is now updated.
Thanks for the explanation! I probably would have noticed it earlier, but I am in my university's gradual retirement program and let a junior faculty member teach the forecasting class this year. I might teach it one last time next year and will need to go through the book more carefully.