def test_simulate_equivalence(): # regression test, needs large k_mc to be reliable k_groups = 4 k_repl = 10 nobs = np.array([10, 12, 13, 15]) * k_repl means = np.array([-1, 0, 0, 1]) * 0.12 vars_ = np.array([1, 2, 3, 4]) nobs_t = nobs.sum() eps = 0.0191 * 10 opt_var = ["unequal", "equal", "bf"] k_mc = 100 np.random.seed(987126) res_mc = smo.simulate_power_equivalence_oneway(means, nobs, eps, vars_=vars_, k_mc=k_mc, trim_frac=0.1, options_var=opt_var, margin_type="wellek") frac_reject = (res_mc.pvalue <= 0.05).sum(0) / k_mc assert_allclose(frac_reject, [0.17, 0.18, 0.14], atol=0.001) # result with k_mc = 10000 is [0.1466, 0.1871, 0.1606] # similar to asy below, but not very close for all es_alt_li = [] for uv in opt_var: es = effectsize_oneway(means, vars_, nobs, use_var=uv) es_alt_li.append(es) # compute asy power as comparison margin = wellek_to_f2(eps, k_groups) pow_ = [ power_equivalence_oneway(es_, margin, nobs_t, n_groups=k_groups, df=None, alpha=0.05, margin_type="f2") for es_ in es_alt_li ] # regression test numbers assert_allclose(pow_, [0.147749, 0.173358, 0.177412], atol=0.007)
def test_equivalence_welch(self): # reference numbers from Jan and Shieh 2019, p. 6 means = self.means nobs = self.nobs stds = self.stds n_groups = self.n_groups vars_ = stds**2 eps = 0.5 res0 = anova_generic(means, vars_, nobs, use_var="unequal", welch_correction=False) f_stat = res0.statistic res = equivalence_oneway_generic(f_stat, n_groups, nobs.sum(), eps, res0.df, alpha=0.05, margin_type="wellek") assert_allclose(res.pvalue, 0.0110, atol=0.001) assert_allclose(res.df, [3.0, 22.6536], atol=0.0006) # agreement for Welch f-stat looks too low b/c welch_correction=False assert_allclose(f_stat, 0.1102, atol=0.007) res = equivalence_oneway(self.data, eps, use_var="unequal", margin_type="wellek") assert_allclose(res.pvalue, 0.0110, atol=1e-4) assert_allclose(res.df, [3.0, 22.6536], atol=0.0006) assert_allclose(res.f_stat, 0.1102, atol=1e-4) # 0.007) # check post-hoc power, JS p. 6 pow_ = _power_equivalence_oneway_emp(f_stat, n_groups, nobs, eps, res0.df) assert_allclose(pow_, 0.1552, atol=0.007) pow_ = power_equivalence_oneway(eps, eps, nobs.sum(), n_groups=n_groups, df=None, alpha=0.05, margin_type="wellek") assert_allclose(pow_, 0.05, atol=1e-13) nobs_t = nobs.sum() es = effectsize_oneway(means, vars_, nobs, use_var="unequal") es = np.sqrt(es) es_w0 = f2_to_wellek(es**2, n_groups) es_w = np.sqrt(fstat_to_wellek(f_stat, n_groups, nobs_t / n_groups)) pow_ = power_equivalence_oneway(es_w, eps, nobs_t, n_groups=n_groups, df=None, alpha=0.05, margin_type="wellek") assert_allclose(pow_, 0.1552, atol=0.007) assert_allclose(es_w0, es_w, atol=0.007) margin = wellek_to_f2(eps, n_groups) pow_ = power_equivalence_oneway(es**2, margin, nobs_t, n_groups=n_groups, df=None, alpha=0.05, margin_type="f2") assert_allclose(pow_, 0.1552, atol=0.007)