Multivariate Linear Mixed Model in lme4

后端 未结 3 1588
挽巷
挽巷 2021-01-31 05:57

I wonder how to fit multivariate linear mixed model with lme4. I fitted univariate linear mixed models with the following code:

library(lme4)
lmer.m         


        
3条回答
  •  庸人自扰
    2021-01-31 06:51

    @John's answer above should be largely right. You add a dummy variable (ie--the factor variable Y) to the model. Here you have 3 subscripts i= 1...N for observations, j=1,...,4 for blocks, and h=1,2 for the dependent var. But you also need to force the level 1 error term to 0 (or to near zero), which I'm not sure lme4 does. Ben Bolker might provide more information. This is described more in Goldstein (2011) Chap 6 and Chap 7 for latent multivariate models.

    IE

    Y_hij = \beta_{01} z_{1ij} + \beta_{02} z_{2ij} + \beta X + u_{1j} z_{1ij} + u_{2j} z_{2ij}

    So:

    require(reshape2)
    Data = melt(data, id.vars=1:3, variable_name='Y')
    Data$Y = factor(gsub('Y(.+)', '\\1', Data$Y))
    
    m1 <- lmer(value ~ Y + A*B + (1|Block) + (1|Block*A), data= Data)
    # not sure how to set the level 1 variance to 0, @BenBolker
    # also unclear to me if you're requesting Y*A*B instead of Y + A*B
    

提交回复
热议问题