How do I extract lmer fixed effects by observation?

前端 未结 2 1635
时光说笑
时光说笑 2021-02-03 14:45

I have a lme object, constructed from some repeated measures nutrient intake data (two 24-hour intake periods per RespondentID):

Male.lme2 <- lmer(BoxCoxXY ~          


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 15:23

    It is going to be something like this (although you really should have given us the results of str(Male.Data) because model output does not tell us the factor levels for the baseline values:)

    #First look at the coefficients
    fixef(Male.lme2)
    
    #Then do the calculations
    fixef(Male.lme2)[`(Intercept)`] + 
    c(0,fixef(Male.lme2)[2:4])[
              match(Male.Data$AgeFactor, c("1to3", "4to8", "9to13","14to18") )] + 
    c(0,fixef(Male.lme2)[5])[
              match(Male.Data$IntakeDay, c("Day1Intake","Day2Intake") )]
    

    You are basically running the original data through a match function to pick the correct coefficient(s) to add to the intercept ... which will be 0 if the data is the factor's base level (whose spelling I am guessing at.)

    EDIT: I just noticed that you put a "-1" in the formula so perhaps all of your AgeFactor terms are listed in the output and you can tale out the 0 in the coefficient vector and the invented AgeFactor level in the match table vector.

提交回复
热议问题