You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all. Firstly, thank you for your work and dedication on this package, it certainly has helped me immensely.
I have a question on an issue I recently encountered in my work using ggeffects.
I have a model with a log-transformed outcome variable. When trying to get predictions using the model, and later conducting hypothesis tests, I realized that while I could back-transform the predictions (via ggpredict) to the original scale, the same could not be done with the contrasts obtained via test_predictions.
I noticed that one could use the scale argument in test_predictions to exponentiate the contrasts, ie:
test_predictions(model, ..., scale = "exp")
But this seems to return the ratio of the predicted responses in each level of the categorical factor (ie pred1/pred2 with 95CIs), instead of the mean difference of the responses on the original scale (ie pred1 - pred2 with 95CIs). I was wondering if this was somehow possible inside of the ggeffects/marginaleffects framework.
A reproducible example follows using mtcars:
library(ggeffects); library(tidyverse)
dat<-mtcars|> mutate(am_cat= as.factor(am))
m2<- lm(log(disp) ~am_cat, dat)
# predictions on the log scale
ggpredict(m2, terms="am_cat", back_transform=FALSE)
#> Model has log transformed response. Predictions are on transformed#> scale.#> # Predicted values of disp#> #> am_cat | Predicted | 95% CI#> -------------------------------#> 0 | 5.59 | 5.38, 5.81#> 1 | 4.83 | 4.57, 5.09
test_predictions(m2, "am_cat")
#> # Pairwise comparisons#> #> am_cat | Contrast | 95% CI | p#> ---------------------------------------#> 0-1 | 0.76 | 0.42, 1.10 | < .001# predictions on the original response scale
ggpredict(m2, terms="am_cat", back_transform=TRUE)
#> Model has log-transformed response. Back-transforming predictions to#> original response scale. Standard errors are still on the transformed#> scale.#> # Predicted values of disp#> #> am_cat | Predicted | 95% CI#> -----------------------------------#> 0 | 268.60 | 216.77, 332.81#> 1 | 125.73 | 97.02, 162.93
test_predictions(m2, "am_cat", scale="exp") # this returns the ratio#> # Pairwise comparisons#> #> am_cat | Contrast | 95% CI | p#> ---------------------------------------#> 0-1 | 2.14 | 1.53, 2.99 | < .001#> #> Contrasts are presented on the exponentiated scale.# as shown by
ggpredict(m2, terms="am_cat", back_transform=TRUE)$predicted[1]/
ggpredict(m2, terms="am_cat", back_transform=TRUE)$predicted[2]
#> Model has log-transformed response. Back-transforming predictions to#> original response scale. Standard errors are still on the transformed#> scale.#> Model has log-transformed response. Back-transforming predictions to#> original response scale. Standard errors are still on the transformed#> scale.#> [1] 2.136294
Thank you. I was aware that back-transformed contrasts were possible in emmeans using the "regrid" function, but it's very handy to know that the emmeans engine seems to achieve this as well.
Hello all. Firstly, thank you for your work and dedication on this package, it certainly has helped me immensely.
I have a question on an issue I recently encountered in my work using ggeffects.
I have a model with a log-transformed outcome variable. When trying to get predictions using the model, and later conducting hypothesis tests, I realized that while I could back-transform the predictions (via ggpredict) to the original scale, the same could not be done with the contrasts obtained via test_predictions.
I noticed that one could use the scale argument in test_predictions to exponentiate the contrasts, ie:
test_predictions(model, ..., scale = "exp")
But this seems to return the ratio of the predicted responses in each level of the categorical factor (ie pred1/pred2 with 95CIs), instead of the mean difference of the responses on the original scale (ie pred1 - pred2 with 95CIs). I was wondering if this was somehow possible inside of the ggeffects/marginaleffects framework.
A reproducible example follows using mtcars:
Created on 2024-10-28 with reprex v2.1.1
Thank you.
The text was updated successfully, but these errors were encountered: