R:根据多元线性回归中系数的 t 统计量计算 Cohen's d

R: Compute Cohen's d based on t-statistic of a coefficient in multiple linear regression

我在关注的连续变量中查看年龄和性别调整后的群体差异。正如我所在领域的其他研究所做的那样,我想根据从多元线性回归模型 .

中提取的 对比来计算 Cohen 的 d

原公式(Nakagawa & Cuthill, 2007)如下:

n1 = 第 1 组的样本量

n2 = 第 2 组的样本量

df' = 用于线性模型中相应 t 值的自由度

t = t 统计对应于感兴趣的对比

到目前为止,我已经尝试在 R 中应用它,但结果看起来很奇怪(效果比预期大得多)。

这是一些模拟数据:

library(broom)

df = data.frame(ID = c(1001, 1002, 1003, 1004, 1005, 1006,1007, 1008, 1009, 1010),
                Group = as.numeric(c('0','1','0','0','1','1','0','1','0','1')),
                age = as.numeric(c('23','28','30','15','7','18','29','27','14','22')),
                sex = as.numeric(c('1','0','1','0','0','1','1','0','0','1')),
                test_score = as.numeric(c('18','20','19','15','20','23','19','25','10','14')))

# run lm and extract regression coefficients

model <- lm(test_score ~ Group + age + sex, data = df)
tidy_model <- tidy(model)

tidy_model

# A tibble: 4 x 5
#term        estimate std.error statistic p.value
#<chr>          <dbl>     <dbl>     <dbl>   <dbl>
#  1 (Intercept)   11.1       4.41     2.52    0.0451
# 2 Group          4.63      2.65     1.75    0.131 
# 3 age            0.225     0.198    1.13    0.300 
# 4 sex            0.131     2.91     0.0452  0.965 

t_statistic <- tidy_model[2,4] # = 1.76
n <- 5 #(equal n of participants in Group1 as in Group2)
cohens_d <- t_statistic*(n + n)/(sqrt(n * n) * sqrt(1)) # 1 dof for 1 estimated parameter (group contrast)

cohens_d  # = 3.518096

你能指出我哪里出错了吗?

您已将自由度设置为 1。但是,您实际上有 6 个自由度,如果您键入:summary(model) 就可以看到。 如果您将自由度设置为 6,您的 Cohen's d 将为 ~1.7,这应该更符合您的预期。