[R-sig-ME] lme4 package

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Wed Jun 1 00:31:34 CEST 2022


  [please keep r-sig-mixed-models using r-project.org in the Cc: list; I 
really don't have the energy to engage in off-list consultations ...]

   If you have 240 subsets of predictor variables, they must be defined 
*somewhere*, either as a list that you've got already or in some 
programmatic way.  Again, this isn't a mixed-model-specific question ...

   How do you decide which subsets of the variables you're going to try? 
  (There aren't any obvious patterns in the examples you've given here.)

   Ben Bolker

On 2022-05-31 6:06 p.m., mina jahan wrote:
> 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, 1 Jun 2022 at 02:20, Ben Bolker <bbolker using gmail.com 
> <mailto: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
> 

-- 
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics



More information about the R-sig-mixed-models mailing list