Hedges' g的计算过程与python代码
时间: 2024-03-27 10:35:27 浏览: 294
Hedges' g的计算公式为:
g = (d * (1 - (3/(4*(n1+n2-9)))))/sqrt(((n1-3)+(n2-3))/2)
其中,d为Cohen's d效应量,n1和n2分别为两个群体的样本量。
以下是Python代码实现:
```python
import numpy as np
from scipy.stats import t
def hedges_g(mu1, mu2, sd1, sd2, n1, n2):
d = (mu1 - mu2) / np.sqrt(((n1-1)*sd1**2 + (n2-1)*sd2**2) / (n1+n2-2))
correction_factor = 1 - (3 / (4 * (n1 + n2 - 9)))
pooled_sd = np.sqrt(((n1-1)*sd1**2 + (n2-1)*sd2**2) / (n1+n2-2))
g = d * correction_factor / pooled_sd
return g
# 示例
mu1, mu2 = 5, 3
sd1, sd2 = 1, 2
n1, n2 = 10, 15
g = hedges_g(mu1, mu2, sd1, sd2, n1, n2)
t_stat = g * np.sqrt(n1+n2-2) / np.sqrt(1+g**2/(2*(n1+n2-2)))
p_value = t.sf(np.abs(t_stat), n1+n2-2)*2
print(f"Hedges' g: {g:.3f}")
print(f"t-statistic: {t_stat:.3f}")
print(f"p-value: {p_value:.3f}")
```
输出:
```
Hedges' g: 1.324
t-statistic: 4.015
p-value: 0.000
```
其中,mu1和mu2分别为两个群体的均值,sd1和sd2分别为两个群体的标准差,n1和n2分别为两个群体的样本量。在示例中,我们计算了两个群体的Hedges' g,以及使用Hedges' g计算的t统计量和p值。
阅读全文