# 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_ttest_ind_ol6_1(): """Compare yli.ttest_ind for Ott & Longnecker (2016) example 6.1""" df = pd.DataFrame({ 'Type': ['Fresh'] * 10 + ['Stored'] * 10, 'Potency': [10.2, 10.5, 10.3, 10.8, 9.8, 10.6, 10.7, 10.2, 10.0, 10.6, 9.8, 9.6, 10.1, 10.2, 10.1, 9.7, 9.5, 9.6, 9.8, 9.9] }) result = yli.ttest_ind(df, 'Potency', 'Type') t_expected = 0.54/(0.285*np.sqrt(1/10+1/10)) assert result.statistic == approx(t_expected, abs=0.01) assert result.dof == 18 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 = '''Type Fresh Stored Potency μ (SD) 10.37 (0.32) 9.83 (0.24) 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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
TypeFreshStored
Potency
μ (SD)10.37 (0.32)9.83 (0.24)
\n

t(18) = 4.24; p < 0.001*
Δμ (95% CI) = 0.54 (0.27–0.81), Fresh > Stored'