-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggpredict shows inaccurate results for models based on lme #297
Comments
Do you have a reproducible example? This one, e.g. works: library(ggeffects)
library(nlme)
m <- lme(
distance ~ age, data = Orthodont,
random = ~ 1 | Sex)
ggpredict(m, "age")
#> # Predicted values of distance
#>
#> age | Predicted | 95% CI
#> --------------------------------
#> 8 | 21.84 | [19.46, 24.21]
#> 10 | 23.16 | [20.85, 25.47]
#> 12 | 24.48 | [22.17, 26.79]
#> 14 | 25.80 | [23.42, 28.17]
#>
#> Adjusted for:
#> * Sex = 0 (population-level)
plot(ggpredict(m, "age")) Created on 2023-03-21 with reprex v2.0.2 |
Dear S, I am using a dataset in a controlled environment which cannot be exported. However this dataset is very close to the issue I experienced. This is my example, library(lme4) LME_Model <- dlply(Soybean, preds <- purrr::map(LME_Model , ggplot(preds, aes(x=x, y=predicted, |
From your example, I can't see any error with lme. Can you elaborate a bit more on which error you experience? |
Sorry if this is the wrong issue to add this reprex... ggpredict does not provide confidence intervals for gamlss model (which is calling nlme::lme) but sjPlot:: does provide confidence intervals. library(tidyverse)
library(palmerpenguins)
library(gamlss)
library(broom)
library(sjPlot)
library(ggeffects)
library(broom.mixed)
# add proportion outcome, drop NAs
penguins <-
penguins |>
mutate(prop = rBE(nrow(penguins), mu = 0.5, sigma = 0.2)) |>
drop_na() |>
droplevels()
# fit model
mod <-
gamlss::gamlss(prop ~ sex*body_mass_g + year + re(random = list(~1 | species, ~1 | island))
, family = BE()
, data = penguins)
# examine outputs
# broom
mod |> broom.mixed::tidy(conf.int = TRUE) # nice confidence intervals (CIs), some warnings
# sjPlot
mod |> sjPlot::plot_model() # CIs present, no warnings
mod |> sjPlot::tab_model() # CIs present, no warnings
# ggeffects
mod |> ggeffects::ggpredict() # warnings and no CIs
mod |> ggeffects::ggpredict(terms = c('sex', 'body_mass_g')) # warnings and no CIs
mod |> ggeffects::ggeffect(terms = c('sex', 'body_mass_g')) # warnings and no output
mod |> ggeffects::ggemmeans(terms = c('sex', 'body_mass_g')) # warnings and no output
# end. |
I think the issue is that standard errors for coefficients are returned, but not for predictions. That's why |
Thank you. The last line is calling ggpmeans. An additional issue I have noticed is that the tab_model() seems to be using exp() on the estimates, but the link function is logit (not log). I therefore think the appropriate transformation is the inverse logit like inv_logit <- function(p) exp(p) / (1 + exp(p)) summary(mod) #shows the mu intercept is 9.080e+00 mod |> sjPlot::tab_model() # produces 8774.88 but same for the other intercept (sigma) Maybe this is an error? Wrong transformation? |
I'm not sure about the But for coefficients, like in logistic regression, where we also have a logit-link, the coefficients are also reported as I also tried packages emmeans and marginaleffects, but no success. Pinging @vincentarelbundock for marginaleffects. |
Personally, I would just use |
Thanks. marginaleffects looks fantastic! marginaleffects::avg_comparisons(mod, what = 'mu') Given the repex, that Error is unexpected and I'm not sure how best to resolve it. |
Thanks for testing it @DHLocke . You found a bug and I just fixed it in the development version of the package. You’ll find instructions for installation and an example at this separate issue, which I opened to discuss |
Thanks so much and sorry for submitting the error to the wrong place. |
see the other thread for a response |
There is a flaw in this ggeffects library.
ggeffect shows erroneous and incorrect results if you try to predict values using estimates from lme model from nlme package.
However if you use lme4 instead of lme, everything works fine.
The x-axis labels are not accurate. the x-axis lables are marked 1,2,3....n observation number instead of actual x values.
The text was updated successfully, but these errors were encountered: