mixed models in R do correctly not account for sampling weights
Should be: mixed models in R do *currently* not account for sampling weights
-----Urspr?ngliche Nachricht-----
Von: R-sig-mixed-models <r-sig-mixed-models-bounces at r-project.org> Im
Auftrag von d.luedecke at uke.de
Gesendet: Montag, 10. Juni 2019 17:31
An: 'Sam Crawley' <sam_crawley at warpmail.net>;
r-sig-mixed-models at r-project.org
Betreff: Re: [R-sig-ME] Predicted probabilites with CIs for multilevel
logistic regression with prior weights
Hi Sam,
you could the "ggeffects" package
(https://strengejacke.github.io/ggeffects/), and there is also an example
for a logistic mixed effects model
(https://strengejacke.github.io/ggeffects/articles/practical_logisticmixedmo
del.html), which might help you.
For binomial models, using weights often results in the following warning:
#> non-integer #successes in a binomial glm!
However, CIs for the predicted probabilities can be calculated nevertheless
(at least in my quick example). Note that afaik, mixed models in R do
correctly not account for sampling weights. However, Thomas Lumley, author
of the survey-package, works on a survey-function for mixed models
(https://github.com/tslumley/svylme), probably the GitHub version is quite
stable (haven't tested yet).
An alternative would be the "scale_weights()" function from the
sjstats-package
(https://strengejacke.github.io/sjstats/articles/mixedmodels-statistics.html
#rescale-model-weights-for-complex-samples ), which rescales sampling
weights so they can be used as "weights" for the mixed models function you
have in R (lme4, lme, ...).
Based on that function, I have a small example that demonstrates how to
compute predicted probabilities for mixed models with (sampling) weights
(ignore the warnings, this is just for demonstration purposes):
library(lme4)
library(sjstats) # for scale_weights() and sample data
library(ggeffects) # for ggpredict()
data(nhanes_sample)
set.seed(123)
nhanes_sample$bin <- rbinom(nrow(nhanes_sample), 1, prob = .3)
nhanes_sample <- scale_weights(nhanes_sample, SDMVSTRA, WTINT2YR)
m <- glmer(
bin ~ factor(RIAGENDR) * age + factor(RIDRETH1) + (1 | SDMVPSU),
family = binomial(),
data = nhanes_sample,
weights = svywght_a
)
ggpredict(m, c("age", "RIAGENDR")) %>% plot()
Best
Daniel
-----Urspr?ngliche Nachricht-----
Von: R-sig-mixed-models <r-sig-mixed-models-bounces at r-project.org> Im
Auftrag von Sam Crawley
Gesendet: Montag, 10. Juni 2019 10:36
An: r-sig-mixed-models at r-project.org
Betreff: [R-sig-ME] Predicted probabilites with CIs for multilevel logistic
regression with prior weights
Hello all,
I am doing a multilevel binomial logistic regression using lme4, and the
survey data I am using requires weights to be used. I would like to
calculate various predicted probabilities with confidence intervals based on
the estimated model. The predict function obviously doesn't give me standard
errors, and the recommended method to get these is to use the bootMer
function.
However, in my case, the weights provided are not integers, and the bootMer
function exits with an error if the weights are not integers (I raised a
GitHub issue about this, and was pointed to this list:
https://github.com/lme4/lme4/issues/524 ).
So my question is, what is the best way to calculate the predicted
probabilities (with confidence intervals) in my case?
I would appreciate any help you can give me, and I'm happy to provide more
details if required.
Thanks,
Sam Crawley.
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
--
_____________________________________________________________________
Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen
Rechts; Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard G?ke (Vorsitzender), Prof. Dr. Dr.
Uwe Koch-Gromus, Joachim Pr?l?, Marya Verdel
_____________________________________________________________________
SAVE PAPER - THINK BEFORE PRINTING
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
--
_____________________________________________________________________
Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard G?ke (Vorsitzender), Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Pr?l?, Marya Verdel
_____________________________________________________________________
SAVE PAPER - THINK BEFORE PRINTING