FIX: delayed ARMA impulse response and simulation when p > q - #976
Open
nicoloangileri wants to merge 1 commit into
Open
nicoloangileri wants to merge 1 commit into
nicoloangileri wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ARMA.impulse_responseandARMA.simulationare shifted byp - qperiods when the AR polynomial is longer than the MA polynomial. This includes every pure AR(p) with p >= 2 built with the defaulttheta=0.The docstring says
psi[0]is unity, andstatsmodels'ArmaProcess(...).arma2magives the second line.qe.ARMA([0.5, 0.1, 0.05])is delayed by two periods, andsimulationstarts withp - qexact zeros for the same reason.The cause is in
set_params:(ma_poly, ar_poly, 1)is passed toscipy.signal.dimpulseanddlsim, which read the coefficients as a transfer function in positive powers ofz. Whenar_polyis longer, the numerator has a lower degree and the system getslen(ar_poly) - len(ma_poly)pure delays.set_paramsalready paddedar_polywhenma_polywas longer; it now also padsma_polywith zeros, so both polynomials have the same length.spectral_densityandautocovarianceusefreqz, which is not affected by trailing zeros, and their output is unchanged.The existing tests use
theta = np.zeros(3)with three AR coefficients, so the polynomials already had the same length there. The new tests check, for AR(1), AR(2), AR(3), ARMA(2, 1), ARMA(1, 2) and the existing test model:impulse_responseagainst the MA(inf) coefficients from the recursionpsi_j = theta_j + sum_i phi_i psi_{j-i};simulationagainstsum_j psi_j u_{t-j}built from the same shocks.Both fail on
mainand pass here. The full test suite passes locally (745 tests).Related to #888 (test coverage of the simulation and impulse-response paths in
_arma).