# NOT RUN {
#--------------------------------------
# Between-Subject Design
dat.bs <- data.frame(group = c("cont", "cont", "cont", "treat", "treat"),
y1 = c(1, 3, 2, 5, 7),
y2 = c(4, 3, 3, 6, 4),
y3 = c(7, 5, 7, 3, 2), stringsAsFactors = FALSE)
# Standardized mean difference divided by the weighted pooled
# standard deviation without small sample correction factor
cohens.d(y1 ~ group, data = dat.bs)
# Standardized mean difference divided by the unweighted pooled
# standard deviation without small sample correction factor
cohens.d(y1 ~ group, data = dat.bs, weighted = FALSE)
# Standardized mean difference divided by the weighted pooled
# standard deviation with small sample correction factor
cohens.d(y1 ~ group, data = dat.bs, correct = TRUE)
# Standardized mean difference divided by the standard deviation
# of the control group without small sample correction factor
cohens.d(y1 ~ group, data = dat.bs, ref = "cont")
# Cohens's d for for more than one outcome variable
cohens.d(cbind(y1, y2, y3) ~ group, data = dat.bs)
#--------------------------------------
# Within-Subject Design
dat.ws <- data.frame(pre = c(1, 3, 2, 5, 7),
post = c(2, 2, 1, 6, 8))
# Standardized mean difference divided by the pooled
# standard deviation while controlling for the correlation
# without small sample correction factor
cohens.d(post ~ pre, data = dat.ws, paired = TRUE)
# Standardized mean difference divided by the pooled
# standard deviation whithout controlling for the correlation
# without small sample correction factor
cohens.d(post ~ pre, data = dat.ws, paired = TRUE, weighted = FALSE)
# Standardized mean difference divided by the pooled
# standard deviation while controlling for the correlation
# with small sample correction factor
cohens.d(post ~ pre, data = dat.ws, paired = TRUE, correct = TRUE)
# Standardized mean difference divided by the standard deviation
# of the pretest without small sample correction factor
cohens.d(post ~ pre, data = dat.ws, paired = TRUE, ref = "pre")
# }
Run the code above in your browser using DataLab