0

Can someone help me understand how to calculate cohen's D from an ANOVA with contrasts? I have no problem calculating cohen's D from vectors or datasets, but can't figure out how to do it from a contrast. Thanks.

#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)
richiepop2
  • 348
  • 1
  • 12

1 Answers1

1

Functions to calculate Cohen's D are in at least three different R packages, including effsize, rstatix, and psych packages. There are no features specifically within the aov() function to calculate Cohen's D.

Cohen's D requires a dichotomous group variable. Given the data in the OP and the contrast statement that compares the test group to the control group, we'll compare the test group to the control group with 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)

...and the output:

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

Cohen's d

d estimate: -3.114651 (large)
95 percent confidence interval:
    lower     upper 
-4.512240 -1.717062 
Len Greski
  • 10,505
  • 2
  • 22
  • 33