# NOT RUN {
# calculate Cohen's d for two independent samples:
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)
# calculate Cohen's d for the same data, described differently:
grade <- c(55, 65, 65, 68, 70, 56, 60, 62, 66) # grades for all students
teacher <- c("A", "A", "A", "A", "A", "B", "B", "B", "B") # teacher for each student
cohensD(grade ~ teacher)
# calculate Cohen's d for two paired samples:
pre <- c(100, 122, 97, 25, 274) # a pre-treatment measure for 5 cases
post <- c(104, 125, 99, 29, 277) # the post-treatment measure for the same 5 cases
cohensD(pre, post, method = "paired") # ... explicitly indicate that it's paired, or else
cohensD(post - pre) # ... do a "single-sample" calculation on the difference
# support for data frames:
exams <- data.frame(grade, teacher)
cohensD(exams$grade ~ exams$teacher) # using $
cohensD(grade ~ teacher, data = exams) # using the 'data' argument
# }
Run the code above in your browser using DataLab