0

Does anyone know how to extract the cohen's f2 effect size value from a model computed with the lm() function in R?

I would like to report effect sizes for individual predictors while accounting for other covariates in a multiple regression model, in order to not limit myself to p values in my reporting. There is information out there for using SAS, but not for the lm() function in R

jpsmith
  • 3,051
  • 1
  • 8
  • 31
  • Are you looking for [this SO post](https://stackoverflow.com/questions/71213139/is-there-any-way-to-calculate-f-squared-as-an-effect-size-for-a-predictor-with)? – Rui Barradas May 13 '22 at 12:37

1 Answers1

1

Here is a function to compute Cohen's f2.

cohen_f2 <- function(fit, fit2){
  R2 <- summary(fit)$r.squared
  if(missing(fit2)) {
    R2/(1 - R2)
  } else {
    R2B <- summary(fit2)$r.squared
    (R2B - R2)/(1 - R2B)
  }
}

data(LifeCycleSavings, package = "datasets")

fm0 <- lm(sr ~ pop15 + pop75 + dpi, data = LifeCycleSavings)
fm1 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)

# summary(fm0)
# summary(fm1)

cohen_f2(fm0)
#> [1] 0.3780803
cohen_f2(fm1)
#> [1] 0.5116161
cohen_f2(fm0, fm1)
#> [1] 0.09689991

Created on 2022-05-13 by the reprex package (v2.0.1)

Rui Barradas
  • 57,195
  • 8
  • 29
  • 57