scipy-yli/tests/test_ttest.py

47 lines
1.7 KiB
Python
Raw Normal View History

2022-10-13 12:53:18 +11:00
# scipy-yli: Helpful SciPy utilities and recipes
# Copyright © 2022 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 <https://www.gnu.org/licenses/>.
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 = '''t(18) = 4.24; p < 0.001*
2022-11-09 17:01:45 +11:00
μ(Fresh) (SD) = 10.37 (0.32), μ(Stored) (SD) = 9.83 (0.24)
Δμ (95% CI) = 0.54 (0.270.81), Fresh > Stored'''
assert result.summary() == expected_summary