6
6
----------
7
7
Lütkepohl (2005) New Introduction to Multiple Time Series Analysis
8
8
"""
9
-
9
+ from statsmodels . compat . pandas import deprecate_kwarg
10
10
from statsmodels .compat .python import (range , lrange , string_types ,
11
11
StringIO , iteritems )
12
- from statsmodels . compat . pandas import deprecate_kwarg
12
+
13
13
from collections import defaultdict
14
14
15
15
import numpy as np
16
- import scipy .stats as stats
17
16
import scipy .linalg
17
+ import scipy .stats as stats
18
18
19
+ import statsmodels .base .wrapper as wrap
20
+ from statsmodels .tsa .base .tsa_model import (TimeSeriesModel ,
21
+ TimeSeriesResultsWrapper )
22
+ import statsmodels .tsa .tsatools as tsa
19
23
from statsmodels .iolib .table import SimpleTable
20
24
from statsmodels .tools .decorators import cache_readonly , deprecated_alias
25
+ from statsmodels .tools .linalg import logdet_symm
21
26
from statsmodels .tools .sm_exceptions import OutputWarning
22
27
from statsmodels .tools .tools import chain_dot
23
- from statsmodels .tools .linalg import logdet_symm
24
28
from statsmodels .tsa .tsatools import vec , unvec , duplication_matrix
29
+ from statsmodels .tsa .vector_ar import output , plotting , util
25
30
from statsmodels .tsa .vector_ar .hypothesis_test_results import \
26
31
CausalityTestResults , NormalityTestResults , WhitenessTestResults
27
-
28
32
from statsmodels .tsa .vector_ar .irf import IRAnalysis
29
33
from statsmodels .tsa .vector_ar .output import VARSummary
30
34
31
- import statsmodels .tsa .tsatools as tsa
32
- from statsmodels .tsa .vector_ar import output , plotting , util
33
- import statsmodels .tsa .base .tsa_model as tsbase
34
- import statsmodels .base .wrapper as wrap
35
-
36
35
37
36
# -------------------------------------------------------------------------------
38
37
# VAR process routines
@@ -495,7 +494,7 @@ def __str__(self):
495
494
# VARProcess class: for known or unknown VAR process
496
495
497
496
498
- class VAR (tsbase . TimeSeriesModel ):
497
+ class VAR (TimeSeriesModel ):
499
498
r"""
500
499
Fit VAR(p) process and do lag order selection
501
500
@@ -641,7 +640,9 @@ def fit(self, maxlags=None, method='ols', ic=None, trend='c',
641
640
self .data .xnames = (self .data .xnames [:k_trend ] +
642
641
x_names_to_add +
643
642
self .data .xnames [k_trend :])
644
-
643
+ self .data .cov_names = ['.' .join ((str (yn ), str (xn )))
644
+ for xn in self .data .xnames
645
+ for yn in self .data .ynames ]
645
646
return self ._estimate_var (lags , trend = trend )
646
647
647
648
def _estimate_var (self , lags , offset = 0 , trend = 'c' ):
@@ -1347,7 +1348,6 @@ def sigma_u_mle(self):
1347
1348
"""
1348
1349
return self .sigma_u * self .df_resid / self .nobs
1349
1350
1350
- @cache_readonly
1351
1351
def cov_params (self ):
1352
1352
"""Estimated variance-covariance of model coefficients
1353
1353
@@ -1359,20 +1359,9 @@ def cov_params(self):
1359
1359
Adjusted to be an unbiased estimator
1360
1360
Ref: Lütkepohl p.74-75
1361
1361
"""
1362
- import warnings
1363
- warnings .warn ("For consistency with other statmsodels models, "
1364
- "starting in version 0.11.0 `VARResults.cov_params` "
1365
- "will be a method instead of a property." ,
1366
- category = FutureWarning )
1367
1362
z = self .endog_lagged
1368
1363
return np .kron (scipy .linalg .inv (np .dot (z .T , z )), self .sigma_u )
1369
1364
1370
- def _cov_params (self ):
1371
- """Wrapper to avoid FutureWarning. Remove after 0.11"""
1372
- import warnings
1373
- with warnings .catch_warnings (record = True ):
1374
- return self .cov_params
1375
-
1376
1365
def cov_ybar (self ):
1377
1366
r"""Asymptotically consistent estimate of covariance of the sample mean
1378
1367
@@ -1405,7 +1394,8 @@ def _cov_alpha(self):
1405
1394
Estimated covariance matrix of model coefficients w/o exog
1406
1395
"""
1407
1396
# drop exog
1408
- return self ._cov_params ()[self .k_exog * self .neqs :, self .k_exog * self .neqs :]
1397
+ kn = self .k_exog * self .neqs
1398
+ return self .cov_params ()[kn :, kn :]
1409
1399
1410
1400
@cache_readonly
1411
1401
def _cov_sigma (self ):
@@ -1427,7 +1417,7 @@ def llf(self):
1427
1417
def stderr (self ):
1428
1418
"""Standard errors of coefficients, reshaped to match in size
1429
1419
"""
1430
- stderr = np .sqrt (np .diag (self ._cov_params ()))
1420
+ stderr = np .sqrt (np .diag (self .cov_params ()))
1431
1421
return stderr .reshape ((self .df_model , self .neqs ), order = 'C' )
1432
1422
1433
1423
bse = stderr # statsmodels interface?
@@ -1829,7 +1819,7 @@ def test_causality(self, caused, causing=None, kind='f', signif=0.05):
1829
1819
1830
1820
# Lütkepohl 3.6.5
1831
1821
Cb = np .dot (C , vec (self .params .T ))
1832
- middle = scipy .linalg .inv (chain_dot (C , self ._cov_params (), C .T ))
1822
+ middle = scipy .linalg .inv (chain_dot (C , self .cov_params (), C .T ))
1833
1823
1834
1824
# wald statistic
1835
1825
lam_wald = statistic = chain_dot (Cb , middle , Cb )
@@ -2145,12 +2135,11 @@ class VARResultsWrapper(wrap.ResultsWrapper):
2145
2135
'tvalues' : 'columns_eq' , 'sigma_u' : 'cov_eq' ,
2146
2136
'sigma_u_mle' : 'cov_eq' ,
2147
2137
'stderr' : 'columns_eq' }
2148
- _wrap_attrs = wrap .union_dicts (tsbase . TimeSeriesResultsWrapper ._wrap_attrs ,
2138
+ _wrap_attrs = wrap .union_dicts (TimeSeriesResultsWrapper ._wrap_attrs ,
2149
2139
_attrs )
2150
2140
_methods = {}
2151
- _wrap_methods = wrap .union_dicts (tsbase . TimeSeriesResultsWrapper ._wrap_methods ,
2141
+ _wrap_methods = wrap .union_dicts (TimeSeriesResultsWrapper ._wrap_methods ,
2152
2142
_methods )
2153
- _wrap_methods .pop ('cov_params' ) # not yet a method in VARResults
2154
2143
wrap .populate_wrapper (VARResultsWrapper , VARResults ) # noqa:E305
2155
2144
2156
2145
0 commit comments