Repository navigation
ENH: Statespace - add OIM and OPG covariance matrices - #2356
Conversation
There was a problem hiding this comment.
Three levels of loops, but I'm not sure there's anything to be done about it. It's probably only run once though, so it shouldn't be a problem.
|
The way I added the notation to |
|
As preliminary comment: I did only a quick skimming of the changes, very useful |
|
I'll go through the interface later, could be after pycon. |
As I understand it, we have the following options for inference purposes:
So it is clear that the we couldn't have
From e.g. the BHHH paper, my understanding is that any of the first three are acceptable for use in optimization, i.e. dictating the direction/stepsize of the quasi-Newton method. Currently there are two different parameters governing these issues:
Let me know if I have any of this wrong. |
Ah, I see. Well I'm happy to do either, I took the cue here from Stata's output.
Hopefully my above comment clarified that what is reported in the table is the information matrix approximation used for inference. |
|
(without looking at the code) Your list of cov_type sounds right. If we allow for pure OLS/WLS cases without lagged endogenous, then we could also use HAC, AFAIU.
I haven't seen this form yet , OPG is an inverse. I have seen the form inv(OIM) * S'S * inv(OIM) (I don't remember the nobs division. From what I understand of your description, about summary: it's mainly a taste question. I don't like the line with only a single entry |
You're absolutely right, this is just my fault for not being clear what I was referring to, and for having a typo. For my own future reference on this PR, let me lay out things in a way that is, I think, corrent. Here is how Hamilton (1994) defines things (pg 143-145):
where information_matrix can be defined as:
and then the asymptotic approximation to the covariance matrix can be defined as:
and then, the quasi-maximum likelihood standard errors for approximate use when errors may not be IID Gaussian is given by:
The final note in this class of models is that information_matrix_cs is an approximation to the information matrix by directly numerically approximating the second derivative. Harvey (1989) shows how in the asymptotic case we can find an analytic form of the information matrix based on the Hessian that only relies on the numerically evaluated gradient, so that we have an alternative measure:
|
|
With that in mind, I guess my question is how to integrate the robust covariance matrices. It looks like, to maintain consistency, I should define a Then for
I do not know if there is a better name for the So perhaps |
|
(And there's no urgency here, I'm just recording thoughts; so things can just sit until after PyCon or whenever.) |
Good points, I will change the behavior to put the covariance type in the top table. |
|
It's now open season for GSoC and this is the first thing on my list. I still need to change the behavior of the covariance matrix printing in summary, but still to decide is the naming for the
Whether or not to use |
|
This commit fixes the two outstanding issues:
Looking back over the comments, I think this PR still needs some code review, but I don't have anything else planned to do to it right now. |
There was a problem hiding this comment.
oim Harvey is an approximation, is it?
cs is real hessian.
If I remember this correctly, then it might be better to use oim for cs, and oim_harvey or something like this for current oim
There was a problem hiding this comment.
i don't see why users should set hessian method. We should have cov_type as explicit keyword, following my pattern in other models.
There was a problem hiding this comment.
oim Harvey is real (analytic) Hessian but it requires the gradient, which we only have numerically. So it it sort of a hybrid.
There was a problem hiding this comment.
cov_type is an allowed argument, but following the pattern of other models (ARIMAModel, LikelihoodModel, I left it in the kwargs. I can make it explicit though.
There was a problem hiding this comment.
Users can set the hessian method because there are three approximations to the Hessian available, and from BHHH (e.g. p655) we need to use a positive definite matrix that approximates the Hessian. In some cases, I've found the cs Hessian approximation may not be positive definite.
So to my understanding, there are two uses for the Hessian here:
- In optimization (i.e. choosing the direction and stepsize in the optimizer), and that can be affected via
hessian_method. - In inference, and that can be affected via
cov_type.
We don't have to have the first one, and I can just eliminate hessian_method.
There was a problem hiding this comment.
about cov_type: LikelihoodModel is a base class and not all subclasses have the cov_type argument. I thought ARIMA doesn't have a covtype choice.
The final models for the user OLS, WLS, Logit, Poisson, ... and SARIMAX should have and explicit cov_type argument in fit. We can put it explicitly in the fit of a class if it is implemented for the subclasses. I don't know where in the class hierarchy this would be the case for the statespace models.
hessian_method: AFAIU it's irrelevant or superseded by cov_type for inference
I guess it can be useful for the optimization, but if it's only for that, then I would make that more explicit and call it optim_hessian. (which I guess is only relevant if the optimizer uses the hessian. So maybe we should hide hessian_method in the kwargs with the other optimization options.
There was a problem hiding this comment.
about cov_type: LikelihoodModel is a base class and not all subclasses have the cov_type argument. I thought ARIMA doesn't have a covtype choice.
The final models for the user OLS, WLS, Logit, Poisson, ... and SARIMAX should have and explicit cov_type argument in fit. We can put it explicitly in the fit of a class if it is implemented for the subclasses. I don't know where in the class hierarchy this would be the case for the statespace models.
I will make this explicit in the MLEModel, since it should be appropriate for all state space models.
hessian_method: AFAIU it's irrelevant or superseded by cov_type for inference
I guess it can be useful for the optimization, but if it's only for that, then I would make that more explicit and call it optim_hessian. (which I guess is only relevant if the optimizer uses the hessian. So maybe we should hide hessian_method in the kwargs with the other optimization options.
I changed the name to optim_hessian and added a note that it's only used if the optimizer uses the Hessian. I didn't subsume it in kwargs because the base class only checks if a hessian method is defined in the class, and optim_hessian is only used to tell the state space class which method to use. So it's not a generic optimization option. But I can hide it if you prefer.
matrix and covariance matrix.
|
Rebased. Good to merge when green. |
There was a problem hiding this comment.
I had forgotten, privatize this with leading underscore. This does not work for creating a correct results instance if some of the cached attributes are already set.
The use_self option only works if none of the cached properties like bse have been set.
|
privatizing We really need to switch to making this internal use only. |
|
I will merge when TravisCI comes back green. I think this is a very important PR, both in the direction of OPG for numerical problems and to robust for unspecified heteroscedasticity (and some deviations from normality) |
ENH: Statespace - add OIM and OPG covariance matrices
I will add an issue. Thanks! |
Greatly improves covariance matrix and standard error calculation in statespace models.
Primary changes:
information_matrix_typeinfitand in the results class to govern whether the complex step Hessian was used (cs), observed information matrix (oim), outer product of gradients (opg), or the delta method on the complex step Hessian (delta). Default isopg, which is guaranteed to yield a covariance matrix with non-negative diagonal elements, and which is the default in Stata.Other changes
loglikeobsfunction (used in OPG calculation)hessian_methodparameter tofit(). Default is as before, the complex step Hessian.Questions:
information_matrix_typerather thancov_typebecause I believe we want to reserve the latter for specifying e.g.HC#, which could be calculated regardless of which information matrix was used.