From fedc715d64ae2ecfbcf9def53e53ffea3d08ec5c Mon Sep 17 00:00:00 2001 From: Natasha Date: Fri, 12 May 2017 14:11:16 +1000 Subject: [PATCH 1/4] update to include statsmodels to estimate ar1 process and remove ols import from pandas --- quantecon/estspec.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/quantecon/estspec.py b/quantecon/estspec.py index 59f11ed2e..3700f7bb9 100644 --- a/quantecon/estspec.py +++ b/quantecon/estspec.py @@ -10,7 +10,8 @@ from __future__ import division, print_function import numpy as np from numpy.fft import fft -from pandas import ols, Series +from pandas import DataFrame +import statsmodels.api as sm def smooth(x, window_len=7, window='hanning'): @@ -140,11 +141,9 @@ def ar_periodogram(x, window='hanning', window_len=7): """ # === run regression === # - x_current, x_lagged = x[1:], x[:-1] # x_t and x_{t-1} - x_current, x_lagged = Series(x_current), Series(x_lagged) # pandas series - results = ols(y=x_current, x=x_lagged, intercept=True, nw_lags=1) - e_hat = results.resid.values - phi = results.beta['x'] + results = sm.tsa.AR(x).fit(maxlag=1, cov_type='HAC', cov_kwds={'maxlags':1}) + e_hat = results.resid + phi = results.params[1] # === compute periodogram on residuals === # w, I_w = periodogram(e_hat, window=window, window_len=window_len) From e26d6a17f82b253192a32d4684d1cf1618a1d49c Mon Sep 17 00:00:00 2001 From: Natasha Date: Fri, 12 May 2017 14:16:40 +1000 Subject: [PATCH 2/4] remove pandas import which is no longer needed, statsmodels accepts arrays as data --- quantecon/estspec.py | 1 - 1 file changed, 1 deletion(-) diff --git a/quantecon/estspec.py b/quantecon/estspec.py index 3700f7bb9..ed8f65ae9 100644 --- a/quantecon/estspec.py +++ b/quantecon/estspec.py @@ -10,7 +10,6 @@ from __future__ import division, print_function import numpy as np from numpy.fft import fft -from pandas import DataFrame import statsmodels.api as sm From 3ce6e6315b3f95755f6013b6a608e518bc63797f Mon Sep 17 00:00:00 2001 From: Natasha Date: Fri, 12 May 2017 14:45:48 +1000 Subject: [PATCH 3/4] reduce amount of imports --- quantecon/estspec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantecon/estspec.py b/quantecon/estspec.py index ed8f65ae9..975c15e26 100644 --- a/quantecon/estspec.py +++ b/quantecon/estspec.py @@ -10,7 +10,7 @@ from __future__ import division, print_function import numpy as np from numpy.fft import fft -import statsmodels.api as sm +from statsmodels.api.tsa import AR def smooth(x, window_len=7, window='hanning'): @@ -140,7 +140,7 @@ def ar_periodogram(x, window='hanning', window_len=7): """ # === run regression === # - results = sm.tsa.AR(x).fit(maxlag=1, cov_type='HAC', cov_kwds={'maxlags':1}) + results = AR(x).fit(maxlag=1, cov_type='HAC', cov_kwds={'maxlags':1}) e_hat = results.resid phi = results.params[1] From 6b2321b7968f0d5be03c5db8f220d61dfb2849be Mon Sep 17 00:00:00 2001 From: Natasha Date: Fri, 12 May 2017 14:49:58 +1000 Subject: [PATCH 4/4] fix tsa import --- quantecon/estspec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantecon/estspec.py b/quantecon/estspec.py index 975c15e26..5ad129155 100644 --- a/quantecon/estspec.py +++ b/quantecon/estspec.py @@ -10,7 +10,7 @@ from __future__ import division, print_function import numpy as np from numpy.fft import fft -from statsmodels.api.tsa import AR +from statsmodels.api import tsa def smooth(x, window_len=7, window='hanning'): @@ -140,7 +140,7 @@ def ar_periodogram(x, window='hanning', window_len=7): """ # === run regression === # - results = AR(x).fit(maxlag=1, cov_type='HAC', cov_kwds={'maxlags':1}) + results = tsa.AR(x).fit(maxlag=1, cov_type='HAC', cov_kwds={'maxlags':1}) e_hat = results.resid phi = results.params[1]