Skip to content

Commit

Permalink
Merge 7512194 into e1be28e
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed Mar 23, 2014
2 parents e1be28e + 7512194 commit 90e907f
Show file tree
Hide file tree
Showing 20 changed files with 3,230 additions and 1,091 deletions.
2 changes: 2 additions & 0 deletions statsmodels/compatnp/py3k.py
Expand Up @@ -34,6 +34,7 @@ def isfileobj(f):
def open_latin1(filename, mode='r'):
return open(filename, mode=mode, encoding='iso-8859-1')
strchar = 'U'
string_types = basestring
from io import BytesIO, StringIO #statsmodels
else:
bytes = str
Expand All @@ -52,6 +53,7 @@ def open_latin1(filename, mode='r'):
return open(filename, mode=mode)
from StringIO import StringIO
BytesIO = StringIO
string_types = str

def getexception():
return sys.exc_info()[1]
Expand Down
3 changes: 2 additions & 1 deletion statsmodels/sandbox/stats/diagnostic.py
Expand Up @@ -34,7 +34,8 @@
from scipy import stats
from statsmodels.regression.linear_model import OLS
from statsmodels.tools.tools import add_constant
from statsmodels.tsa.stattools import acf, adfuller
from statsmodels.tsa.stattools import acf
from statsmodels.tsa.unitroot import adfuller
from statsmodels.tsa.tsatools import lagmat

#get the old signature back so the examples work
Expand Down
387 changes: 0 additions & 387 deletions statsmodels/tsa/adfvalues.py

This file was deleted.

70 changes: 70 additions & 0 deletions statsmodels/tsa/cointegration.py
@@ -0,0 +1,70 @@
"""
Estimation and testing of cointegrated time series
"""
from __future__ import division

import numpy as np

from statsmodels.regression.linear_model import OLS
from statsmodels.tools.tools import add_constant
from statsmodels.tsa.unitroot import mackinnonp, mackinnoncrit


def coint(y1, y2, regression="c"):
"""
This is a simple cointegration test. Uses unit-root test on residuals to
test for cointegrated relationship
See Hamilton (1994) 19.2
Parameters
----------
y1 : array_like, 1d
first element in cointegrating vector
y2 : array_like
remaining elements in cointegrating vector
c : str {'c'}
Included in regression
* 'c' : Constant
Returns
-------
coint_t : float
t-statistic of unit-root test on residuals
pvalue : float
MacKinnon's approximate p-value based on MacKinnon (1994)
crit_value : dict
Critical values for the test statistic at the 1 %, 5 %, and 10 %
levels.
Notes
-----
The Null hypothesis is that there is no cointegration, the alternative
hypothesis is that there is cointegrating relationship. If the pvalue is
small, below a critical size, then we can reject the hypothesis that there
is no cointegrating relationship.
P-values are obtained through regression surface approximation from
MacKinnon 1994.
References
----------
MacKinnon, J.G. 1994. "Approximate asymptotic distribution functions for
unit-root and cointegration tests. `Journal of Business and Economic
Statistics` 12, 167-76.
"""
regression = regression.lower()
if regression not in ['c', 'nc', 'ct', 'ctt']:
raise ValueError("regression option %s not understood") % regression
y1 = np.asarray(y1)
y2 = np.asarray(y2)
if regression == 'c':
y2 = add_constant(y2, prepend=False)
st1_resid = OLS(y1, y2).fit().resid # stage one residuals
lgresid_cons = add_constant(st1_resid[0:-1], prepend=False)
uroot_reg = OLS(st1_resid[1:], lgresid_cons).fit()
coint_t = (uroot_reg.params[0] - 1) / uroot_reg.bse[0]
pvalue = mackinnonp(coint_t, regression="c", num_unit_roots=2)
crit_value = mackinnoncrit(num_unit_roots=1, regression="c", nobs=len(y1))
return coint_t, pvalue, crit_value
1 change: 1 addition & 0 deletions statsmodels/tsa/critical_values/__init__.py
@@ -0,0 +1 @@
__author__ = 'kevin.sheppard'
34 changes: 34 additions & 0 deletions statsmodels/tsa/critical_values/dfgls.py
@@ -0,0 +1,34 @@
"""
Contains values used to approximate the critical value and
p-value from DFGLS statistics
These have been computed using the methodology of MacKinnon (1994) and (2010).
simulation.
"""

from numpy import array

dfgls_cv_approx = {'c': array([[-2.56781793e+00, -2.05575392e+01, 1.82727674e+02,
-1.77866664e+03],
[-1.94363325e+00, -2.17272746e+01, 2.60815068e+02,
-2.26914916e+03],
[-1.61998241e+00, -2.32734708e+01, 3.06474378e+02,
-2.57483557e+03]]),
'ct': array([[-3.40689134, -21.69971242, 27.26295939, -816.84404772],
[-2.84677178, -19.69109364, 84.7664136, -799.40722401],
[-2.55890707, -19.42621991, 116.53759752, -840.31342847]])}

dfgls_tau_max = {'c': 13.365361509140614,
'ct': 8.73743383728356}

dfgls_tau_min = {'c': -17.561302895074206,
'ct': -13.681153542634465}

dfgls_tau_star = {'c': -0.4795076091714674,
'ct': -2.1960404365401298}

dfgls_large_p = {'c': array([0.50612497, 0.98305664, -0.05648525, 0.00140875]),
'ct': array([2.60561421, 1.67850224, 0.0373599, -0.01017936])}

dfgls_small_p = {'c': array([0.67422739, 1.25475826, 0.03572509]),
'ct': array([2.38767685, 1.57454737, 0.05754439])}

0 comments on commit 90e907f

Please sign in to comment.