用于重复测量的 Lmer

Lmer for repeated measures

这是我的数据集的示例:

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 时遇到了一些困难。谢谢!

您在 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