'is there any way to calculate f-squared (as an effect size) for a predictor within an lm() multiple linear regression model?

For example, see the following reproducible example from the effectsize package:

library(effectsize)
model1 <- lm(mpg ~ cyl + disp + hp, data = mtcars)
model2 <- lm(mpg ~ cyl, data = mtcars)
cohens_f_squared(model1, model2 = model2)

The output indicates the Cohen's f2 is .18 and the change in r2 is .04. I would think f-squared would be .04167 (.04/1 - .04).

Let me know where I'm missing something - thank you!

rlm


Solution 1:[1]

@BenBolker This is the correct formula for computing f-square (see reference below):

f2 = (R2_modelA - R2_modelB)/(1 - R2_modelA)

In the example you posted, the modelA R2 is 0.7262 and modelB R2 is 0.7679. When you plug this into the f-square formula, you get (0.7679-0.7262)/(1-0.7679) = 0.18, which is the same value computed by the cohens_f_squared() function.

Cheers!

REFERENCE:

Selya, A. S., Rose, J. S., Dierker, L. C., Hedeker, D., & Mermelstein, R. J. (2012). A Practical Guide to Calculating Cohen's f(2), a Measure of Local Effect Size, from PROC MIXED. Frontiers in psychology, 3, 111. https://doi.org/10.3389/fpsyg.2012.00111

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3328081/#:~:text=f%202%20%3D%20R%202%201%20%2D%20R%202%20.

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