Add expected summary output to unit tests for examples in documentation
This commit is contained in:
parent
d5ce46f6d0
commit
66d7e70806
@ -50,3 +50,6 @@ def test_regress_ftest_ol8_2():
|
||||
assert result.dof1 == 2
|
||||
assert result.dof2 == 21
|
||||
assert result.pvalue < 0.001
|
||||
|
||||
expected_summary = 'F(2, 21) = 29.57; p < 0.001*'
|
||||
assert result.summary() == expected_summary
|
||||
|
@ -67,3 +67,14 @@ def test_chi2_ol10_18():
|
||||
assert result.oddsratio.point == approx(1.333, abs=0.001)
|
||||
assert result.oddsratio.ci_lower == approx(1.113, abs=0.001)
|
||||
assert result.oddsratio.ci_upper == approx(1.596, abs=0.001)
|
||||
|
||||
expected_summary = '''Stress False True
|
||||
Response
|
||||
False 250 400
|
||||
True 750 1600
|
||||
|
||||
χ²(1) = 9.82; p = 0.002*
|
||||
OR (95% CI) = 1.33 (1.11–1.60)
|
||||
RR (95% CI) = 1.11 (1.03–1.18)'''
|
||||
|
||||
assert result.summary() == expected_summary
|
||||
|
@ -32,3 +32,8 @@ def test_mannwhitney_ol6_6():
|
||||
result = yli.mannwhitney(df, 'Oxygen', 'Sample', method='asymptotic', alternative='less')
|
||||
|
||||
assert result.pvalue == approx(0.00007, abs=0.00001)
|
||||
|
||||
expected_summary = '''U = 6.0; p < 0.001*
|
||||
r = 0.92, Before > After'''
|
||||
|
||||
assert result.summary() == expected_summary
|
||||
|
@ -113,15 +113,38 @@ def test_regress_logit_ol12_23():
|
||||
assert lrtest_result.dof == 2
|
||||
assert lrtest_result.pvalue == approx(0.0191, rel=0.02)
|
||||
|
||||
# Can't validate intercept as very negative
|
||||
|
||||
expbeta_fib = np.exp(result.terms['Fibrinogen'].beta)
|
||||
assert expbeta_fib.point == approx(6.756, rel=0.01)
|
||||
assert expbeta_fib.ci_lower == approx(1.007, rel=0.01)
|
||||
assert expbeta_fib.ci_upper == approx(45.308, rel=0.02)
|
||||
assert result.terms['Fibrinogen'].pvalue == approx(0.0491, rel=0.01)
|
||||
|
||||
expbeta_gam = np.exp(result.terms['GammaGlobulin'].beta)
|
||||
assert expbeta_gam.point == approx(1.169, abs=0.001)
|
||||
assert expbeta_gam.ci_lower == approx(0.924, abs=0.001)
|
||||
assert expbeta_gam.ci_upper == approx(1.477, abs=0.001)
|
||||
assert result.terms['GammaGlobulin'].pvalue == approx(0.1925, rel=0.01)
|
||||
|
||||
expected_summary = ''' Logistic Regression Results
|
||||
======================================================
|
||||
Dep. Variable: Unhealthy | No. Observations: 32
|
||||
Model: Logit | Df. Model: 2
|
||||
Method: MLE | Df. Residuals: 29
|
||||
Date: {0:%Y-%m-%d} | Pseudo R²: 0.26
|
||||
Time: {0:%H:%M:%S} | LL-Model: -11.47
|
||||
Std. Errors: Non-Robust | LL-Null: -15.44
|
||||
| p (LR): 0.02*
|
||||
======================================================
|
||||
exp(β) (95% CI) p
|
||||
-----------------------------------------------
|
||||
(Intercept) 0.00 (0.00 - 0.24) 0.03*
|
||||
Fibrinogen 6.80 (1.01 - 45.79) 0.049*
|
||||
GammaGlobulin 1.17 (0.92 - 1.48) 0.19
|
||||
-----------------------------------------------'''.format(result.fitted_dt)
|
||||
|
||||
assert result.summary() == expected_summary
|
||||
|
||||
def test_regress_logit_ol10_18():
|
||||
"""Compare odds ratios via yli.regress for Ott & Longnecker (2016) example 10.18"""
|
||||
@ -172,3 +195,22 @@ def test_regress_penalisedlogit_kleinman():
|
||||
assert lrtest_result.statistic == approx(78.95473)
|
||||
assert lrtest_result.dof == 1
|
||||
assert lrtest_result.pvalue < 0.0001
|
||||
|
||||
expected_summary = ''' Penalised Logistic Regression Results
|
||||
=========================================================
|
||||
Dep. Variable: Outcome | No. Observations: 240
|
||||
Model: Logit | Df. Model: 1
|
||||
Method: Penalised ML | Pseudo R²: 0.37
|
||||
Date: {0:%Y-%m-%d} | LL-Model: -66.43
|
||||
Time: {0:%H:%M:%S} | LL-Null: -105.91
|
||||
Std. Errors: Non-Robust | p (LR): <0.001*
|
||||
=========================================================
|
||||
β (95% CI) p
|
||||
---------------------------------------------
|
||||
(Intercept) -2.28 (-2.77 - -1.85) <0.001*
|
||||
Pred 5.99 (3.95 - 10.85) <0.001*
|
||||
---------------------------------------------'''.format(result.fitted_dt)
|
||||
|
||||
assert result.summary() == expected_summary
|
||||
|
||||
# TODO: Test for logit_then_regress
|
||||
|
@ -38,3 +38,8 @@ def test_ttest_ind_ol6_1():
|
||||
assert result.delta.point == approx(0.54, abs=0.01)
|
||||
assert result.delta.ci_lower == approx(0.272, abs=0.01)
|
||||
assert result.delta.ci_upper == approx(0.808, abs=0.01)
|
||||
|
||||
expected_summary = '''t(18) = 4.24; p < 0.001*
|
||||
Δμ (95% CI) = 0.54 (0.27–0.81), Fresh > Stored'''
|
||||
|
||||
assert result.summary() == expected_summary
|
||||
|
Loading…
Reference in New Issue
Block a user