Skip to content

ENH: Statespace: Postestimation - #2566

Merged
josef-pkt merged 32 commits into
statsmodels:masterfrom
ChadFulton:ss-postest
Sep 9, 2015
Merged

josef-pkt merged 32 commits into
statsmodels:masterfrom
ChadFulton:ss-postest

Conversation

@ChadFulton

Copy link
Copy Markdown
Member

A PR corresponding to #2564. Would like to add support for (at least):

  • Full prediction / forecast interface (e.g. with confidence intervals, etc).
  • Add impulse response functions, FEVDs, etc., and confidence intervals (at least asymptotic, possibly bootstrapped as well).

Possibly will also address (but may punt for later):

  • Figure out how to better implement a wide range of diagnostic tests

@ChadFulton

Copy link
Copy Markdown
Member Author

Initial push adds support to state space results objects for:

  • Simulating a new time series based on the fitted model / parameter values (res.simulate())
  • Impulse response functions based on the fitted model / parameter values (res.impulse_responses()) - these are just point IRFs right now, no confidence intervals of any kind.

@ChadFulton

Copy link
Copy Markdown
Member Author

Ah, looks live I've messed up this branch. I'll clean this up with Git and force push in a bit.

@ChadFulton

Copy link
Copy Markdown
Member Author

Okay, that did it, this branch is clean.

@ChadFulton

Copy link
Copy Markdown
Member Author

Rebased. Currently this branch includes:

  • Full prediction / forecast interface (get_prediction, get_forecast)
  • Simulation (simulate)
  • Impulse responses (impulse_responses) without confidence intervals

and I think that is enough for now. The FEVD and asymptotic confidence intervals for IRFs that I have in mind are specific to VARMA-type models, so I think I'd like to add them there instead of generally for the state space classes.

So, pending review and assuming Travis is green, I think this branch can be merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is k_posdef? not defined or explained

shape specification in numpy notation would be easier to understand, e.g.
"a column vector with shape (k_posdef, 1)"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k_posdef is defined in the general state space model; I'll add a note giving that reference.

Good idea about the shape specification.

@josef-pkt

Copy link
Copy Markdown
Member

@ChadFulton general question (about possible future design changes)

Would it be difficult to add an option that the estimation uses only a subsample of the attached data?
Eg. nobs =500 and I only want to use the first 400 observation to estimate, but filter all of them, or use the last 100 for out of sample prediction.

My guess would be that this could be a good speedup for rolling or expanding backtesting, or crossvalidation on out of sample prediction, depending on how expensive it is to set up a state space model from scratch.
(It has been requested several times for ARMA.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of the method still has full_results

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@josef-pkt

Copy link
Copy Markdown
Member

Please rebase again, so we get the Travis run after the test fixes.

master is on 0.8 version, so I can merge this today or tomorrow

I didn't completely review, not enough to understand how all the pieces fit together. I didn't see any real problems.
IMO, we can merge these PRs relatively fast and then do another round of review and playing with examples after the merges to see how well everything works together.

@josef-pkt

Copy link
Copy Markdown
Member

@ChadFulton

Copy link
Copy Markdown
Member Author

On impulse response function options, especially concerning orthogonalized and generalized IRFs:

(Note: I haven't thought about this too deeply, but I'm pretty sure the below is a first-pass correct way to view the differences. I'm going to dump some information here, which may or may not be useful to you, but will be useful to me to put down somewhere.)

The main difference is that the VAR specification knows the moving average form (dynamic multipliers) from the coefficient matrices. Then orthogonalized or generalized impulse responses can be computed by selecting (possibly scaled) columns from the dynamic multipliers multiplied by some matrix (e.g. Cholesky decomposition or otherwise). The key here is that the VAR impulse responses are usually described in terms of the selection of columns from matrices that can be generically known / calculated. The problem here is calculating the matrices we want.

In our generic case we do not know the moving average form, and so we don't know the dynamic multipliers, so instead I have set this up to think about simulating the process from a given initial shock. Thought about this way, the problem is selecting the initial shock. In the naive case, this leads to doing a 1-unit shock to a specific error component. In the "orthogonalized" shocks case, this leads to taking a 1-unit shock to a specific error component and using the Cholesky factor to "spread the shock out" according to the true correlation structure. In the "generalized" case, again spread the shock out, but this time according to the scaled covariance matrix.

A byproduct of this difference is that the function in the state space package can only compute a single impulse response at a time, whereas in the VAR model it can compute them all simultaneously through matrix multiplication.

Right now, the implementation allows specification of the (single) impulse itself, so it is generic to any formulation someone might want. i.e. you could get orthogonalized impulse responses as follows:

mod = ...
res = mod.fit()
base_impulse = np.array([1,0,0])
var_decomp = np.linalg.cholesky(res.filter_results.state_cov)
impulse = np.dot(var_decomp, base_impulse)
res.impulse_responses(steps=10, impulse=impulse)

or generalized impulses by doing:

mod = ...
res = mod.fit()
base_impulse = np.array([1,0,0])
state_cov = res.filter_results.state_cov
impulse = np.dot(state_cov, base_impulse) / np.sqrt(state_cov[0,0])
res.impulse_responses(steps=10, impulse=impulse)

Right now there are two additional conveniences; first, instead of providing the impulse vector, you can instead provide the index of the error component to be shocked; the following does a 1-unit impulse to the second error component.

mod = ...
res = mod.fit()
res.impulse_responses(steps=10, impulse=1)

The second helper allows orthogonalized shocks using the orthogonalized keyword:

mod = ...
res = mod.fit()
res.impulse_responses(steps=10, impulse=1, orthogonalized=True)

so this just generates the base impuse vector as np.array([0,1]) and then pre-multiplies it by the Cholesky of the state covariance matrix.


So maybe I should remove the orthogonalized argument, and instead add something like transform_impulse={None, 'orthogonalized'}. We could then add 'generalized', and possibly others?

@ChadFulton

Copy link
Copy Markdown
Member Author

Rebased. I think I have fixed all the above comments, except for the question about whether to replace orthogonalized with transform_impulse.

@josef-pkt

Copy link
Copy Markdown
Member

That took a long time for Travis to run the tests. Py 2.6 timed out this time. Something is still fragile somewhere. The first py 2.7 times out sometimes, it's the first time I saw it with py2.6, AFAIR.

transform_impulse={None, 'orthogonalized'} looks a bit ugly compared to know and I think we can leave finding the right options when we need them.

I'm planning to merge this after another brief look.

josef-pkt added a commit that referenced this pull request Sep 9, 2015
ENH: Statespace: Postestimation
@josef-pkt
josef-pkt merged commit 3ed2fd9 into statsmodels:master Sep 9, 2015
@josef-pkt

Copy link
Copy Markdown
Member

Thanks @ChadFulton

number 1 is merged

@josef-pkt josef-pkt added this to the 0.8 milestone Sep 9, 2015
@ChadFulton
ChadFulton deleted the ss-postest branch January 16, 2016 08:38
@josef-pkt josef-pkt mentioned this pull request Feb 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants