Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Estimate Cohen's d for effect size

Tags:

r

statistics

given two vectors:

x <- rnorm(10, 10, 1)
y <- rnorm(10, 5, 5)

How to calculate Cohen's d for effect size?

For example, I want to use the pwr package to estimate the power of a t-test with unequal variances and it requires Cohen's d.

like image 715
Kevin Avatar asked Mar 15 '13 15:03

Kevin


People also ask

How do you calculate Cohen's d effect size?

Calculate Cohen's d by taking the difference between two means and dividing by the data's standard deviation. This measure reports the size of the mean difference by comparing it to the data's variability.

How do you estimate effect size?

Generally, effect size is calculated by taking the difference between the two groups (e.g., the mean of treatment group minus the mean of the control group) and dividing it by the standard deviation of one of the groups.

What is the effect size using Cohen's d?

Interpreting cohen's d A commonly used interpretation is to refer to effect sizes as small (d = 0.2), medium (d = 0.5), and large (d = 0.8) based on benchmarks suggested by Cohen (1988).

What is the formula for Cohen's d?

d = (M1 – M2) / spooled M1 = mean of group 1. M2 = mean of group 2. spooled = pooled standard deviations for the two groups. The formula is: √[(s12+ s22) / 2]


1 Answers

Following this link and wikipedia, Cohen's d for a t-test seems to be:

enter image description here

Where sigma (denominator) is:

enter image description here

So, with your data:

set.seed(45)                        ## be reproducible 
x <- rnorm(10, 10, 1)                
y <- rnorm(10, 5, 5)

cohens_d <- function(x, y) {
    lx <- length(x)- 1
    ly <- length(y)- 1
    md  <- abs(mean(x) - mean(y))        ## mean difference (numerator)
    csd <- lx * var(x) + ly * var(y)
    csd <- csd/(lx + ly)
    csd <- sqrt(csd)                     ## common sd computation

    cd  <- md/csd                        ## cohen's d
}
> res <- cohens_d(x, y)
> res
# [1] 0.5199662
like image 83
Arun Avatar answered Oct 22 '22 18:10

Arun