def test_oneway(self): r1 = self.res_oneway r2s = self.res_2s res_bfm = self.res_bfm res_wa = self.res_wa res_fa = self.res_fa # check we got the correct data m = [x_i.mean() for x_i in self.x] assert_allclose(m, self.res_m, rtol=1e-13) # 3 sample case resg = smo.anova_oneway(self.x, use_var="unequal", trim_frac=1 / 13) # assert_allclose(res.statistic, res_bfm.statistic, rtol=1e-13) assert_allclose(resg.pvalue, r1.p_value, rtol=1e-13) assert_allclose(resg.df, [r1.df1, r1.df2], rtol=1e-13) # df # 2-sample against yuen t-test resg = smo.anova_oneway(self.x[:2], use_var="unequal", trim_frac=1 / 13) # assert_allclose(res.statistic, res_bfm.statistic, rtol=1e-13) assert_allclose(resg.pvalue, r2s.p_value, rtol=1e-13) assert_allclose(resg.df, [1, r2s.df], rtol=1e-13) # df # no trimming bfm res = smo.anova_oneway(self.x, use_var="bf") assert_allclose(res[0], res_bfm.statistic, rtol=1e-13) assert_allclose(res.pvalue2, res_bfm.p_value, rtol=1e-13) assert_allclose(res.df2, res_bfm.parameter, rtol=1e-13) # df # no trimming welch res = smo.anova_oneway(self.x, use_var="unequal") assert_allclose(res.statistic, res_wa.statistic, rtol=1e-13) assert_allclose(res.pvalue, res_wa.p_value, rtol=1e-13) assert_allclose(res.df, res_wa.parameter, rtol=1e-13) # df # no trimming standard anova res = smo.anova_oneway(self.x, use_var="equal") assert_allclose(res.statistic, res_fa.statistic, rtol=1e-13) assert_allclose(res.pvalue, res_fa.p_value, rtol=1e-13) assert_allclose(res.df, res_fa.parameter, rtol=1e-13) # df
def test_means(self): # library onewaystats, BF test for equality of means # st = bf.test(y ~ g, df3) statistic = 7.10900606421182 parameter = [2, 31.4207256105052] p_value = 0.00283841965791224 # method = 'Brown-Forsythe Test' res = anova_oneway(self.data, use_var="bf") # R bf.test uses original BF df_num assert_allclose(res.pvalue2, p_value, rtol=1e-13) assert_allclose(res.statistic, statistic, rtol=1e-13) assert_allclose([res.df_num2, res.df_denom], parameter)
def test_options(self): # regression tests for options, # many might not be implemented in other packages data = self.data # regression numbers from initial run statistic, p_value = 1.0173464626246675, 0.3763806150460239 df = (2.0, 24.40374758005409) res = smo.test_scale_oneway(data, method='unequal', center='median', transform='abs', trim_frac_mean=0.2) assert_allclose(res.pvalue, p_value, rtol=1e-13) assert_allclose(res.statistic, statistic, rtol=1e-13) assert_allclose(res.df, df) statistic, p_value = 1.0329722145270606, 0.3622778213868562 df = (1.83153791573948, 30.6733640949525) p_value2 = 0.3679999679787619 df2 = (2, 30.6733640949525) res = smo.test_scale_oneway(data, method='bf', center='median', transform='abs', trim_frac_mean=0.2) assert_allclose(res.pvalue, p_value, rtol=1e-13) assert_allclose(res.statistic, statistic, rtol=1e-13) assert_allclose(res.df, df) assert_allclose(res.pvalue2, p_value2, rtol=1e-13) assert_allclose(res.df2, df2) statistic, p_value = 1.7252431333701745, 0.19112038168209514 df = (2.0, 40.0) res = smo.test_scale_oneway(data, method='equal', center='mean', transform='square', trim_frac_mean=0.2) assert_allclose(res.pvalue, p_value, rtol=1e-13) assert_allclose(res.statistic, statistic, rtol=1e-13) assert_equal(res.df, df) statistic, p_value = 0.4129696057329463, 0.6644711582864451 df = (2.0, 40.0) res = smo.test_scale_oneway( data, method='equal', center='mean', transform=lambda x: np.log(x * x), # noqa trim_frac_mean=0.2) assert_allclose(res.pvalue, p_value, rtol=1e-13) assert_allclose(res.statistic, statistic, rtol=1e-13) assert_allclose(res.df, df) # compare no transform with standard anova res = smo.test_scale_oneway(data, method='unequal', center=0, transform='identity', trim_frac_mean=0.2) res2 = anova_oneway(self.data, use_var="unequal") assert_allclose(res.pvalue, res2.pvalue, rtol=1e-13) assert_allclose(res.statistic, res2.statistic, rtol=1e-13) assert_allclose(res.df, res2.df)
print(sm.stats.anova_lm(st_vfcc, typ=2)) print('Residual Shapiro ' + str(stats.shapiro(st_vfcc.resid))) print(stats.anderson(st_vfcc.resid)) mm.probability_plot_ols(10, st_vfcc.resid) #except Exception: # pass try: print('') print('Welch ANOVA') print('') welch = ao.anova_oneway(df['vF'], df['Depth'], use_var='unequal', welch_correction=True) print('-------- vF ----------') print(welch) welch = ao.anova_oneway(df['vwc1kPa'], df['Depth'], use_var='unequal', welch_correction=True) print('-------- vwc1kPa ----------') print(welch) welch = ao.anova_oneway(df['vwc3kPa'], df['Depth'], use_var='unequal', welch_correction=True)
bartlett = stats.bartlett( df[df['indp_var']=='grad'][col], df[df['indp_var']=='wish'][col], df[df['indp_var']=='no_wish'][col] ) if not levene[1] > 0.05 or bartlett[1] > 0.05: noequal_var.append(col) else: print(col) # Brown-Forsythe test for no equality of varience brown = [] for col in noequal_var: brown.append( anova_oneway( df[col], df['indp_var'], use_var='bf' ).pvalue2) no_equal_df = pd.DataFrame([noequal_var, brown]).T no_equal_df.to_csv(data_loc + 'no_equalANOVA.csv', encoding='cp949') # Only one column satisfy an equality of varience model = ols('교수수업만족 ~ C(indp_var)', df).fit() print(anova_lm(model)) anova_lm(model).to_csv(data_loc + 'equl_교수수업만족anova.csv') # Chi-square for categorical y variables chi_score = [] p_value = [] degree_f = [] for col in categorical: