Lowpar
Lowpar

Reputation: 907

Convert R2 to Cohen's d

I am looking to convert the output of the lm function to Cohen's d, so far I have been able to extract the r2, however, how can I retrieve Cohen's d from R2 in r?

m <- lm(outcome ~ predictor, data = df)
summary(m)$adj.r.squared

Also any idea how to calculate the upper and lower bounds of the r2?

Upvotes: 1

Views: 639

Answers (2)

Rui Barradas
Rui Barradas

Reputation: 76422

To calculate the upper and lower bounds of the r2 you can bootstrap. Function boot::boot is very easy to use, if you choose to use this method.

Data

set.seed(1072)   # Make it reproducible

predictor <- rnorm(100)
outcome <- predictor + rnorm(100)
df <- data.frame(predictor, outcome)

Code

bootfun <- function(DF, index){
    m <- lm(outcome ~ predictor, data = DF[index, ])
    summary(m)$adj.r.squared
}

b <- boot::boot(df, bootfun, R = 1000)
quantile(b$t, c(0.025, 0.975))
     2.5%     97.5% 
0.4065505 0.6500718

Upvotes: 1

Dan
Dan

Reputation: 12074

The lsr package seems to provide a function for calculating Cohen's d:

cohensD(outcome ~ predictor, data = df)

Upvotes: 2

Related Questions