diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..f17f438
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,4 @@
+[run]
+command_line = -m pytest
+omit =
+ tests/*.py
diff --git a/.gitignore b/.gitignore
index 3e21f69..b2fd836 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
__pycache__
*.pyc
+/.coverage
/docs/_build
diff --git a/tests/test_anova.py b/tests/test_anova.py
index 4d188c4..6acabcf 100644
--- a/tests/test_anova.py
+++ b/tests/test_anova.py
@@ -52,3 +52,4 @@ def test_regress_ftest_ol8_2():
expected_summary = 'F(2, 21) = 29.57; p < 0.001*'
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'F(2, 21) = 29.57; p < 0.001*'
diff --git a/tests/test_bayes_factors.py b/tests/test_bayes_factors.py
index f099af1..37f727c 100644
--- a/tests/test_bayes_factors.py
+++ b/tests/test_bayes_factors.py
@@ -42,7 +42,19 @@ def test_afbf_logit_beta_zero():
assert bf.num_desc == 'Fibrinogen ≠ 0'
assert bf.denom_desc == 'Fibrinogen = 0'
+ expected_summary = '''BF10 = 1.23, Anecdotal evidence in favour of H1
+H1: Fibrinogen ≠ 0
+H0: Fibrinogen = 0'''
+ assert bf.summary() == expected_summary
+ assert bf._repr_html_() == 'BF10 = 1.23, Anecdotal evidence in favour of H1
H1: Fibrinogen ≠ 0
H0: Fibrinogen = 0'
+
bf = result.bayesfactor_beta_zero('GammaGlobulin')
assert bf.factor == approx(2.417, abs=0.001)
assert bf.num_desc == 'GammaGlobulin = 0'
assert bf.denom_desc == 'GammaGlobulin ≠ 0'
+
+ expected_summary = '''BF01 = 2.42, Anecdotal evidence in favour of H0
+H0: GammaGlobulin = 0
+H1: GammaGlobulin ≠ 0'''
+ assert bf.summary() == expected_summary
+ assert bf._repr_html_() == 'BF01 = 2.42, Anecdotal evidence in favour of H0
H0: GammaGlobulin = 0
H1: GammaGlobulin ≠ 0'
diff --git a/tests/test_chi2.py b/tests/test_chi2.py
index 579e537..d4cb894 100644
--- a/tests/test_chi2.py
+++ b/tests/test_chi2.py
@@ -78,3 +78,4 @@ OR (95% CI) = 1.33 (1.11–1.60)
RR (95% CI) = 1.11 (1.03–1.18)'''
assert result.summary() == expected_summary
+ assert result._repr_html_() == '
\n\n
\n \n \n Stress | \n False | \n True | \n
\n \n Response | \n | \n | \n
\n \n \n \n False | \n 250 | \n 400 | \n
\n \n True | \n 750 | \n 1600 | \n
\n \n
\n
χ2(1) = 9.82; p = 0.002*
OR (95% CI) = 1.33 (1.11–1.60)
RR (95% CI) = 1.11 (1.03–1.18)'
diff --git a/tests/test_correlation.py b/tests/test_correlation.py
index d3a65c0..d9fe328 100644
--- a/tests/test_correlation.py
+++ b/tests/test_correlation.py
@@ -1,5 +1,5 @@
# scipy-yli: Helpful SciPy utilities and recipes
-# Copyright © 2022 Lee Yingtong Li (RunasSudo)
+# Copyright © 2022–2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -35,6 +35,7 @@ def test_pearsonr_ol11_15():
expected_summary = 'r (95% CI) = 0.65 (0.11–0.89); p = 0.02*'
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'r (95% CI) = 0.65 (0.11–0.89); p = 0.02*'
def test_pearsonr_ol11_16():
"""Compare yli.pearsonr for Ott & Longnecker (2016) example 11.16"""
@@ -64,3 +65,4 @@ def test_spearman_ol11_17():
expected_summary = 'ρ (95% CI) = 0.87 (0.60–0.96); p < 0.001*' # NB: The confidence intervals are unvalidated
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'ρ (95% CI) = 0.87 (0.60–0.96); p < 0.001*'
diff --git a/tests/test_mannwhitney.py b/tests/test_mannwhitney.py
index 4c87e66..99c60e3 100644
--- a/tests/test_mannwhitney.py
+++ b/tests/test_mannwhitney.py
@@ -1,5 +1,5 @@
# scipy-yli: Helpful SciPy utilities and recipes
-# Copyright © 2022 Lee Yingtong Li (RunasSudo)
+# Copyright © 2022–2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -42,3 +42,4 @@ U = 6.0; p < 0.001*
r = 0.92, Before > After'''
assert result.summary() == expected_summary
+ assert result._repr_html_() == '\n\n
\n \n \n Sample | \n After | \n Before | \n
\n \n Oxygen | \n | \n | \n
\n \n \n \n Median (IQR) | \n 10.75 (10.55–10.95) | \n 11.55 (11.20–11.83) | \n
\n \n Median (range) | \n 10.75 (11.00–12.10) | \n 11.55 (11.00–12.10) | \n
\n \n
\n
U = 6.0; p < 0.001*
r = 0.92, Before > After'
diff --git a/tests/test_ordinallogit.py b/tests/test_ordinallogit.py
index 355cac0..5b4fb83 100644
--- a/tests/test_ordinallogit.py
+++ b/tests/test_ordinallogit.py
@@ -62,6 +62,7 @@ somewhat likely/very likely 4.30 (2.72 - 5.88) <0.001*
------------------------------------------------------------'''.format(result.fitted_dt)
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'Ordinal Logistic Regression ResultsDep. Variable: | apply | No. Observations: | 400 |
---|
Model: | Ordinal Logit | Df. Model: | 5 |
---|
Date: | {0:%Y-%m-%d} | Df. Residuals: | 395 |
---|
Time: | {0:%H:%M:%S} | Pseudo R2: | 0.03 |
---|
Std. Errors: | Non-Robust | LL-Model: | -358.51 |
---|
| | LL-Null: | -370.60 |
---|
| | p (LR): | <0.001* |
---|
| β | (95% CI) | p |
---|
pared | 1.05 | (0.53 | – | 1.57) | <0.001* |
---|
public | -0.06 | (-0.64 | – | 0.53) | =0.84 |
---|
gpa | 0.62 | (0.10 | – | 1.13) | =0.02* |
---|
(Cutoffs) | | | | | |
---|
unlikely/somewhat likely | 2.20 | (0.68 | – | 3.73) | =0.005* |
somewhat likely/very likely | 4.30 | (2.72 | – | 5.88) | <0.001* |
'.format(result.fitted_dt)
def test_brant_ucla():
"""Compare RegressionModel.brant with R brant library for UCLA example at https://stats.oarc.ucla.edu/r/dae/ordinal-logistic-regression/"""
@@ -97,3 +98,4 @@ public 3.44 1 0.06
gpa 0.18 1 0.67 '''
assert brant_result.summary() == expected_summary
+ assert brant_result._repr_html_() == 'Brant Test Results | χ2 | df | p |
---|
Omnibus | 4.34 | 3 | =0.23 |
---|
pared | 0.13 | 1 | =0.72 |
---|
public | 3.44 | 1 | =0.06 |
---|
gpa | 0.18 | 1 | =0.67 |
---|
'
diff --git a/tests/test_regress.py b/tests/test_regress.py
index a9777bf..8f5200c 100644
--- a/tests/test_regress.py
+++ b/tests/test_regress.py
@@ -63,6 +63,7 @@ Dep. Variable: GrowthRet | No. Observations: 20
----------------------------------------------'''.format(result.fitted_dt)
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'Ordinary Least Squares Regression ResultsDep. Variable: | GrowthRet | No. Observations: | 20 |
---|
Model: | OLS | Df. Model: | 1 |
---|
Date: | {0:%Y-%m-%d} | Df. Residuals: | 18 |
---|
Time: | {0:%H:%M:%S} | R2: | 0.74 |
---|
Std. Errors: | Non-Robust | F: | 52.01 |
---|
| | p (F): | <0.001* |
---|
| β | (95% CI) | p |
---|
(Intercept) | 47.48 | (38.17 | – | 56.78) | <0.001* |
---|
SoilPh | -7.86 | (-10.15 | – | -5.57) | <0.001* |
---|
'.format(result.fitted_dt)
@pytest.mark.skip('Not implemented in refactored regression implementation')
def test_regress_bootstrap_ols_ol11_4():
@@ -184,6 +185,7 @@ GammaGlobulin 1.17 (0.92 - 1.48) 0.19
-----------------------------------------------'''.format(result.fitted_dt)
assert result.summary() == expected_summary
+ assert result._repr_html_() == 'Logistic Regression ResultsDep. Variable: | Unhealthy | No. Observations: | 32 |
---|
Model: | Logit | Df. Model: | 2 |
---|
Date: | {0:%Y-%m-%d} | Df. Residuals: | 29 |
---|
Time: | {0:%H:%M:%S} | Pseudo R2: | 0.26 |
---|
Std. Errors: | Non-Robust | LL-Model: | -11.47 |
---|
| | 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)
def test_regress_logit_ol10_18():
"""Compare odds ratios via yli.regress for Ott & Longnecker (2016) example 10.18"""
@@ -251,5 +253,4 @@ Dep. Variable: Outcome | No. Observations: 240
---------------------------------------------'''.format(result.fitted_dt)
assert result.summary() == expected_summary
-
-# TODO: Test for logit_then_regress
+ assert result._repr_html_() == 'Penalised Logistic Regression ResultsDep. Variable: | Outcome | No. Observations: | 240 |
---|
Model: | Penalised Logit | Df. Model: | 1 |
---|
Date: | {0:%Y-%m-%d} | Pseudo R2: | 0.37 |
---|
Time: | {0:%H:%M:%S} | LL-Model: | -66.43 |
---|
Std. Errors: | Non-Robust | LL-Null: | -105.91 |
---|
| | 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)
diff --git a/tests/test_ttest.py b/tests/test_ttest.py
index 81f0f59..2c44e27 100644
--- a/tests/test_ttest.py
+++ b/tests/test_ttest.py
@@ -1,5 +1,5 @@
# scipy-yli: Helpful SciPy utilities and recipes
-# Copyright © 2022 Lee Yingtong Li (RunasSudo)
+# Copyright © 2022–2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -47,3 +47,4 @@ t(18) = 4.24; p < 0.001*
Δμ (95% CI) = 0.54 (0.27–0.81), Fresh > Stored'''
assert result.summary() == expected_summary
+ assert result._repr_html_() == '\n\n
\n \n \n Type | \n Fresh | \n Stored | \n
\n \n Potency | \n | \n | \n
\n \n \n \n μ (SD) | \n 10.37 (0.32) | \n 9.83 (0.24) | \n
\n \n
\n
t(18) = 4.24; p < 0.001*
Δμ (95% CI) = 0.54 (0.27–0.81), Fresh > Stored'