# scipy-yli: Helpful SciPy utilities and recipes # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from pytest import approx import numpy as np import pandas as pd import yli def test_mannwhitney_ol6_6(): """Compare yli.mannwhitney for Ott & Longnecker (2016) example 6.6""" df = pd.DataFrame({ 'Sample': ['Before'] * 12 + ['After'] * 12, 'Oxygen': [11.0, 11.2, 11.2, 11.2, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9, 11.9, 12.1, 10.2, 10.3, 10.4, 10.6, 10.6, 10.7, 10.8, 10.8, 10.9, 11.1, 11.1, 11.3] }) result = yli.mannwhitney(df, 'Oxygen', 'Sample', method='asymptotic', alternative='less') assert result.pvalue == approx(0.00007, abs=0.00001) expected_summary = '''Sample After Before Oxygen Median (IQR) 10.75 (10.55–10.95) 11.55 (11.20–11.83) Median (range) 10.75 (11.00–12.10) 11.55 (11.00–12.10) 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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
SampleAfterBefore
Oxygen
Median (IQR)10.75 (10.55–10.95)11.55 (11.20–11.83)
Median (range)10.75 (11.00–12.10)11.55 (11.00–12.10)
\n

U = 6.0; p < 0.001*
r = 0.92, Before > After'