Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions statsmodels/regression/tests/test_glsar_gretl.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ def test_all(self):
normality = [23.962, 0.00001, 2, "chi2"]

het_white = [33.503723, 0.000003, 5, "chi2"]
het_breush_pagan = [1.302014, 0.521520, 2, "chi2"] #TODO: not available
het_breush_pagan_konker = [0.709924, 0.701200, 2, "chi2"]
het_breusch_pagan = [1.302014, 0.521520, 2, "chi2"] #TODO: not available
het_breusch_pagan_konker = [0.709924, 0.701200, 2, "chi2"]


reset_2_3 = [5.219019, 0.00619, 2, 197, "f"]
Expand Down Expand Up @@ -381,9 +381,9 @@ def test_all(self):
assert_almost_equal(linear_sq[0], linear_squares[0], decimal=6)
assert_almost_equal(linear_sq[1], linear_squares[1], decimal=7)

hbpk = smsdia.het_breushpagan(res.resid, res.model.exog)
assert_almost_equal(hbpk[0], het_breush_pagan_konker[0], decimal=6)
assert_almost_equal(hbpk[1], het_breush_pagan_konker[1], decimal=6)
hbpk = smsdia.het_breuschpagan(res.resid, res.model.exog)
assert_almost_equal(hbpk[0], het_breusch_pagan_konker[0], decimal=6)
assert_almost_equal(hbpk[1], het_breusch_pagan_konker[1], decimal=6)

hw = smsdia.het_white(res.resid, res.model.exog)
assert_almost_equal(hw[:2], het_white[:2], 6)
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/sandbox/regression/gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05):
condno = np.sqrt(eigvals[-1]/eigvals[0])

# TODO: check what is valid.
# box-pierce, breush-pagan, durbin's h are not with endogenous on rhs
# box-pierce, breusch-pagan, durbin's h are not with endogenous on rhs
# use Cumby Huizinga 1992 instead
self.diagn = dict(jb=jb, jbpv=jbpv, skew=skew, kurtosis=kurtosis,
omni=omni, omnipv=omnipv, condno=condno,
Expand Down
29 changes: 20 additions & 9 deletions statsmodels/sandbox/stats/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def acorr_lm(x, maxlag=None, autolag='AIC', store=False, regresults=False):
This is a generic Lagrange Multiplier test for autocorrelation. I don't
have a reference for it, but it returns Engle's ARCH test if x is the
squared residual array. A variation on it with additional exogenous
variables is the Breush-Godfrey autocorrelation test.
variables is the Breusch-Godfrey autocorrelation test.

Parameters
----------
Expand Down Expand Up @@ -340,7 +340,7 @@ def acorr_lm(x, maxlag=None, autolag='AIC', store=False, regresults=False):
See Also
--------
het_arch
acorr_breush_godfrey
acorr_breusch_godfrey
acorr_ljung_box

'''
Expand Down Expand Up @@ -450,8 +450,8 @@ def het_arch(resid, maxlag=None, autolag=None, store=False, regresults=False,
regresults=regresults)


def acorr_breush_godfrey(results, nlags=None, store=False):
'''Breush Godfrey Lagrange Multiplier tests for residual autocorrelation
def acorr_breusch_godfrey(results, nlags=None, store=False):
'''Breusch Godfrey Lagrange Multiplier tests for residual autocorrelation

Parameters
----------
Expand Down Expand Up @@ -498,6 +498,7 @@ def acorr_breush_godfrey(results, nlags=None, store=False):
if nlags is None:
#for adf from Greene referencing Schwert 1989
nlags = np.trunc(12. * np.power(nobs/100., 1/4.))#nobs//4 #TODO: check default, or do AIC/BIC
nlags = int(nlags)

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

Expand Down Expand Up @@ -530,8 +531,14 @@ def acorr_breush_godfrey(results, nlags=None, store=False):
else:
return lm, lmpval, fval, fpval

def het_breushpagan(resid, exog_het):
'''Breush-Pagan Lagrange Multiplier test for heteroscedasticity
acorr_breush_godfrey = np.deprecate(acorr_breusch_godfrey, 'acorr_breush_godfrey',
'acorr_breusch_godfrey',
"Use acorr_breusch_godfrey, acorr_breush_godfrey will be "
"removed in 0.9 \n(Note: misspelling missing 'c')")


def het_breuschpagan(resid, exog_het):
'''Breusch-Pagan Lagrange Multiplier test for heteroscedasticity

The tests the hypothesis that the residual variance does not depend on
the variables in x in the form
Expand All @@ -544,7 +551,7 @@ def het_breushpagan(resid, exog_het):
Parameters
----------
resid : arraylike, (nobs,)
For the Breush-Pagan test, this should be the residual of a regression.
For the Breusch-Pagan test, this should be the residual of a regression.
If an array is given in exog, then the residuals are calculated by
the an OLS regression or resid on exog. In this case resid should
contain the dependent variable. Exog can be the same as x.
Expand Down Expand Up @@ -587,7 +594,7 @@ def het_breushpagan(resid, exog_het):
----------
http://en.wikipedia.org/wiki/Breusch%E2%80%93Pagan_test
Greene 5th edition
Breush, Pagan article
Breusch, Pagan article

'''

Expand All @@ -601,6 +608,10 @@ def het_breushpagan(resid, exog_het):
# Note: degrees of freedom for LM test is nvars minus constant
return lm, stats.chi2.sf(lm, nvars-1), fval, fpval

het_breushpagan = np.deprecate(het_breuschpagan, 'het_breushpagan', 'het_breuschpagan',
"Use het_breuschpagan, het_breushpagan will be "
"removed in 0.9 \n(Note: misspelling missing 'c')")

def het_white(resid, exog, retres=False):
'''White's Lagrange Multiplier Test for Heteroscedasticity

Expand Down Expand Up @@ -1591,7 +1602,7 @@ def lb4(x):
y = x.sum(1) + 1.01*(1-0.5*(x[:,1]>10))*np.random.rand(nobs)
print(het_goldfeldquandt(y,x, 1))

print(het_breushpagan(y,x))
print(het_breuschpagan(y,x))
print(het_white(y,x))

f, fp, fo = het_goldfeldquandt(y,x, 1)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_lilliefors_table():

return lf

lillifors_table = get_lilliefors_table()
lilliefors_table = get_lilliefors_table()

def pval_lf(Dmax, n):
'''approximate pvalues for Lilliefors test of normality
Expand Down Expand Up @@ -179,7 +179,7 @@ def pval_lf(Dmax, n):


def kstest_normal(x, pvalmethod='approx'):
'''Lillifors test for normality,
'''lilliefors test for normality,

Kolmogorov Smirnov test with estimated mean and variance

Expand Down Expand Up @@ -225,12 +225,16 @@ def kstest_normal(x, pvalmethod='approx'):
pval = pval_lf(d_ks, nobs)
elif pvalmethod == 'table':
#pval = pval_lftable(d_ks, nobs)
pval = lillifors_table.prob(d_ks, nobs)
pval = lilliefors_table.prob(d_ks, nobs)

return d_ks, pval


lillifors = kstest_normal
lilliefors = kstest_normal

lillifors = np.deprecate(lilliefors, 'lillifors', 'lilliefors',
"Use lilliefors, lillifors will be "
"removed in 0.9 \n(Note: misspelling missing 'e')")


#old version:
Expand Down
8 changes: 5 additions & 3 deletions statsmodels/stats/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# pylint: disable=W0611
from . import diagnostic
from .diagnostic import (
acorr_ljungbox, acorr_breush_godfrey,
acorr_ljungbox, acorr_breusch_godfrey,
CompareCox, compare_cox, CompareJ, compare_j,
HetGoldfeldQuandt, het_goldfeldquandt,
het_breushpagan, het_white, het_arch,
het_breuschpagan, het_white, het_arch,
linear_harvey_collier, linear_rainbow, linear_lm,
breaks_cusumolsresid, breaks_hansen, recursive_olsresiduals,
unitroot_adf,
normal_ad, lillifors
normal_ad, lilliefors,
# deprecated because of misspelling:
lillifors, het_breushpagan, acorr_breush_godfrey
)

from . import multicomp
Expand Down
12 changes: 7 additions & 5 deletions statsmodels/stats/diagnostic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#collect some imports of verified (at least one example) functions
from statsmodels.sandbox.stats.diagnostic import (
acorr_ljungbox, breaks_cusumolsresid, breaks_hansen, CompareCox, CompareJ,
compare_cox, compare_j, het_breushpagan, HetGoldfeldQuandt,
compare_cox, compare_j, het_breuschpagan, HetGoldfeldQuandt,
het_goldfeldquandt, het_arch,
het_white, recursive_olsresiduals, acorr_breush_godfrey,
het_white, recursive_olsresiduals, acorr_breusch_godfrey,
linear_harvey_collier, linear_rainbow, linear_lm,
unitroot_adf)
unitroot_adf,
het_breushpagan, acorr_breush_godfrey # deprecated because of misspelling
)

from .lilliefors import kstest_normal, lillifors
from .adnorm import normal_ad
from ._lilliefors import kstest_normal, lilliefors, lillifors # lillifors is deprecated
from ._adnorm import normal_ad
56 changes: 30 additions & 26 deletions statsmodels/stats/tests/test_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
currently all tests are against R

"""
#import warnings
#warnings.simplefilter("default")
# ResourceWarning doesn't exist in python 2
#warnings.simplefilter("ignore", ResourceWarning)
import os

import numpy as np
Expand Down Expand Up @@ -219,13 +223,13 @@ def test_het_goldfeldquandt(self):
assert_equal(gq[-1], 'two-sided')
#TODO other options ???

def test_het_breush_pagan(self):
def test_het_breusch_pagan(self):
res = self.res

bptest = dict(statistic=0.709924388395087, pvalue=0.701199952134347,
parameters=(2,), distr='f')

bp = smsdia.het_breushpagan(res.resid, res.model.exog)
bp = smsdia.het_breuschpagan(res.resid, res.model.exog)
compare_t_est(bp, bptest, decimal=(12, 12))


Expand Down Expand Up @@ -277,28 +281,28 @@ def test_het_arch2(self):
res3 = smsdia.het_arch(resid, maxlag=1, autolag='aic')
assert_almost_equal(res3[:4], res1[:4], decimal=13)

def test_acorr_breush_godfrey(self):
def test_acorr_breusch_godfrey(self):
res = self.res

#bgf = bgtest(fm, order = 4, type="F")
breushgodfrey_f = dict(statistic=1.179280833676792,
breuschgodfrey_f = dict(statistic=1.179280833676792,
pvalue=0.321197487261203,
parameters=(4,195,), distr='f')

#> bgc = bgtest(fm, order = 4, type="Chisq")
#> mkhtest(bgc, "breushpagan_c", "chi2")
breushgodfrey_c = dict(statistic=4.771042651230007,
#> mkhtest(bgc, "breuschpagan_c", "chi2")
breuschgodfrey_c = dict(statistic=4.771042651230007,
pvalue=0.3116067133066697,
parameters=(4,), distr='chi2')

bg = smsdia.acorr_breush_godfrey(res, nlags=4)
bg_r = [breushgodfrey_c['statistic'], breushgodfrey_c['pvalue'],
breushgodfrey_f['statistic'], breushgodfrey_f['pvalue']]
bg = smsdia.acorr_breusch_godfrey(res, nlags=4)
bg_r = [breuschgodfrey_c['statistic'], breuschgodfrey_c['pvalue'],
breuschgodfrey_f['statistic'], breuschgodfrey_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)
bg2 = smsdia.acorr_breusch_godfrey(res, nlags=None)
bg3 = smsdia.acorr_breusch_godfrey(res, nlags=14)
assert_almost_equal(bg2, bg3, decimal=13)

def test_acorr_ljung_box(self):
Expand Down Expand Up @@ -537,29 +541,29 @@ def test_normality(self):

#> library(nortest) #Lilliefors (Kolmogorov-Smirnov) normality test
#> lt = lillie.test(residuals(fm))
#> mkhtest(lt, "lillifors", "-")
lillifors1 = dict(statistic=0.0723390908786589,
#> mkhtest(lt, "lilliefors", "-")
lilliefors1 = dict(statistic=0.0723390908786589,
pvalue=0.01204113540102896, parameters=(), distr='-')

#> lt = lillie.test(residuals(fm)**2)
#> mkhtest(lt, "lillifors", "-")
lillifors2 = dict(statistic=0.301311621898024,
#> mkhtest(lt, "lilliefors", "-")
lilliefors2 = dict(statistic=0.301311621898024,
pvalue=1.004305736618051e-51,
parameters=(), distr='-')

#> lt = lillie.test(residuals(fm)[1:20])
#> mkhtest(lt, "lillifors", "-")
lillifors3 = dict(statistic=0.1333956004203103,
#> mkhtest(lt, "lilliefors", "-")
lilliefors3 = dict(statistic=0.1333956004203103,
pvalue=0.4618672180799566, parameters=(), distr='-')

lf1 = smsdia.lillifors(res.resid)
lf2 = smsdia.lillifors(res.resid**2)
lf3 = smsdia.lillifors(res.resid[:20])
lf1 = smsdia.lilliefors(res.resid)
lf2 = smsdia.lilliefors(res.resid**2)
lf3 = smsdia.lilliefors(res.resid[:20])

compare_t_est(lf1, lillifors1, decimal=(14, 14))
compare_t_est(lf2, lillifors2, decimal=(14, 14)) #pvalue very small
assert_approx_equal(lf2[1], lillifors2['pvalue'], significant=10)
compare_t_est(lf3, lillifors3, decimal=(14, 1))
compare_t_est(lf1, lilliefors1, decimal=(14, 14))
compare_t_est(lf2, lilliefors2, decimal=(14, 14)) #pvalue very small
assert_approx_equal(lf2[1], lilliefors2['pvalue'], significant=10)
compare_t_est(lf3, lilliefors3, decimal=(14, 1))
#R uses different approximation for pvalue in last case

#> ad = ad.test(residuals(fm))
Expand Down Expand Up @@ -874,10 +878,10 @@ def test_outlier_test():
#t = TestDiagnosticG()
#t.test_basic()
#t.test_hac()
#t.test_acorr_breush_godfrey()
#t.test_acorr_breusch_godfrey()
#t.test_acorr_ljung_box()
#t.test_het_goldfeldquandt()
#t.test_het_breush_pagan()
#t.test_het_breusch_pagan()
#t.test_het_white()
#t.test_compare_lr()
#t.test_compare_nonnested()
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/stats/tests/test_statstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from statsmodels.stats.stattools import (omni_normtest, jarque_bera,
durbin_watson, _medcouple_1d, medcouple,
robust_kurtosis, robust_skewness)
from statsmodels.stats.adnorm import normal_ad
from statsmodels.stats._adnorm import normal_ad

#a random array, rounded to 4 decimals
x = np.array([-0.1184, -1.3403, 0.0063, -0.612, -0.3869, -0.2313, -2.8485,
Expand Down