easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
232 stars 19 forks source link

estimate_contrasts with transform = "response" for a logistic model does not give estimates in terms of probabilities #215

Open ManuelSpinola opened 1 year ago

ManuelSpinola commented 1 year ago

When doing estimate_contrasts with transform = "response" for a logistic model the estimates are not in terms of probabilities like the help page said:

"Thus for a logistic model, "none" will give estimations expressed in log-odds (probabilities on logit scale) and "response" in terms of probabilities."

g <- glm(vs ~ factor(am), data = mtcars, family = binomial())

estimate_contrasts(g, contrast = "am", transform = "response")

Marginal Contrasts Analysis

Level1 | Level2 | Difference |        95% CI |   SE |  df |     z |     p
-------------------------------------------------------------------------
am0    |    am1 |      -0.69 | [-2.13, 0.74] | 0.73 | Inf | -0.95 | 0.344

Marginal contrasts estimated at am
p-value adjustment method: Holm (1979)
DominiqueMakowski commented 1 year ago

Can you update the package and check again? This works for me:

g <- glm(vs ~ factor(am), data = mtcars, family = binomial())

modelbased::estimate_contrasts(g, contrast = "am", transform = "response")
#> Marginal Contrasts Analysis
#> 
#> Level1 | Level2 | Odds ratio |       95% CI |   SE |  df |     z |     p
#> ------------------------------------------------------------------------
#> am0    |    am1 |       0.50 | [0.12, 2.10] | 0.37 | Inf | -0.95 | 0.344
#> 
#> Marginal contrasts estimated at am
#> p-value adjustment method: Holm (1979)

Created on 2022-10-16 by the reprex package (v2.0.1)

IndrajeetPatil commented 1 year ago

I really think we should be updating the CRAN version soon.

This issue keeps resurfacing here, and we keep asking users to update to the GitHub version.

DominiqueMakowski commented 1 year ago

yes right, I'll submit soon then (I'm testing some of the improvements)

ManuelSpinola commented 1 year ago

Thank you Dominique.

May be I am confused but I was expecting the difference in probabilities not in odds ratios, like the help says.

I can have the difference in probabilities using the emmeans package:

em <- emmeans(g, "am", type = "response") |> regrid()

pairs(em) contrast estimate SE df z.ratio p.value am0 - am1 -0.17 0.177 Inf -0.960 0.3370

El dom, 16 oct 2022 a las 2:47, Dominique Makowski (< @.***>) escribió:

Can you update the package and check again? This works for me:

g <- glm(vs ~ factor(am), data = mtcars, family = binomial()) modelbased::estimate_contrasts(g, contrast = "am", transform = "response")#> Marginal Contrasts Analysis#> #> Level1 | Level2 | Odds ratio | 95% CI | SE | df | z | p#> ------------------------------------------------------------------------#> am0 | am1 | 0.50 | [0.12, 2.10] | 0.37 | Inf | -0.95 | 0.344#> #> Marginal contrasts estimated at am#> p-value adjustment method: Holm (1979)

Created on 2022-10-16 by the reprex package https://reprex.tidyverse.org (v2.0.1)

— Reply to this email directly, view it on GitHub https://github.com/easystats/modelbased/issues/215#issuecomment-1279923541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFI3FBYJVRRHYHDZ7KJNCP3WDO6JVANCNFSM6AAAAAARFIHXWA . You are receiving this because you authored the thread.Message ID: @.***>

-- Manuel Spínola, Ph.D. Instituto Internacional en Conservación y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA @. @.> @.*** Teléfono: (506) 8706 - 4662 Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/index.php/manuel Blog sobre Ciencia de Datos: https://mspinola-ciencia-de-datos.netlify.app