Reputation: 907
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
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