How to define degree of freedom for Ljung Box text? 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    "Weekday"))`
                                                                           <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.

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.
