【问题标题】:Lmer for repeated measures用于重复测量的 Lmer
【发布时间】:2021-12-15 08:39:56
【问题描述】:

这是我的数据集的一个示例:

df <- data.frame(
id  = c(13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 
           34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 
           19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
           40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
           29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65), 
collection_point       = c(rep(c("Baseline", "Immediate", "3M"), each=28)), 
intervention = c(rep(c("B", "A", "C", "B", "C", "A", "A", "B", "A", "C", "B", "C", 
                  "A", "A", "B", "A", "C", "B", "C", "A", "A"), each = 4)), 
scale_A       = c(6.5, 7.0, 6.25, 6.0, NA, 7.5, 7.5, 
            8.0, 7.5, 6.75, 7.5, 6.75, 6.75, 6.5, 
            5.75, 6.75, 7.75, 7.5, 7.75, 7.25, 7.75, 
            7.25, 7.25, 5.75, 6.75, NA, 6.75, 7.5, 
            6.75, 7.0, 6.5, 7.0, 7.5, 7.5, 7.5, 
            7.75, 7.25, 7.25, 7.25, 7.5, 6.5, 6.25, 
            6.25, 7.25, 7.5, 6.75, 7.25, 7.25, 7.5, 
            7.25, 7.5, 7.25, NA, 7.0, 7.5, 7.5, 
            6.75, 7.25, 6.5, 7.0, 7.5, 7.5, 7.5, 
            7.75, 7.5, 7.5, 7.5, 7.5, 6.5, 5.75, 
            6.25, 6.75, 7.5, 7.25, 7.25, 7.5, 7.75, 
            7.75, 7.75, 7.5, NA, NA, NA, NA))

在哪里,

id = 参与者

collection_point = 从参与者那里收集数据的次数(重复测量)

干预 = 每个参与者被随机分配到的组(固定效应)

scale_A = 每个参与者在每个数据收集点完成的问卷分数(结果)

参与者被随机分配到三种干预措施中的一种,并在三个不同的时间点完成相同的量表(量表 A),以确定随着时间的推移是否有任何改进。

为了将collection_point作为重复测量,我最初是这样做的:

mixed.lmer.A<-lmer(scale_A~intervention+collection_point+intervention*collection_point+(1|collection_point), data = df)

根据我的阅读,通常变量既不是固定效应也不是随机效应,但我不确定如何将collection_point 指定为重复测量。另外,当我运行模型时,R 说有 500 个观察值。如果您将所有观察结果从基线添加到 3M,这是有道理的,但只有 200 名参与者(一些参与者退出,因此观察结果比预期的要少)。所以我认为 R 没有考虑到重复问卷的参与者是同一个人?

我也试过这个:

mixed.lmer.A2<-lmer(scale_A~intervention+collection_point+intervention*collection_point+(1+collection_point|id), data = df)

但我收到一条错误消息,说明 obs 的数量。

最后,我尝试了这个,但我不确定这是否是解决方法:

mixed.lmer.A3<-lmer(scale_A~intervention+collection_point+intervention*collection_point+(1|collection_point/id), data = df)

任何帮助将不胜感激!我仍在学习 R 并且在使用 lmer 时遇到了一些困难。谢谢!

【问题讨论】:

    标签: r lme4


    【解决方案1】:

    您在 collection_pointid 分组中重复测量(而且它也不平衡,这会使绘图有些困难。)(注意:分组不是独立的,请参阅此答案底部的注释)

    您似乎正在考虑将intervention 视为感兴趣的固定效应。由于您可能希望收集点的任何显示都按照您将其呈现给数据框的顺序显示,因此您需要它具有 levels 值和 ordered 标志。

     collection_point = factor( c(rep(c("Baseline", "Immediate", "3M"), each=28)), 
                              levels=c("Baseline", "Immediate", "3M"), ordered=TRUE)
    

    对于模型构建考虑这个,权威咨询请参考BBolker关于这个主题的页面:https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#model-definition

    > mixed.lmer.A1<-lmer(scale_A~intervention+(1|id) +(1|collection_point), data = df)
    > summary(mixed.lmer.A1)
    Linear mixed model fit by REML ['lmerMod']
    Formula: scale_A ~ intervention + (1 | id) + (1 | collection_point)
       Data: df
    
    REML criterion at convergence: 70.4
    
    Scaled residuals: 
        Min      1Q  Median      3Q     Max 
    -3.9506 -0.3416  0.1162  0.5891  1.4978 
    
    Random effects:
     Groups           Name        Variance Std.Dev.
     id               (Intercept) 0.042109 0.20521 
     collection_point (Intercept) 0.008454 0.09195 
     Residual                     0.099734 0.31581 
    Number of obs: 77, groups:  id, 28; collection_point, 3
    
    Fixed effects:
                  Estimate Std. Error t value
    (Intercept)    7.38963    0.10002  73.880
    interventionB -0.81671    0.12886  -6.338
    interventionC -0.04588    0.12886  -0.356
    
    Correlation of Fixed Effects:
                (Intr) intrvB
    interventnB -0.558       
    interventnC -0.558  0.433
    

    另一种选择可能是建立一个模型,该模型在三个收集点的有序时间范围内具有干预效果和线性趋势估计:

    mixed.lmer.inter.trend <- lmer(scale_A~intervention+as.numeric(collection_point)+
             (1|id), 
                   data = df)
    

    最后一个建议是在尝试将收集点建模为固定效应但同时得到线性和二次估计(由有序因子的默认处理引起)之后提出的。

    您也可能只需要+(1|id),因为没有比 id 分组的成员参与多个系列的集合:

    with(df, table( collection_point, id))
                    id
    collection_point 13 14 15 16 17 18 19 20 21 22 23 24 29 30 31 32 33 34 35 36 37 38 39 40 62 63 64 65
           Baseline   1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
           Immediate  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
           3M         1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
    

    【讨论】:

    • 感谢您的建议!你的第一个建议和mixed.lmer.A1&lt;-lmer(scale_A~intervention+(collection_point|id), control = lmerControl(check.nobs.vs.nRE = "ignore"), data = df) 有什么区别?
    • 第一个模型不会计算 collection_points 效应的估计值。第二个确实如此,但这意味着基线到即时的更改与从即时到 3M 的更改相同。如果这不合理,那么您将需要一个更复杂的模型。我试过lmer(scale_A~intervention + collection_point +(1|id), data = df),它既有线性项又有二次项。二次项很小,所以我认为线性模型可能信息丰富且更易于理解。
    猜你喜欢
    • 2020-04-13
    • 2013-02-14
    • 2012-09-26
    • 1970-01-01
    • 2021-09-08
    • 2021-09-07
    • 2021-01-05
    • 2015-07-14
    • 2014-12-08
    相关资源
    最近更新 更多