Skip to content

ENH: Allow ARMA(0,0) and ARIMA(0,d,0) models with constant/trend models to be estimated - #1262

Closed
bashtage wants to merge 6 commits into
statsmodels:masterfrom
bashtage:ARIMA-order-0-0
Closed

bashtage wants to merge 6 commits into
statsmodels:masterfrom
bashtage:ARIMA-order-0-0

Conversation

@bashtage

Copy link
Copy Markdown
Member

Does not try to implement "parameterless" models.

Fix AIC and BIC so that they match LS when models are identical
Remove checks on (0,0) and (0,d,0) models
Fixed bug where fittedvalues where not initialized
Information criteria tests are not failing - need clarification about definition
@josef-pkt

Copy link
Copy Markdown
Member

Looks quite good, I didn't expect that you can get with as few changes as in this PR

looking through parts of the source: df_model includes the constant if it is estimated (in contrast to other models), so the extra + 1 looks strange to me.

For the details, I leave it to @jseabold It's his code and he wrote the unittests.

@bashtage

Copy link
Copy Markdown
Member Author

I have updated the tests with a few more edge cases involving exogenous regressors.

I agree that the +1 is almost certainly from a formula where:

  • df_model does not include a constant
  • The model is always assumed to include a constant

The main issue is how to fix the test failures. It seems that res2 comes form gretl which have been hand encoded into resulta_arma.py. Is there anything documented on how the gretl was produced?

@josef-pkt

Copy link
Copy Markdown
Member

In some cases we added the R or Stata files to the test directory, but not always or not even very often. the .inp file might be Gretl, If I remember correctly, Skipper used it for testing forecast, and found a bug in Gretl.

the results .py files look to be autogenerated from R or Stata. We have Stata and R scripts in tools to dump the results to py files and csv,

@bashtage

Copy link
Copy Markdown
Member Author

For now I have fixed them is a bad way but subtracting 1 unit of the penalty in the test functions. It would be best to re-generate these test results (and have a script that can do the regeneration), but that sounds a non-trivial issue and also potentially risky.

@jseabold

Copy link
Copy Markdown
Member

Gretl results available in the GUI are not always available from their scripting language IIRC, so you have to do it by point and click in the GUI. This may have changed since I wrote this, or I may just not have spent much time trying to do this. Otherwise, it was the case that you don't have enough control over formatting from the scripting language so it was just easier to copy-paste the table at greater precision from the GUI.

The .inp files in tsa/tests/results/ show how to save the forecasts.

My recollection/guess is that the +1 is included because we are also estimating the variance and that's not included in our df_model. The tests are 'right' in that, that's what I got from gretl, R, or Stata. I'm fairly certain that the MLE results are from Stata and that the CSS results are from gretl/R, based on code comments in the tests suite and results.

The DOF calculation  it is now consistent with both OLS and other packages
@jseabold

jseabold commented Jan 8, 2014

Copy link
Copy Markdown
Member

Are the IC changes related to the other changes? If not, can you put them into a separate PR? I'm going to look into this.

@jseabold

jseabold commented Jan 8, 2014

Copy link
Copy Markdown
Member

Yes, the information criteria as is match gretl already. The issue is that our df_model does not include the estimated variance hence the +1, though their k in the manual is the "number of 'independently adjusted parameters within the model,'" which includes both the estimated parameters and the variance, presumably. Maybe df_model should include the variance? But in any even the current formulas and tests are right.

@josef-pkt

Copy link
Copy Markdown
Member

Is there a justification why they count also the variance? We don't do it in the linear models.

@jseabold

jseabold commented Jan 8, 2014

Copy link
Copy Markdown
Member

My guess was always that though it's concentrated out, it could be (and is often presented as if it is) estimated as part of the optimization problem. MLE vs. OLS. Cf. the discrete choice models.

@jseabold

jseabold commented Jan 8, 2014

Copy link
Copy Markdown
Member

The x-12arima manual is a little more explicit. "Suppose the number of estimated parameters in the model, including the white noise variance, is n_p...then the formulas are"

AIC = -2L + 2*n_p 
AICC = -2L + 2*n_p*(1 - (n_p +1)/N)**-1
HQIC = -2L + 2*n_p*log(log(N))
BIC = -2*L + n_p*log(N)

@josef-pkt

Copy link
Copy Markdown
Member

sounds ok to me either way.

I assume in a GARCH model we would also count the variance parameters. Then the question is whether ARMA is a generalization of OLS/GLS or if it is a special case of GARCH.
And I still haven't figured out some other cases, for example, when I did pure normal MLE without concentrating out the scale, then I also had one extra parameter compared to LS.
I don't think we count (co)variance parameters in GLSAR and similar, but I haven't checked.

(maybe there is an analogy to the difference between ML and REML which I also haven't really figured out yet. Maybe there is some justification somewhere why we should have one or the other which is only really relevant in very small samples, and to have a nice consistency across models. )

And finally: the Stata documentation has quite a lot of explanations why different equivalent models/estimators don't give exactly the same results, mainly because of different small sample corrections.

@bashtage

Copy link
Copy Markdown
Member Author

After reading through the testing comments, I found some information about "why" the IC take the forms that they do.

In particular, the IC match X12 but not GRETL in all cases.

GRETL uses:

  • the same IC for pure AR models estimated using CSS as it does for OLS. This way when OLS is estimated though the AR interface, the IC is the same (e.g. ARMA(0,0)).
  • The +1 IC for ARMA or MA models estimated using CSS or any model estimated using Exact ML

The GRETL choices are particularly confusing since they don't generally match the GRETL documentation.

X12, according to the comments, always uses the +1 IC.

While I believe the +1 is due to sigma^2 parameter, I think it is silly since restricting the sigma^2 produces a model which is no longer point identified, at least for AR models estimated CSS since there is a K-1 dimension solution to this problem.

I am a big beleiver is doing things based on sane principles even if it means differing form what other packages output, at least when:

  • It is understood as to why the divergence occurs
  • The tests can be corrected for the deviation

@bashtage

Copy link
Copy Markdown
Member Author

My guess was always that though it's concentrated out, it could be (and is often presented as if it is) estimated as part of the optimization problem. MLE vs. OLS. Cf. the discrete choice models.

I think it only makes sense to treat it as a parameter if it is possible to fix its (sigma^2) value and then estimate the remaining parameters. Similar to fixing an AR coefficient, and then not counting this.

@josef-pkt

Copy link
Copy Markdown
Member

There is always a difference in treatment between OLS and some full maximum likelihood (for general models). The question is where is the difference.

One argument why I thought about not counting the variance parameter in OLS and GLS with heterogeneity is when the Hessian is block diagonal.
In many models that I looked at recently (GEE, GMM, WLS/GLS with estimated variance function, Poisson/exponential) the justification for a two stage process relies on the block diagonal structure of the Hessian, information matrix or similar.
With the same argument we can consistently estimate in this models the mean function even if the variance function is misspecified.

From this it sounds like we could justify the boundary between counting or not counting the variance parameter in whether we have the block diagonal structure and can separate the mean model from the (co)variance model. If we don't have the block diagonal structure, then the mean model cannot be consistently estimated without correctly specifying the variance function.

I don't know what this means for ARMA models, but for example for GARCH models there is a difference between garch in mean without separation and the regular garch models that have separation of mean and variance function (and in ARMA-GARCH we can estimate the two parts separately).

However maybe this gets "weird" if we estimate mean and variance functions jointly in MLE and would separate the IC for the two parts. However, we do separate them in a two stage model, I think.

@josef-pkt

Copy link
Copy Markdown
Member

I think it only makes sense to treat it as a parameter if it is possible to fix its (sigma^2) value and then estimate the remaining parameters. Similar to fixing an AR coefficient, and then not counting this.

I've never heard about that in econometrics. However, astronomists, physicists and in some engineering fields they fix sigma. I had long discussions on the scipy mailing list and scipy issues about whether the scale/sigma should be estimated in nonlinear WLS or not.
With a fixed sigma the weighted error sum of squares then gets a chisquare interpretation.

However, for least squares the estimating or fixing the scale does not affect the (mean) parameter estimates.
As a Bayesian it would be just a very strong prior for the variance estimate.

I'm not sure it's relevant for ARMA. Does the variance parameter directly affect the coefficient estimates through the initial conditions?

@josef-pkt

Copy link
Copy Markdown
Member

However maybe this gets "weird" if we estimate mean and variance functions jointly in MLE and would separate the IC for the two parts. However, we do separate them in a two stage model, I think.

Maybe that's not so weird. In terms of consistency with misspecification it makes a difference if we estimate in two stages or in the joint estimation problem.

I haven't implemented anything yet, but from what I was reading in GEE and GMM, when the information matrix has block-diagonal structure:
If we estimate in two stages, then the misspecified first stage (covariance estimation) does not prevent consistent estimation of the mean function. If we want to check the specification of the mean model (using IC), then I guess we can also ignore the first stage.
If we estimate jointly, then consistent estimation depends on the correct specification of all parts (the full model). I guess in this case we shouldn't treat the specification search for the two parts separately, and should use a joint IC.

@josef-pkt

Copy link
Copy Markdown
Member

Making the same argument in small samples, for the actual calculation:

In OLS, WLS, GLS and Poisson, we can set the scale to anything and the actual coefficients and mean prediction, fittedvalues and residuals don't change. This doesn't rely on asymptotics, it's just the separability of the optimization problem.
In other models, we don't get this numerical separability (but we can still get the asymptotic separability).
(as far as I remember)

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 736d32a on bashtage:ARIMA-order-0-0 into * on statsmodels:master*.

@bashtage

Copy link
Copy Markdown
Member Author

In many models that I looked at recently (GEE, GMM, WLS/GLS with estimated variance function, Poisson/exponential) the justification for a two stage process relies on the block diagonal structure of the Hessian, information matrix or similar.
With the same argument we can consistently estimate in this models the mean function even if the variance function is misspecified.

In the case of least squares/Gaussian MLE, the justification is that given the parameters of the conditional mean, the ML estimator of the variance has a closed form so that the concentrated log likelihood can be used in place of the full (joint) log likelihood. The block diagonality of the hessian only holds when either the model includes a constant or when the model is correct for the conditional mean; the concentration still holds even when the model is mis-specified.

From this it sounds like we could justify the boundary between counting or not counting the variance parameter in whether we have the block diagonal structure and can separate the mean model from the (co)variance model.

I would think a more natural "test" is whether the scale/variance is be jointly estimated with the other parameters in the model so that it could be naturally restricted. In all of the LS models, including CSS AR, this is not possible since the solution is no longer point identified, and so I think it is reasonable to not count the variance in these models.

I don't know what this means for ARMA models, but for example for GARCH models there is a difference between garch in mean without separation and the regular garch models that have separation of mean and variance function (and in ARMA-GARCH we can estimate the two parts separately).

In GARCH models the natural analogue would be to not count the intercept in the variance equation since this parameter would be there even if all of the ARCH-terms were removed. Although someone may be interested in estimating a model with out an intercept in the variance equation (e.g. IGARCH), and so things would become more complicated.

However, for least squares the estimating or fixing the scale does not affect the (mean) parameter estimates.
As a Bayesian it would be just a very strong prior for the variance estimate.

I think this affects the convexity of the problem, although a proper prior on the regression coefficient would provide some guidance on which coefficients to prefer.

In OLS, WLS, GLS and Poisson, we can set the scale to anything and the actual coefficients and mean prediction, fittedvalues and residuals don't change. This doesn't rely on asymptotics, it's just the separability of the optimization problem.

I think this is the wrong test - the important question is whether these are ML estimates (or justifiable under some other criteria, such as consistency).

@josef-pkt

Copy link
Copy Markdown
Member

about concentrated log likelihood: I always thought this is just a computational trick. We can always replace a joint optimization by a nested optimization. Is there anything that concentrating out the scale adds?

Even if we maximize the non-concentrated log-likelihood, then the first order conditions for the mean parameters are independent of the scale/variance estimate in the normal model, aren't they?

I would think a more natural "test" is whether the scale/variance is be jointly estimated with the other parameters in the model so that it could be naturally restricted. In all of the LS models, including CSS AR, this is not possible since the solution is no longer point identified.

I don't understand this part. What do you mean by "no longer point identified"? We still get the unique solution for the mean parameters, which is still a consistent estimator in OLS, WLS, AFAIKS.

It might be irrelevant for all practical purposes but the similar case that I'm interested in and where we have to come up with some convention is between Feasible GLS and MLE for linear models with estimated heteroscedasticity or autocorrelation.
(Based on the test results that I saved from Gretl, it looks like they don't report aic or bic with GLSAR - Cochrane-Orcutt or Prais-Winston ar1, they might also just report the WLS results after GLSHet, hsk. I didn't know they have that and never tried.)

@bashtage

Copy link
Copy Markdown
Member Author

Is there anything that concentrating out the scale adds?
Just computational convenience - but it is often a lot (in the case of the variance, it avoids an extra constraint in the optimization or a transformation (i.e. exp() or x**2)

Even if we maximize the non-concentrated log-likelihood, then the first order conditions for the mean parameters are independent of the scale/variance estimate in the normal model, aren't they?

I don't think this is any reason to not use the concentrated likelihood since it is always the solution to the MLE, only a full likelihood has a additional parameter to estimate.

I don't understand this part. What do you mean by "no longer point identified"? We still get the unique solution for the mean parameters, which is still a consistent estimator in OLS, WLS, AFAIKS.

Suppse you want to estimate the mean using LS - which is just regression on a constant. However, you want to do this subject to a constraint that the variance is 1 (and suppose that this is larger than the MLE estimator of the variance), then there are 2 points which will produce the same variance value of 1, mu_hat + theta and mu_hat - theta where theta is that value that will make the variance satisfy the constraint. If the regression model had more explanatory variances, the set of points would be a k-1 dimensional plane (i.e. a line if 2 regressors, etc.)

@bashtage

Copy link
Copy Markdown
Member Author

I think I'll roll back all of the IC changes and leave that for someone else.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling d66ea97 on bashtage:ARIMA-order-0-0 into * on statsmodels:master*.

@josef-pkt

Copy link
Copy Markdown
Member

Suppse you want to estimate the mean using LS - which is just regression on a constant. However, you want to do this subject to a constraint that the variance is 1 (and suppose that this is larger than the MLE estimator of the variance), then there are 2 points which will produce the same variance value of 1, mu_hat + theta and mu_hat - theta where theta is that value that will make the variance satisfy the constraint. If the regression model had more explanatory variances, the set of points would be a k-1 dimensional plane (i.e. a line if 2 regressors, etc.)

(I just realized I never wrote my reply)

Aren't you fixing the mse, the variance of the estimated residuals in this case, and not the estimated population variance.
The way I interpret this is that we still get the OLS or MLE beta estimate. When we set up the Lagrangian with sigma fixed, then the first order condition for the mean parameters is unchanged. sigma only enters the first order condition for sigma and the constraint. So, the solution should be that the mean parameters, beta, are the same as in the unconstrained problem, but the sigma estimate is just our restriction.
This should be correct in the linear model (normal mle, ols, wls, gls) and, I think, in exponential family with canonical link function, like poisson with exp.

@jseabold

jseabold commented Feb 7, 2014

Copy link
Copy Markdown
Member

Any objections to my cleaning this up a bit before a merge. I just want to squash to two commits for tests and the code changes and rewrite the commit messages so that things are clear. To be clear the code, the authorship, and the notes will be the same as they are now.

@jseabold

jseabold commented Feb 7, 2014

Copy link
Copy Markdown
Member

See #1370.

@jseabold

jseabold commented Feb 7, 2014

Copy link
Copy Markdown
Member

Closed by baff17b.

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.

4 participants