def test_rm_anova2(self): """Test function rm_anova2. Compare with JASP. """ data = read_dataset('rm_anova2') aov = rm_anova(data=data, subject='Subject', within=['Time', 'Metric'], dv='Performance').round(3) array_equal(aov.loc[:, 'MS'], [828.817, 682.617, 112.217]) array_equal(aov.loc[:, 'F'], [33.852, 26.959, 12.632]) array_equal(aov.loc[:, 'np2'], [0.790, 0.750, 0.584]) array_equal(aov.loc[:, 'eps'], [1., 0.969, 0.727]) # With different effect sizes aov = rm_anova(data=data, subject='Subject', within=['Time', 'Metric'], dv='Performance', effsize="n2").round(3) array_equal(aov.loc[:, 'n2'], [0.255, 0.419, 0.069]) aov = rm_anova(data=data, subject='Subject', within=['Time', 'Metric'], dv='Performance', effsize="ng2").round(3) array_equal(aov.loc[:, 'ng2'], [0.254, 0.359, 0.084]) # 2 factors with missing values. Cannot compare with JASP directly # because Pingouin applies an automatic removal of missing values # (on the last factor). JASP uses a regression-based approach which # can handle missing values. df2 = read_dataset('rm_missing') df2.rm_anova(dv='BOLD', within=['Session', 'Time'], subject='Subj') # Error: more than two factors with pytest.raises(ValueError): df2.rm_anova(dv='BOLD', within=['Session', 'Time', 'Wrong'], subject='Subj')
def test_rm_anova(self): """Test function rm_anova. Compare with JASP""" rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=False, detailed=False) rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=False) aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction='auto', detailed=True) # Compare with JASP assert np.allclose(aov.loc[0, 'F'], 3.913) assert np.allclose(np.round(aov.loc[0, 'p-unc'], 3), .023) assert np.allclose(aov.loc[0, 'np2'], .062) rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=True) rm_anova(dv='Scores', within=['Time'], subject='Subject', data=df_nan, export_filename='test_export.csv') # Using a wide dataframe with NaN and compare with JASP data = read_dataset('rm_anova_wide') aov = data.rm_anova(detailed=True, correction=True) assert aov.loc[0, 'F'] == 5.201 assert round(aov.loc[0, 'p-unc'], 3) == .007 assert aov.loc[0, 'np2'] == .394 assert aov.loc[0, 'eps'] == .694 assert aov.loc[0, 'W-spher'] == .307 assert round(aov.loc[0, 'p-GG-corr'], 3) == .017
def _rm_anova(self, dv=None, within=None, subject=None, detailed=False, correction='auto', export_filename=None): """One-way and two-way repeated measures ANOVA.""" aov = rm_anova(data=self, dv=dv, within=within, subject=subject, correction=correction, detailed=detailed, export_filename=export_filename) return aov
def test_rm_anova2(self): """Test function rm_anova2. Compare with JASP.""" data = read_dataset('rm_anova2') aov = rm_anova(data=data, subject='Subject', within=['Time', 'Metric'], dv='Performance', export_filename='test_export.csv').round(3) assert aov.loc[0, "MS"] == 828.817 assert aov.loc[1, "MS"] == 682.617 assert aov.loc[2, "MS"] == 112.217 assert aov.loc[0, "F"] == 33.852 assert aov.loc[1, "F"] == 26.959 assert aov.loc[2, "F"] == 12.632 assert aov.loc[0, "np2"] == 0.790 assert aov.loc[1, "np2"] == 0.750 assert aov.loc[2, "np2"] == 0.584 assert aov.loc[0, "eps"] == 1.000 assert aov.loc[1, "eps"] == 0.969 assert aov.loc[2, "eps"] >= 0.500 # 0.5 is the lower bound # With missing values df2 = read_dataset('rm_missing') df2.rm_anova(dv='BOLD', within=['Session', 'Time'], subject='Subj')
def test_rm_anova2(self): """Test function rm_anova2. Compare with JASP.""" data = read_dataset('rm_anova2') aov = rm_anova(data=data, subject='Subject', within=['Time', 'Metric'], dv='Performance', export_filename='test_export.csv').round(3) array_equal(aov.loc[:, 'MS'].values, [828.817, 682.617, 112.217]) array_equal(aov.loc[:, 'F'].values, [33.852, 26.959, 12.632]) array_equal(aov.loc[:, 'np2'].values, [0.790, 0.750, 0.584]) assert aov.loc[0, "eps"] == 1.000 assert aov.loc[1, "eps"] == 0.969 assert aov.loc[2, "eps"] >= 0.500 # 0.5 is the lower bound # With missing values df2 = read_dataset('rm_missing') df2.rm_anova(dv='BOLD', within=['Session', 'Time'], subject='Subj') # Error: more than two factors with pytest.raises(ValueError): df2.rm_anova(dv='BOLD', within=['Session', 'Time', 'Wrong'], subject='Subj')
def test_rm_anova2(self): """Test function rm_anova2.""" data = pd.DataFrame({ 'Subject': [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], 'Time': [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1], 'Drug': ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'], 'Scores': [3, 4, 5, 7, 2, 4, 5, 8, 5, 7, 3, 8] }) rm_anova2(dv='Scores', within=['Time', 'Drug'], subject='Subject', data=data, export_filename='test_export.csv') rm_anova(dv='Scores', within=['Time', 'Drug'], subject='Subject', data=data)
def test_rm_anova(self): """Test function rm_anova.""" rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=False, detailed=False) rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=False) aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction='auto', detailed=True) # Compare with JASP assert np.allclose(aov.loc[0, 'F'], 3.913) assert np.allclose(np.round(aov.loc[0, 'p-unc'], 3), .023) assert np.allclose(aov.loc[0, 'np2'], .062) rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=True) rm_anova(dv='Scores', within=['Time'], subject='Subject', data=df_nan, export_filename='test_export.csv')
def test_rm_anova(self): """Test function rm_anova. Compare with JASP """ rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=False, detailed=False) rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=False) # Compare with JASP aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction='auto', detailed=True).round(3) assert aov.at[0, 'F'] == 3.913 assert aov.at[0, 'p-unc'] == .023 assert aov.at[0, 'np2'] == .062 # Same but with categorical columns aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df_cat, correction='auto', detailed=True).round(3) assert aov.at[0, 'F'] == 3.913 assert aov.at[0, 'p-unc'] == .023 assert aov.at[0, 'np2'] == .062 # With different effect sizes aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction='auto', effsize="n2").round(3) assert aov.at[0, 'n2'] == .062 aov = rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction='auto', detailed=True, effsize="ng2").round(3) assert aov.at[0, 'ng2'] == .040 rm_anova(dv='Scores', within='Time', subject='Subject', data=df, correction=True, detailed=True) rm_anova(dv='Scores', within=['Time'], subject='Subject', data=df_nan) # Using a wide dataframe with NaN and compare with JASP data = read_dataset('rm_anova_wide') aov = data.rm_anova(detailed=True, correction=True).round(3) assert aov.at[0, 'F'] == 5.201 assert aov.at[0, 'p-unc'] == .007 assert aov.at[0, 'np2'] == .394 assert aov.at[0, 'eps'] == .694 assert aov.at[0, 'W-spher'] == .307 assert aov.at[0, 'p-GG-corr'] == .017