我使用Cohen的d(使用effsize
包中的cohen.d()
实现(作为我的因变量在两个因子水平之间的效应大小的度量。
我的代码如下:cohen.d(d, f)
,其中d
是数值的向量,f
是具有两个级别的因子:"a"one_answers"B"。
根据我的理解,科恩d的符号取决于公式中输入的平均数(即因子水平(的顺序。但是,即使我颠倒了f
中级别的顺序,我的cohen.d()
命令也会返回负值(和负CI(。
这里有一个可重复的例子:
library('effsize')
# Load in Chickweight data
a=ChickWeight
# Cohens d requires two levels in factor f, so take the first two available in Diet
a=a[a$Diet==c(1,2),]
a$Diet=a$Diet[ , drop=T]
# Compute cohen's d with default order of Diet
d1 = a$weight
f1 = a$Diet
cohen1 = cohen.d(d1,f1)
# Re-order levels of Diet
a$Diet = relevel(a$Diet, ref=2)
# Re-compute cohen's d
d2 = a$weight
f2 = a$Diet
cohen2 = cohen.d(d2,f2)
# Compare values
cohen1
cohen2
有人能解释为什么会这样吗?和/或我是否做错了什么?
提前感谢您的建议!
我不完全确定你的例子中这个问题背后的原因是什么(也许其他人可以在这里发表评论(,但如果你看看?cohen.d
下的例子,有几种不同的计算方法:
treatment = rnorm(100,mean=10)
control = rnorm(100,mean=12)
d = (c(treatment,control))
f = rep(c("Treatment","Control"),each=100)
## compute Cohen's d
## treatment and control
cohen.d(treatment,control)
## data and factor
cohen.d(d,f)
## formula interface
cohen.d(d ~ f)
如果使用cohen.d(treatment, control)
的第一个示例并将其反转为cohen.d(control, treatment)
,则会得到以下内容:
cohen.d(treatment, control)
Cohen's d
d estimate: -1.871982 (large)
95 percent confidence interval:
inf sup
-2.206416 -1.537547
cohen.d(control, treatment)
Cohen's d
d estimate: 1.871982 (large)
95 percent confidence interval:
inf sup
1.537547 2.206416
因此,使用示例中的两个矢量方法与您的数据,我们可以做到:
a1 <- a[a$Diet == 1,"weight"]
a2 <- a[a$Diet == 2,"weight"]
cohen3a <- cohen.d(a1, a2)
cohen3b <- cohen.d(a2, a1)
我注意到?cohen.d
例子中的f
不是一个因子,而是一个字符向量。我试着使用cohen.d(d, f)
方法,但没有找到解决方案。我想看看其他人是否对此有所了解。