简体   繁体   English

用于重复测量的 Lmer

[英]Lmer for repeated measures

Here is an example of my dataset:这是我的数据集的示例:

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))

where,在哪里,

id = participant id = 参与者

collection_point = times data was collected from participant (repeated measure) collection_point = 从参与者收集数据的次数(重复测量)

intervention = group each participant was randomized to (fixed effect)干预 = 每个参与者被随机分配到的组(固定效应)

scale_A = questionnaire score that each participant completed at each data collection point (outcome) scale_A = 每个参与者在每个数据收集点完成的问卷分数(结果)

Participants were randomized to one of three interventions and completed the same scale (scale A) at three different time points to determine any improvements over time.参与者被随机分配到三种干预措施中的一种,并在三个不同的时间点完成相同的量表(量表 A),以确定随时间推移的任何改善。

To account for collection_point as a repeated measure, I originally did this:为了将collection_point作为重复测量,我最初是这样做的:

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

From what I've read, generally a variable isn't both a fixed and random effect, but I wasn't sure how else to specify collection_point as a repeated measure.从我读过的内容来看,通常一个变量不是固定效应和随机效应,但我不确定如何将collection_point指定为重复测量。 Also, when I run the model R says there's 500 observations.另外,当我运行模型时,R 说有 500 个观察值。 Which makes sense if you add all observations from baseline to 3M, but there are only 200 participants (some participants dropped out, hence fewer observations than expected).如果您将所有从基线到 3M 的观察结果相加,这是有道理的,但只有 200 名参与者(一些参与者退出,因此观察结果少于预期)。 So I'm thinking R isn't accounting for the fact that it's the same participants that repeated the questionnaire?所以我认为 R 没有考虑到重复问卷的参与者是同一个人这一事实?

I've also tried this:我也试过这个:

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

But I get an error message stating number of obs.但是我收到一条错误消息,指出 obs 的数量。 <= number of random effects. <= 随机效应的数量。

Lastly, I tried this but I'm not sure if this is the way to go about it either:最后,我尝试了这个,但我不确定这是否是解决问题的方法:

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

Any help would be greatly appreciated!任何帮助将不胜感激! I'm still learning R and have had some difficulty with lmer.我仍在学习 R 并且在使用 lmer 时遇到了一些困难。 Thanks!谢谢!

You have repeated measures within both a collection_point and id grouping (and it's also not balanced which will make plotting somewhat difficult.) (Note: the groupings are not independent, see the note at the bottom of this answer)您在collection_pointid分组中都有重复的度量(而且它也不平衡,这会使绘图有些困难。)(注意:分组不是独立的,请参阅此答案底部的注释)

It appears you are considering the intervention to be the fixed effect of interest.看来您正在考虑将intervention视为兴趣的固定效应。 Since you probably want any display of the collection points to be in the order that you presented it to the dataframe, you would need it to have a levels value and an ordered flag.由于您可能希望收集点的任何显示都按照您将其呈现给数据框的顺序进行,因此您需要它具有levels值和ordered标志。

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

For the model building consider this, and for authoritative consultation refer to BBolker's page on the subject: https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#model-definition模型搭建考虑这个,权威咨询参考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

Another option might be to build a model with both an intervention effect and a linear trend estimate across the ordered timings at the three collection points:另一种选择可能是构建一个模型,该模型在三个收集点的有序时序中既具有干预效应又具有线性趋势估计:

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

The last suggestion was made after trying to model collection point as a fixed effect but got both a linear and quadratic estimate (caused by the default handling of the ordered factor).最后一个建议是在尝试将收集点建模为固定效应后提出的,但得到了线性和二次估计(由有序因子的默认处理引起)。

It's also the case that you may only need the +(1|id) since no member of than id grouping participates in more than one series of collections:您可能只需要+(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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM