Skip to content
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

get_predicted confidence intervals in mixed-effects models #677

Open
vincentarelbundock opened this issue Nov 3, 2022 · 12 comments
Open
Labels
docs 📚 Something to be adressed in docs and/or vignettes what's your opinion 🙉 Collectively discuss something

Comments

@vincentarelbundock
Copy link
Contributor

vincentarelbundock commented Nov 3, 2022

At the moment, confidence intervals around predicted values for lmerMod only take into account the fixed effects.

For example, in a model with Chick-level random intercepts and coefficients, each Chick will have intervals of the exact same width at every time point:

library(lme4)
library(insight)

fit1 <- lmer(
  weight ~ 1 + Time + (1 + Time | Chick),
  data = ChickWeight)

get_predicted(fit1, ci = .95) |> 
    cbind(ChickWeight) |>
    within({CI_width = CI_high - CI_low}) |>
    subset(Time == 4, select = "CI_width") |>
    table()
#> CI_width
#>  4.1810057846375 4.18100578463751 
#>                5               44

I was chatting with @ASKurz and we were wondering if this is what most users would expect/want. In particular, it seems like many would want the random components to be accounted for in the computation. Should we supply CIs at all, issue a warning, or is the status quo just fine?

Curious what everyone thinks (and maybe especially @bwiernik )

@ASKurz
Copy link

ASKurz commented Nov 3, 2022

Speaking for myself, the current behavior is not what I would have hoped for and I like the options Vincent suggested.

@bwiernik
Copy link
Contributor

bwiernik commented Nov 3, 2022

Definitely would prefer for the uncertainty due to random effects to be included. But I think this might be a limitation of lme4? I think maybe if we did bootstrap intervals it might work?

@bwiernik
Copy link
Contributor

bwiernik commented Nov 3, 2022

Because the clever linear algebra tricks that lme4 uses, I don't think it's feasible to get correlations between fix effect and random effect estimates in this package. (They could be obtained in glmmTMB but currently aren't provided because they are computationally expensive).

We should probably add a message saying that these default intervals don't include uncertainty due to random effects. And then we can recommend using ci_method = "boot" as an alternative?

@ASKurz
Copy link

ASKurz commented Nov 3, 2022

How computationally expensive are we talking in the glmmTMB case?

@strengejacke
Copy link
Member

One possible way is following Ben's suggestion of adding sigma/random effect variances before computing SE for predictions:

https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#predictions-andor-confidence-or-prediction-intervals-on-predictions

@strengejacke
Copy link
Member

Or we look at merTools::predictInterval(), but I think it's limited to few families only?

@vincentarelbundock
Copy link
Contributor Author

Re: bootstrap

I played around with some ideas and didn't come out reassured. My guess is that a good handling of the nested structure of the data will require something fancy. We probably don't want to give the user the impression that a plain-vanilla approach will give great results by giving them a ci_method.

Re: Bolker

He sounds lukewarm about all of these solutions, and ends up recommending Bayes. Seems like a lot of work to implement for a suboptimal result... might be best to just remove CIs or issue a warning.

Re: predictInterval

Those are prediction intervals, not confidence, right?

@bwiernik
Copy link
Contributor

bwiernik commented Nov 5, 2022

@ASKurz see glmmTMB/glmmTMB#691

@strengejacke strengejacke added docs 📚 Something to be adressed in docs and/or vignettes what's your opinion 🙉 Collectively discuss something labels Nov 9, 2022
@strengejacke
Copy link
Member

Re: bootstrap

I played around with some ideas and didn't come out reassured. My guess is that a good handling of the nested structure of the data will require something fancy. We probably don't want to give the user the impression that a plain-vanilla approach will give great results by giving them a ci_method.

I think lme4::bootMer() takes RE structures into account.

Re: Bolker

He sounds lukewarm about all of these solutions, and ends up recommending Bayes. Seems like a lot of work to implement for a suboptimal result... might be best to just remove CIs or issue a warning.

Re: predictInterval

Those are prediction intervals, not confidence, right?

Ok, you were thinking about some bias adjustment?

@mattansb
Copy link
Member

I think lme4::bootMer() takes RE structures into account.

image

use.u = FALSE, type = "parameteric" are the default.

@bwiernik
Copy link
Contributor

Yep, you're right. lme4::bootMer() should give what we are looking for

@bbolker
Copy link
Contributor

bbolker commented Sep 26, 2023

See lme4/lme4#739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs 📚 Something to be adressed in docs and/or vignettes what's your opinion 🙉 Collectively discuss something
Projects
None yet
Development

No branches or pull requests

6 participants