def test_pairwise_gameshowell(self): """Test function pairwise_gameshowell. The p-values are slightly different because of a different algorithm used to calculate the studentized range approximation, but significance should be the same. """ # Compare with R package `userfriendlyscience` - Hair color dataset # Update Feb 2021: The userfriendlyscience package has been removed # from CRAN. df = read_dataset('anova') stats = pairwise_gameshowell(dv='Pain threshold', between='Hair color', data=df) assert np.array_equal(np.abs(stats['T'].round(2)), [2.47, 1.42, 1.75, 4.09, 1.11, 3.56]) assert np.array_equal(stats['df'].round(2), [7.91, 7.94, 6.56, 8.0, 6.82, 6.77]) # JASP: [0.1401, 0.5228, 0.3715, 0.0148, 0.6980, 0.0378] # Pingouin: [0.1401, 0.5220, 0.3722, 0.0148, 0.6848, 0.0378] assert np.allclose([0.1401, 0.5228, 0.3715, 0.0148, 0.6980, 0.0378], stats.loc[:, 'pval'].to_numpy().round(3), atol=0.05) sig = stats['pval'].apply(lambda x: 'Yes' if x < 0.05 else 'No').to_numpy() assert np.array_equal(sig, ['No', 'No', 'No', 'Yes', 'No', 'Yes']) # Compare with JASP in the Palmer Penguins dataset df = read_dataset("penguins") stats = pairwise_gameshowell(data=df, dv="body_mass_g", between="species").round(4) assert np.array_equal(stats['A'], ["Adelie", "Adelie", "Chinstrap"]) assert np.array_equal(stats['B'], ["Chinstrap", "Gentoo", "Gentoo"]) assert np.array_equal(stats['diff'], [-32.426, -1375.354, -1342.928]) assert np.array_equal(stats['se'], [59.7064, 58.8109, 65.1028]) assert np.array_equal(stats['df'], [152.4548, 249.6426, 170.4044]) assert np.array_equal(stats['T'], [-0.5431, -23.3860, -20.6278]) # P-values JASP: [0.8502, 0.0000, 0.0000] # P-values Pingouin: [0.8339, 0.0010, 0.0010] sig = stats['pval'].apply(lambda x: 'Yes' if x < 0.05 else 'No').to_numpy() assert np.array_equal(sig, ['No', 'Yes', 'Yes']) # Same but with balanced group df_balanced = df.groupby('species').head(20).copy() # To complicate things, let's encode between as a categorical df_balanced['species'] = df_balanced['species'].astype('category') stats = pairwise_gameshowell(data=df_balanced, dv="body_mass_g", between="species").round(4) assert np.array_equal(stats['A'], ["Adelie", "Adelie", "Chinstrap"]) assert np.array_equal(stats['B'], ["Chinstrap", "Gentoo", "Gentoo"]) assert np.array_equal(stats['diff'], [-142.5, -1457.5, -1315.]) assert np.array_equal(stats['se'], [104.5589, 163.1546, 154.1104]) assert np.array_equal(stats['df'], [35.5510, 30.8479, 26.4576]) assert np.array_equal(stats['T'], [-1.3629, -8.9332, -8.5328]) # P-values JASP: [0.3709, 0.0000, 0.0000] # P-values Pingouin: [0.3719, 0.0010, 0.0010] sig = stats['pval'].apply(lambda x: 'Yes' if x < 0.05 else 'No').to_numpy() assert np.array_equal(sig, ['No', 'Yes', 'Yes'])
def test_pairwise_gameshowell(self): """Test function pairwise_gameshowell""" df = read_dataset('anova') stats = pairwise_gameshowell(dv='Pain threshold', between='Hair color', data=df) # Compare with R package `userfriendlyscience` np.testing.assert_array_equal(np.abs(stats['T'].round(2)), [2.48, 1.42, 1.75, 4.09, 1.11, 3.56]) np.testing.assert_array_equal(stats['df'].round(2), [7.91, 7.94, 6.56, 8.0, 6.82, 6.77]) sig = stats['pval'].apply(lambda x: 'Yes' if x < 0.05 else 'No').values np.testing.assert_array_equal(sig, ['No', 'No', 'No', 'Yes', 'No', 'Yes'])