Making a loop for lme() in r

后端 未结 3 951
死守一世寂寞
死守一世寂寞 2021-01-16 09:51

I am trying to use lme function from nlme package inside a for loop. I have tried (almost) everything now, but without any luck. Without the loop my lme function are working

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 10:40

    Without knowing your data, conceptually it should be sth like that

    df <- data.frame(lipid = rep(c(LETTERS[1:4]), each = 4), x1 = c(rnorm(16, 10, 1)), x2 = c(rnorm(16, 20, 5) ))
        df
    
    for (i in levels(df$lipid)){
      print(paste("MODEL", i, sep = ""))
      df1 = subset(df, lipid == i)
      model <- lm(x1~x2, data = df1 )
      print(summary(model)$coef)
    }
    

提交回复
热议问题