Learn R Programming

rstatix (version 0.1.0)

cohens_d: Compute Cohen's d Measure of Effect Size

Description

Compute the effect size for t-test.

Usage

cohens_d(data, formula, paired = FALSE, mu = 0, var.equal = FALSE)

Arguments

data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group.

paired

a logical indicating whether you want a paired test.

mu

theoretical mean, use for one-sample t-test. Default is O.

var.equal

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used.

Examples

Run this code
# NOT RUN {
# One-sample t test effect size
ToothGrowth %>% cohens_d(len ~ 1, mu = 0)

# Two indepedent samples t-test effect size
ToothGrowth %>% cohens_d(len ~ supp, var.equal = TRUE)

# Paired samples effect size
df <- data.frame(
  id = 1:5,
  pre  = c(110, 122, 101, 120, 140),
  post = c(150, 160, 110, 140, 155)
)
df <- df %>% gather(key = "treatment", value = "value", -id)
head(df)

df %>% cohens_d(value ~ treatment, paired = TRUE)
# }

Run the code above in your browser using DataLab