Python also has a package called Python Meta that performs meta-analysis, but for the purpose of studying, this time I will implement a meta-analysis with pandas. I did.
There are two main types of meta-analysis models, ** Fixed Effect Model ** and ** Random Effects Model **, so let's implement each one.
This time, I will experiment using the following data.
import pandas as pd
import numpy as np
data = pd.DataFrame({
"g": [0.12, 0.23, 0.34, 0.45, 0.42, 0.39, 0.49, 0.65, 0.76, 0.87],
"V": [0.01, 0.04, 0.03, 0.02, 0.01, 0.02, 0.03, 0.04, 0.02, 0.01]
})
Here, g is Hedges'g (= effect size) and V is the variance of effect size.
In the fixed effects model, the reciprocal of the variance of the effect size is simply the weight of the item. Therefore, the average effect size to be calculated is calculated as the effect size of each item weighted and divided by the total weight. The calculation formula is as follows. Even Python can be written in 3 lines.
#Fixed effects model
data['W'] = 1 / data.V
data['Wg'] = data['g'] * data['W']
result = data['Wg'].sum() / data['W'].sum()
result
>> 0.4776
The random effects model makes the weight calculation a bit more complicated. In order to take into account the variability of effect sizes between studies, we take the average effect size and then incorporate the deviation of each item into the weight calculation. The calculation formula is as follows.
g_hat = data.g.mean()
Q = (data.W * (data.g - g_hat)**2).sum()
data['W2'] = data.W ** 2
C = data.W.sum() - (data.W2.sum()/data.W.sum())
d = len(data) - 1
#Inter-research variance
if (Q-d) > 0:
V_between = (Q - d) / C
else:
V_between = 0
data['V_str'] = data.V + V_between
data['W_str'] = 1 / data.V_str
result = (data.g * data.W_str).sum() / data.W_str.sum()
result
You can calculate the 95% confidence interval from the sum of the calculated weights in both the fixed effects model and the random effects model.
std_err = np.sqrt(1/data.W_str.sum())
lwr = result - 1.96 * std_err
upr = result + 1.96 * std_err
[lwr, upr]
["Introduction to Meta-Analysis for Systematic Review of Psychology / Educational Research" edited by Takeshi Yamada and Toshiya Inoue](https://www.amazon.co.jp/%E3%83%A1%E3%82%BF% E5% 88% 86% E6% 9E% 90% E5% 85% A5% E9% 96% 80-% E5% BF% 83% E7% 90% 86% E3% 83% BB% E6% 95% 99% E8 % 82% B2% E7% A0% 94% E7% A9% B6% E3% 81% AE% E7% B3% BB% E7% B5% B1% E7% 9A% 84% E3% 83% AC% E3% 83 % 93% E3% 83% A5% E3% 83% BC% E3% 81% AE% E3% 81% 9F% E3% 82% 81% E3% 81% AB-% E5% B1% B1% E7% 94% B0-% E5% 89% 9B% E5% 8F% B2 / dp / 4130420720)
Recommended Posts