# two independent groups supplied as separate vectors
gradesA <- c(55, 65, 65, 68, 70) # 5 students with teacher A
gradesB <- c(56, 60, 62, 66) # 4 students with teacher B
cohensD(gradesA, gradesB)
# the same comparison using a formula and a data frame
grade <- c(55, 65, 65, 68, 70, 56, 60, 62, 66)
teacher <- c("A", "A", "A", "A", "A", "B", "B", "B", "B")
cohensD(grade ~ teacher)
# paired samples: use method = "paired" (SD of within-person differences)
pre <- c(100, 122, 97, 25, 274)
post <- c(104, 125, 99, 29, 277)
cohensD(pre, post, method = "paired")
# equivalent one-sample calculation on the difference scores
cohensD(post - pre)
# formula interface with a data frame
exams <- data.frame(grade, teacher)
cohensD(grade ~ teacher, data = exams)
Run the code above in your browser using DataLab