statespace_diagnostics#
Goodness of fit (DK §7.4) and diagnostic checking (DK §2.12, §7.5).
Residuals#
subroutine standardized_residuals(fres, e)
real(dp), intent(out) :: e(:, :) ! (p, n)
subroutine auxiliary_residuals(rep, sres, eps_std, eta_std)
real(dp), intent(out) :: eps_std(:, :), eta_std(:, :) ! (p, n), (r, n)
subroutine auxiliary_residuals_vector(rep, sres, eps_std, eta_std)
subroutine de_jong_penzer(rep, fres, sres, r_stat, e_stat)
real(dp), intent(out) :: r_stat(:, :), e_stat(:, :) ! (m, n), (p, n)
subroutine least_squares_residuals(rep, first, last, vplus, info)
real(dp), intent(out) :: vplus(:, :) ! (p, n)
integer function diagnostic_start(rep, fres)
standardized_residuals\(e_t = L_t^{-1} v_t\) over the observed elements, with \(F_{t,oo} = L_t L_t'\) (Cholesky, as in statsmodels); NaN for missing elements and in the diffuse periods (statsmodels reports 0).
auxiliary_residualsThe smoothed disturbances standardized element by element by \(Var(\hat\varepsilon_t) = H_t - Var(\varepsilon_t | Y)\) and \(Var(\hat\eta_t) = Q_t - Var(\eta_t | Y)\), for detecting outliers and structural breaks (DK §2.12.2, §7.5). NaN where the variance is zero.
auxiliary_residuals_vectorThe same standardized as vectors, \(B_t \hat\varepsilon_t\) with \(B_t' B_t = Var(\hat\varepsilon_t)^{-1}\) (DK §7.5).
de_jong_penzerThe shock statistics of de Jong and Penzer (1998) (DK §7.5): \(r_{i,t} / \sqrt{N_{ii,t}}\) for the state equation and \(e_{i,t} / \sqrt{D_{ii,t}}\) for the observation equation, with \(e_t = F_t^{-1} v_t - K_t' r_t\) and \(D_t = F_t^{-1} + K_t' N_t K_t\) (DK §4.5.3). NaN where undefined.
least_squares_residualsDK §6.2.4: with regression coefficients in states
first..last(diffuse, constant), the residuals at their full-sample estimate \(\hat\beta\), computed as the innovations of the model with those states fixed at \(\hat\beta\). The innovations of the original model are the recursive residuals.diagnostic_startFirst period of the residuals to use in tests: after the burn-in and the diffuse periods.
Tests#
On a residual series, NaNs skipped, as in statsmodels (DK §2.12.1):
subroutine ljung_box(x, stat, pvalue, model_df)
real(dp), intent(in) :: x(:)
real(dp), intent(out) :: stat(:), pvalue(:) ! lags 1..size(stat)
integer, intent(in), optional :: model_df
subroutine jarque_bera(x, jb, pvalue, skew, kurtosis)
subroutine breakvar_test(x, stat, pvalue, h)
integer, intent(in), optional :: h ! default n / 3
ljung_box\(Q(k) = n(n+2) \sum_{j=1}^k \rho_j^2 / (n - j)\) against \(\chi^2_{k - model\_df}\). Pairs with a NaN are skipped.
jarque_beraNormality from skewness and kurtosis, against \(\chi^2_2\).
breakvar_testHeteroskedasticity: H(h), the sum of the last h squared residuals over the sum of the first h, against F(h, h); two-sided p-value.
Goodness of fit#
real(dp) function r2_diffuse(rep, fres, i) result(r2)
subroutine prediction_error_variance(rep, F, info)
real(dp), intent(out) :: F(:, :)
r2_diffuse\(R^2_D = 1 - SSE / \sum_t (\Delta y_t - \overline{\Delta y})^2\), against a random walk with drift (Harvey 1989), for series i.
prediction_error_varianceThe steady-state \(\bar F\) of a time-invariant model (DK §4.3.4, §7.4; see
steady_state). DK’s printed values in §8.2 differ by the factor (n - d)/n; see Road casualties and the seat belt law (DK §8.2).