Skip to content

Commit

Permalink
Merge pull request #1031 from josef-pkt/bug_lowess_oth_maint
Browse files Browse the repository at this point in the history
BUG: Fix lowess returns and Breusch Godfrey undefined variable.
  • Loading branch information
jseabold committed Aug 14, 2013
2 parents f67b488 + 35aa4da commit fa4d6dd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion statsmodels/nonparametric/smoothers_lowess.py
Expand Up @@ -165,7 +165,7 @@ def lowess(endog, exog, frac=2.0/3.0, it=3, delta=0.0, is_sorted=False,
res = _lowess(y, x, frac=frac, it=it, delta=delta)
_, yfitted = res.T

if return_sorted or (all_valid and is_sorted):
if return_sorted:
return res
else:
# rebuild yfitted with original indices
Expand All @@ -175,6 +175,8 @@ def lowess(endog, exog, frac=2.0/3.0, it=3, delta=0.0, is_sorted=False,
yfitted_.fill(np.nan)
yfitted_[sort_index] = yfitted
yfitted = yfitted_
else:
yfitted = yfitted

if not all_valid:
yfitted_ = np.empty_like(endog)
Expand Down
5 changes: 5 additions & 0 deletions statsmodels/nonparametric/tests/test_lowess.py
Expand Up @@ -112,6 +112,11 @@ def test_options(self):
actual_lowess = lowess(y[::-1], x[::-1], return_sorted=False)
assert_almost_equal(actual_lowess, actual_lowess1[::-1, 1], decimal=13)

# check returns yfitted only
actual_lowess = lowess(y, x, return_sorted=False, missing='none',
is_sorted=True)
assert_almost_equal(actual_lowess, actual_lowess1[:, 1], decimal=13)

# check integer input
actual_lowess = lowess(np.round(y).astype(int), x, is_sorted=True)
actual_lowess1 = lowess(np.round(y), x, is_sorted=True)
Expand Down
6 changes: 3 additions & 3 deletions statsmodels/sandbox/stats/diagnostic.py
Expand Up @@ -490,14 +490,14 @@ def acorr_breush_godfrey(results, nlags=None, store=False):
'''

x = np.concatenate((np.zeros(nlags), results.resid))
x = np.asarray(results.resid)
exog_old = results.model.exog
x = np.asarray(x)
nobs = x.shape[0]
if nlags is None:
#for adf from Greene referencing Schwert 1989
nlags = 12. * np.power(nobs/100., 1/4.)#nobs//4 #TODO: check default, or do AIC/BIC
nlags = np.trunc(12. * np.power(nobs/100., 1/4.))#nobs//4 #TODO: check default, or do AIC/BIC

x = np.concatenate((np.zeros(nlags), x))

#xdiff = np.diff(x)
#
Expand Down
5 changes: 5 additions & 0 deletions statsmodels/stats/tests/test_diagnostic.py
Expand Up @@ -294,6 +294,11 @@ def test_acorr_breush_godfrey(self):
breushgodfrey_f['statistic'], breushgodfrey_f['pvalue']]
assert_almost_equal(bg, bg_r, decimal=13)

# check that lag choice works
bg2 = smsdia.acorr_breush_godfrey(res, nlags=None)
bg3 = smsdia.acorr_breush_godfrey(res, nlags=14)
assert_almost_equal(bg2, bg3, decimal=13)

def test_acorr_ljung_box(self):
res = self.res

Expand Down

0 comments on commit fa4d6dd

Please sign in to comment.