Skip to content

FIX: Define trendorder for trend only models in VAR - #2327

Closed
saketkc wants to merge 3 commits into
statsmodels:masterfrom
saketkc:gh-2271
Closed

saketkc wants to merge 3 commits into
statsmodels:masterfrom
saketkc:gh-2271

Conversation

@saketkc

@saketkc saketkc commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

Fixes #2271

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 83.91% when pulling a19d847 on saketkc:gh-2271 into 5dd2502 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

Thanks,

Did you check what happens to VAR.fit after this fix?
If we fix the helper function, then maybe VAR breaks somewhere else, or it could even produce incorrect numbers if this case is not allowed (not implemented yet). In the latter case, we would need to raise a ValueError in VAR.

@saketkc

saketkc commented Mar 18, 2015

Copy link
Copy Markdown
Contributor Author

I did:

In [20]: model = VAR(data)

In [21]: results = model.fit(2, trend = 't')

In [22]: results.summary()
Out[22]: 
  Summary of Regression Results   
==================================
Model:                         VAR
Method:                        OLS
Date:           Wed, 18, Mar, 2015
Time:                     10:58:24
--------------------------------------------------------------------
No. of Equations:         3.00000    BIC:                   -27.3915
Nobs:                     200.000    HQIC:                  -27.5977
Log likelihood:           1943.42    FPE:                8.98787e-13
AIC:                     -27.7378    Det(Omega_mle):     8.10654e-13
--------------------------------------------------------------------
Results for equation realgdp
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const               0.000001         0.000007            0.113           0.911
L1.realgdp         -0.215327         0.165442           -1.302           0.195
L1.realcons         0.689491         0.131560            5.241           0.000
L1.realinv          0.020205         0.025097            0.805           0.422
L2.realgdp          0.059267         0.170771            0.347           0.729
L2.realcons         0.324729         0.145420            2.233           0.027
L2.realinv         -0.016105         0.025272           -0.637           0.525
==============================================================================

Results for equation realcons
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const               0.000017         0.000006            2.813           0.005
L1.realgdp          0.069194         0.150807            0.459           0.647
L1.realcons         0.308417         0.119922            2.572           0.011
L1.realinv         -0.007257         0.022877           -0.317           0.751
L2.realgdp          0.022924         0.155664            0.147           0.883
L2.realcons         0.313153         0.132556            2.362           0.019
L2.realinv         -0.000055         0.023036           -0.002           0.998
==============================================================================

Results for equation realinv
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const              -0.000104         0.000035           -2.990           0.003
L1.realgdp         -2.585443         0.878918           -2.942           0.004
L1.realcons         4.265822         0.698916            6.103           0.000
L1.realinv          0.340764         0.133329            2.556           0.011
L2.realgdp         -0.180373         0.907225           -0.199           0.843
L2.realcons         0.537421         0.772547            0.696           0.487
L2.realinv         -0.037848         0.134257           -0.282           0.778
==============================================================================

Correlation matrix of residuals
             realgdp  realcons   realinv
realgdp     1.000000  0.603037  0.711741
realcons    0.603037  1.000000  0.063149
realinv     0.711741  0.063149  1.000000

@josef-pkt

Copy link
Copy Markdown
Member

the summary table shows const. I guess it should be trend.
Do the coefficients differ from the trend='c' case?

@saketkc

saketkc commented Mar 18, 2015

Copy link
Copy Markdown
Contributor Author

Yes, that's what made me trust it works:

In [47]: results = model.fit(2, trend = 't')

In [48]: results.coefs
Out[48]: 
array([[[ -2.15327341e-01,   6.89490653e-01,   2.02048127e-02],
        [  6.91942813e-02,   3.08417086e-01,  -7.25678927e-03],
        [ -2.58544292e+00,   4.26582190e+00,   3.40763606e-01]],

       [[  5.92669940e-02,   3.24728619e-01,  -1.61046931e-02],
        [  2.29239907e-02,   3.13153140e-01,  -5.47725418e-05],
        [ -1.80373170e-01,   5.37420802e-01,  -3.78484359e-02]]])

In [49]: results = model.fit(2, trend = 'c')

In [50]: results.coefs
Out[50]: 
array([[[-0.27943474,  0.67501575,  0.03321945],
        [-0.10046798,  0.26863955,  0.02573873],
        [-1.97097367,  4.41416233,  0.22547895]],

       [[ 0.00822108,  0.29045763, -0.00732091],
        [-0.12317393,  0.23249944,  0.02350376],
        [ 0.38078585,  0.80028092, -0.12407906]]])

@saketkc

saketkc commented Mar 18, 2015

Copy link
Copy Markdown
Contributor Author

@josef-pkt

Copy link
Copy Markdown
Member

My guess is that there are many places that assume that trendorder means all trends up to the specified order. I recently fixed impulse response function, irf, which also assumes it, IIRC.

to fix #2271 for now, I would raise a ValueError with an informative message in VAR, if users specify trend with missing 'c', i.e. no 't' or 'tt' is allowed.

However, given that the VAR calculations seem to work, we can open a new issue and a new PR to allow for trends that have gaps in the order. Those changes would need to be verified that they work correctly for all the different parts of the VAR analysis.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.0%) to 83.91% when pulling 259ed61 on saketkc:gh-2271 into 5dd2502 on statsmodels:master.

saketkc added a commit to saketkc/statsmodels that referenced this pull request Mar 18, 2015
@saketkc

saketkc commented Apr 20, 2015

Copy link
Copy Markdown
Contributor Author

Superseded by #2329

@saketkc saketkc closed this Apr 20, 2015
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG VAR fit with trend='t' raises exception

4 participants