def test_smd(self): # compare with metafor yi = np.array([ 0.09452415852032972, 0.27735586626551018, 0.36654442951591998, 0.66438496832691396, 0.46180628128769841, 0.18516443739910043 ]) vi_asy = np.array([ 0.03337056173559990, 0.03106510106366112, 0.05083971761755720, 0.01055175923267344, 0.04334466980873156, 0.02363025255552155 ]) vi_ub = np.array([ 0.03337176211751222, 0.03107388569950075, 0.05088098670518214, 0.01055698026322296, 0.04339077140867459, 0.02363252645927709 ]) eff, var_eff = effectsize_smd(*self.dta) # agreement with metafor is lower, atol for var 2.5e-06 # It's likely a small difference in bias correction assert_allclose(eff, yi, rtol=1e-5) assert_allclose(var_eff, vi_ub, rtol=1e-4) assert_allclose(var_eff, vi_asy, rtol=2e-3) # not the same definition # with unequal variance, not available yet # > r = escalc(measure="SMDH", m1i=m.t, sd1i=sd.t, n1i=n.t, m2i=m.c, # sd2i=sd.c, n2i=n.c, data=dat, vtype="UB") yi = np.array([ 0.09452415852032972, 0.27735586626551023, 0.36654442951591998, 0.66438496832691396, 0.46122883016705268, 0.18516443739910043 ]) vi_ub = np.array([ 0.03350541862210323, 0.03118164624093491, 0.05114625874744853, 0.01057160214284120, 0.04368303906568672, 0.02369839436451885 ]) # compare with package `meta` # high agreement, using smd function was written based on meta example # > rm = metacont(n.t,m.t,sd.t,n.c,m.c,sd.c, # + data=dat,studlab=rownames(dat),sm="SMD") # > rm$TE yi_m = np.array([ 0.09452437336063831, 0.27735640148036095, 0.36654634845797818, 0.66438509989113559, 0.46180797677414176, 0.18516464424648887 ]) # > rm$seTE**2 vi_m = np.array([ 0.03337182573880991, 0.03107434965484927, 0.05088322525353587, 0.01055724834741877, 0.04339324466573324, 0.02363264537147130 ]) assert_allclose(eff, yi_m, rtol=1e-13) assert_allclose(var_eff, vi_m, rtol=1e-13)
] colnames = ["study", "mean_t", "sd_t", "n_t", "mean_c", "sd_c", "n_c"] rownames = [i[0] for i in data] dframe1 = pd.DataFrame(data, columns=colnames) rownames mean2, sd2, nobs2, mean1, sd1, nobs1 = np.asarray( dframe1[["mean_t", "sd_t", "n_t", "mean_c", "sd_c", "n_c"]]).T rownames = dframe1["study"] rownames.tolist() np.array(nobs1 + nobs2) # ### estimate effect size standardized mean difference eff, var_eff = effectsize_smd(mean2, sd2, nobs2, mean1, sd1, nobs1) # ### Using one-step chi2, DerSimonian-Laird estimate for random effects # variance tau # # Method option for random effect `method_re="chi2"` or `method_re="dl"`, # both names are accepted. # This is commonly referred to as the DerSimonian-Laird method, it is # based on a moment estimator based on pearson chi2 from the fixed effects # estimate. res3 = combine_effects(eff, var_eff, method_re="chi2", use_t=True, row_names=rownames)