Skip to content

Commit

Permalink
Merge commit 'e417dc0fe26d5e87509678b680f5671eef613e1a' into backport…
Browse files Browse the repository at this point in the history
…-0.14.1
  • Loading branch information
bashtage committed Dec 14, 2023
2 parents 44c1020 + e417dc0 commit a78a176
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ filterwarnings =
error:The previous implementation of stack is deprecated:FutureWarning
error:Series.__setitem__ treating keys as positions is deprecated:FutureWarning
error:The provided callable:FutureWarning
error:divide by zero encountered in log1p:RuntimeWarning
markers =
example: mark a test that runs example code
matplotlib: mark a test that requires matplotlib
Expand Down
10 changes: 8 additions & 2 deletions statsmodels/stats/_adnorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Author: Josef Perktold and Scipy developers
License : BSD-3
"""
import warnings

import numpy as np
from scipy import stats

Expand Down Expand Up @@ -64,8 +66,12 @@ def anderson_statistic(x, dist='norm', fit=True, params=(), axis=0):
sl2 = [slice(None)] * x.ndim
sl2[axis] = slice(None, None, -1)
sl2 = tuple(sl2)
s = np.sum((2 * i[sl1] - 1.0) / nobs * (np.log(z) + np.log1p(-z[sl2])),
axis=axis)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message="divide by zero encountered in log1p"
)
ad_values = (2 * i[sl1] - 1.0) / nobs * (np.log(z) + np.log1p(-z[sl2]))
s = np.sum(ad_values, axis=axis)
a2 = -nobs - s
return a2

Expand Down
4 changes: 2 additions & 2 deletions statsmodels/stats/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def linear_reset(res, power=3, test_type="fitted", use_f=False,
raise ValueError("power must contains distinct integers all >= 2")
exog = res.model.exog
if test_type == "fitted":
aug = res.fittedvalues[:, None]
aug = np.asarray(res.fittedvalues)[:, None]
elif test_type == "exog":
# Remove constant and binary
aug = res.model.exog
Expand Down Expand Up @@ -1293,7 +1293,7 @@ def linear_lm(resid, exog, func=None):
if func is None:
def func(x):
return np.power(x, 2)

exog = np.asarray(exog)
exog_aux = np.column_stack((exog, func(exog[:, 1:])))

nobs, k_vars = exog.shape
Expand Down
40 changes: 40 additions & 0 deletions statsmodels/stats/tests/test_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,3 +1957,43 @@ def test_small_skip(reset_randomstate):
# M2 + fit(M1)-exp(fit(M2)) < 2.22e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

@pytest.mark.smoke
def test_diagnostics_pandas(reset_randomstate):
# GH 8879
n = 100
df = pd.DataFrame(
{
"y": np.random.rand(n),
"x": np.random.rand(n),
"z": np.random.rand(n)}
)
y, x = df["y"], add_constant(df["x"])

res = OLS(df["y"], add_constant(df[["x"]])).fit()
res_large = OLS(df["y"], add_constant(df[["x", "z"]])).fit()
res_other = OLS(df["y"], add_constant(df[["z"]])).fit()
smsdia.linear_reset(res_large)
smsdia.linear_reset(res_large, test_type="fitted")
smsdia.linear_reset(res_large, test_type="exog")
smsdia.linear_reset(res_large, test_type="princomp")
smsdia.het_goldfeldquandt(y, x)
smsdia.het_breuschpagan(res.resid, x)
smsdia.het_white(res.resid, x)
smsdia.het_arch(res.resid)
smsdia.acorr_breusch_godfrey(res)
smsdia.acorr_ljungbox(y)
smsdia.linear_rainbow(res)
smsdia.linear_lm(res.resid, x)
smsdia.linear_harvey_collier(res)
smsdia.acorr_lm(res.resid)
smsdia.breaks_cusumolsresid(res.resid)
smsdia.breaks_hansen(res)
smsdia.compare_cox(res, res_other)
smsdia.compare_encompassing(res, res_other)
smsdia.compare_j(res, res_other)
smsdia.recursive_olsresiduals(res)
smsdia.recursive_olsresiduals(
res, order_by=np.arange(y.shape[0] - 1, 0 - 1, -1)
)
smsdia.spec_white(res.resid, x)

0 comments on commit a78a176

Please sign in to comment.