[R-sig-ME] lme4 package
mina jahan
m|n@j@h@ng|r|984 @end|ng |rom gm@||@com
Wed Jun 1 00:17:15 CEST 2022
Dear Ben,
Thank you for your response. This code is very useful.
My data file contains 1000 predictor variables and I should run lmer model
with different subsets of predictor variables (e.g. a model with 5
predictor variables, a model with 7 predictor variables, ...). I use your
code to define subsets of the predictor variables.
"var_combs <- list(model1 = c("X1", "X7"),model2 = c("X2", "X3",
"X12"),model3 = c("X4", "X8", "X9", "X11"))"
But this code will be too long for 240 subsets of predictor variables. Is
there a remedial to solve this problem?
Best regards,
Mina
On Wed, Jun 1, 2022, 2:20 AM Ben Bolker <bbolker using gmail.com> wrote:
> This is not a particularly mixed-model-specific question. The
> general approach would be something like:
>
> var_combs <- list(model1 = c("X1", "X7"),
> model2 = c("X2", "X3", "X12"),
> model3 = c("X4", "X8", "X9", "X11"),
> ## etc.)
>
> (I don't know the logic behind your choice of combinations of predictors
> so can't automate it any further)
>
> Then:
>
> results <- list()
> for (m in names(var_combs)) {
> form <- reformulate(c(var_combs[[m]], "(1|group)"), response = "Y")
> fit <- lmer(form, data = ..., ....)
> results[[m]] <- fit
> }
>
> This assumes that the random-effects component is only variation in
> the intercept across `group`.
>
> There are a huge variety of alternatives -- you could use lapply() or
> purrr::map() instead of a for loop, do something to parallelize the fits
> across cores, etc. etc..
>
> On 2022-05-31 4:38 p.m., mina jahan wrote:
> > Hi,
> > I want to run linear mixed-effects models based on the different subsets
> of
> > predictor variables (the outcome variable in each model is similar) using
> > package lme4. For example, a dataset contains a Y as a longitudinal
> outcome
> > variable and X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, and X12 as
> > predictor variables. I want to create a loop to run these models:
> > Y~X1+X7
> > Y~X2+X3+X12
> > Y~X4+X8+X9+X11
> > Y~X5+X6+X10
> >
> > Please guide me.
> >
> > Best regards,
> > Mina
> >
> > [[alternative HTML version deleted]]
> >
>
> --
> Dr. Benjamin Bolker
> Professor, Mathematics & Statistics and Biology, McMaster University
> Director, School of Computational Science and Engineering
> (Acting) Graduate chair, Mathematics & Statistics
>
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list