This is a test version of Biostars. For the public version, visit https://www.biostars.org.
linear mixed model - metabolomics

Hi

I want to run following linear mixed model, for each metabolite in my dataset where I hace fixed effects gender and timepoint, and random effect the person_id.

For each metabolite seperately, the code works, but if I put it in this for loop, it gives following error:

Error in model.frame.default(data = sample_df_M, drop.unused.levels = TRUE,  : 
  variable lengths differ (found for 'gender')

Is there another way ? Because the code does work if i use the first metabolite, which is Valine (Val) , then I get the output. As soon as I put it in the for loop, it gives the error.

library("lme4")
metabolites <- colnames(metab.matrix)
for (m in metabolites) {
  out <- lmer(m ~ gender+ month+ (1|person_id), data=sample_df_M)
  out0 <- lmer(m ~ (1|person_id), data = sample_df_M)
  comp <- anova(out0, out)
  pv <- comp[["Pr(>Chisq)"]][[2]]
  print(pv)
}

thank you in advance!

lme4 linearmixedmodel metabolomics

Do all metabolites fail in the for loop execution or just specific metabolites? What happens when you run the loop with just valine in the metabolites vector? Does it still work? This would test whether or not the issue is related to any modifications you made specifically for the for loop execution.

The error message sounds like the length of m and gender differ but not too sure...

0 answers

No answers yet.

Log in to answer this question.