Loop lapply mixed linear model assessing groups effect over time

Viewed 11

I'm trying to assess the effect of variables (e.g. presence of severe trauma) on energy expenditure (=REE) levels over time (Day).

Following I would like to display the results using the mixed linear model for each assessed variable in one large table. I'm currently using the following code:

library(tidyverse)
library(ggpmisc)
library(sjPlot)
library(lme4)

my_data %>%
lm_models <- lapply(10:54, function(x) {lmer(REE ~ (1|my_data[,x]) + Day, data=my_data)})
tab_model(lm_models,
          show.se = TRUE, 
          show.std = TRUE, 
          show.stat = TRUE,
          show.ci=TRUE,
          show.p=TRUE,
          col.order=c("p"),
          auto.label = FALSE,)

However, I get the following message in the console on my lapply function:

Error: couldn't evaluate grouping factor my_data[, x] within model frame:error =Error in .subset(x, j) : invalid subscript type 'language'
Try adding grouping factor to data frame explicitly if possible

Any idea on how to adapt the function to resolve this issue?

Thanks!

0 Answers
Related