# 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 pandas as pd import yli def test_anova_oneway_ol8_2(): """Compare yli.anova_oneway for Ott & Longnecker (2016) example 8.2""" df = pd.DataFrame({ 'Method': [1]*8 + [2]*7 + [3]*9, 'Score': [96, 79, 91, 85, 83, 91, 82, 87, 77, 76, 74, 73, 78, 71, 80, 66, 73, 69, 66, 77, 73, 71, 70, 74] }) result = yli.anova_oneway(df, 'Score', 'Method') assert result.statistic == approx(545.316/18.4366, rel=0.001) assert result.dof1 == 2 assert result.dof2 == 21 assert result.pvalue < 0.001 def test_regress_ftest_ol8_2(): """Compare ANOVA via yli.regress for Ott & Longnecker (2016) example 8.2""" df = pd.DataFrame({ 'Method': [1]*8 + [2]*7 + [3]*9, 'Score': [96, 79, 91, 85, 83, 91, 82, 87, 77, 76, 74, 73, 78, 71, 80, 66, 73, 69, 66, 77, 73, 71, 70, 74] }) result = yli.regress(yli.OLS, df, 'Score', 'C(Method)').ftest() assert result.statistic == approx(545.316/18.4366, rel=0.001) 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 assert result._repr_html_() == 'F(2, 21) = 29.57; p < 0.001*'