Learn R Programming

apa (version 0.3.4)

cohens_d: Cohen's d

Description

Calculate Cohen's d from raw data or a call to t_test/t.test.

Usage

cohens_d(...)

# S3 method for default cohens_d( x, y = NULL, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... )

# S3 method for data.frame cohens_d( data, dv, iv, paired = FALSE, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... )

# S3 method for formula cohens_d( formula, data, corr = c("none", "hedges_g", "glass_delta"), na.rm = FALSE, ... )

# S3 method for htest cohens_d(ttest, corr = c("none", "hedges_g", "glass_delta"), ...)

Arguments

...

Further arguments passed to methods.

x

A (non-empty) numeric vector of data values.

y

An optional (non-empty) numeric vector of data values.

paired

A logical indicating whether Cohen's d should be calculated for a paired sample or two independent samples (default). Ignored when calculating Cohen's for one sample.

corr

Character specifying the correction applied to calculation of the effect size: "none" (default) returns Cohen's d, "hedges_g" applies Hedges correction and "glass_delta" calculates Glass' \(\Delta\) (uses the standard deviation of the second group).

na.rm

Logical. Should missing values be removed?

data

A data frame containing either the variables in the formula formula or the variables specified by dv and iv.

dv

Character indicating the name of the column in data for the dependent variable

iv

Character indicating the name of the column in data for the independent variable

formula

A formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs either 1 for one sample or paired data or a factor with two levels giving the corresponding groups. If lhs is of class "Pair" and rhs is 1, Cohen's d for paired data will be calculated.

ttest

An object of class htest (a call to either t_test (preferred) or t.test).

Details

To calculate Cohen's d from summary statistics (M, SD, ..) use cohens_d_.

References

Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. doi:10.3389/fpsyg.2013.00863

Examples

Run this code
# Calculate from raw data
cohens_d(c(10, 15, 11, 14, 17), c(22, 18, 23, 25, 20))

# Methods when working with data frames
cohens_d(sleep, dv = extra, iv = group, paired = TRUE)
# or
cohens_d(sleep, dv = "extra", iv = "group", paired = TRUE)
# formula interface
sleep2 <- reshape(sleep, direction = "wide", idvar = "ID", timevar = "group")
cohens_d(Pair(extra.1, extra.2) ~ 1, sleep2, paired = TRUE)

# Or pass a call to t_test or t.test
cohens_d(t_test(Pair(extra.1, extra.2) ~ 1, sleep2))

Run the code above in your browser using DataLab