科恩的 D 与 R 中的对比

cohen's D with contrasts in R

有人可以帮助我了解如何通过具有对比的方差分析计算科恩 D 值吗?我可以从向量或数据集计算 cohen's D,但无法从对比中弄清楚如何计算。谢谢

#Create data frame
group = c("treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment",
          "control","control","control","control","control","control","control","control","control","control",
          "other","other","other","other","other","other","other","other","other","other") 
score = c(7,8,9,10,7,8,9,10,7,8,
          6,5,4,6,5,4,6,5,4,6,
          3,2,1,3,2,1,3,2,1,3) 
sample =data.frame(group,score) 


#Set contrasts
contrast = c(-1,0,1)

#Bind contrasts
contrasts(sample$group) = cbind(contrast)

#Check contrasts
contrasts(sample$group)

#Run ANOVA w/ contrasts 
aov1 = aov(score ~ group, sample)
summary.lm(aov1)

计算 Cohen's D 的函数至少在三个不同的 R 包中,包括 effsizerstatixpsych 包。 aov() 函数中没有专门用于计算 Cohen's D 的功能。

Cohen 的 D 需要二分组变量。鉴于 OP 中的数据和将测试组与对照组进行比较的对比语句,我们将使用 psych::cohen.d() 将测试组与对照组进行比较。

group = c("treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment","treatment",
          "control","control","control","control","control","control","control","control","control","control",
          "other","other","other","other","other","other","other","other","other","other") 
score = c(7,8,9,10,7,8,9,10,7,8,
          6,5,4,6,5,4,6,5,4,6,
          3,2,1,3,2,1,3,2,1,3) 
sample =data.frame(group,score) 

sample2 <- sample[sample$group != "other",]
sample2$group <- factor(sample2$group)
library(psych)
cohen.d(score ~ group, data = sample2)

...输出:

> cohen.d(score ~ group, data = sample2)

Cohen's d

d estimate: -3.114651 (large)
95 percent confidence interval:
    lower     upper 
-4.512240 -1.717062