'Cohen's f2 in R

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



Solution 1:[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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rui Barradas