0

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!

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
maudib528
  • 51
  • 1
  • 7
  • 2
    `library("sos"); findFn("{f squared}")`; https://search.r-project.org/CRAN/refmans/effectsize/html/eta_squared.html – Ben Bolker Feb 21 '22 at 21:20
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please be very clear about exactly what value you want to calculate and give a reference if possible. – MrFlick Feb 21 '22 at 21:20
  • @BenBolker Thank you! I'm wondering why the cohens_f_squared() function is yielding a different value than when I do it manually. Both are employing a .43 change in R2 (or R2 delta). Given the formula (.43)/(1-.43), I would think the answer should be .754, but the formula is returning .96. My only inputs were two lm() models that result in a R2 delta of .43. – maudib528 Feb 21 '22 at 21:54
  • I have no idea. Could we please have a [mcve]??? (You could use e.g. the `mtcars` data set from base R) – Ben Bolker Feb 21 '22 at 21:56
  • @BenBolker Sure! ```model1 <- lm(mpg ~ cyl + disp + hp, data = mtcars) model2 <- lm(mpg ~ cyl, data = mtcars) cohens_f_squared(model1, model2 = model2)``` 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) Thank you! – maudib528 Feb 21 '22 at 22:00
  • thanks. Can you please **edit your question** to include that information? – Ben Bolker Feb 21 '22 at 22:05
  • The question is improved, but I'm now voting to close and move it to [CrossValidated](https://stats.stackexchange.com) since it's (now) about the statistical calculations rather than about "how do I do X"? The actual computations can be viewed in `effectsize:::.cohens_f_delta`; I see that Cohen's F is computed from ANOVA F-statistics via `effectsize::F_to_f` while the R2 difference is computed directly from the models. I don't know if these two computations are supposed to lead to the same results, or under what conditions ... – Ben Bolker Feb 21 '22 at 23:10

1 Answers1

0

@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.

Kiet
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31929002) – Waldi Jun 05 '22 at 11:06