【发布时间】:2016-06-16 01:22:46
【问题描述】:
我希望在因变量 DV 上运行线性混合模型,该变量收集在两个不同的 Condition 和三个不同的 Timepoint 下。数据结构如下:
## dput(head(RawData,5))
structure(list(Participant = structure(c(2L, 2L, 2L, 2L, 4L),
.Label = c("Jessie", "James", "Gus", "Hudson", "Flossy",
"Bobby", "Thomas", "Alfie", "Charles", "Will", "Mat", "Paul", "Tim",
"John", "Toby", "Blair"), class = "factor"),
xVarCondition = c(1, 1, 0, 0, 1),
Measure = structure(c(1L, 2L, 3L, 4L, 1L),
.Label = c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12"), class = "factor"),
Sample = structure(c(1L, 2L, 1L, 2L, 1L),
.Label = c("1", "2"), class = "factor"),
Condition = structure(c(2L, 2L, 1L, 1L, 2L),
.Label = c("AM", "PM"), class = "factor"),
Timepoint = structure(c(2L, 2L, 2L, 2L, 1L),
.Label = c("Baseline", "Mid", "Post"), class = "factor"),
DV = c(83.6381348645853, 86.9813802115179, 69.2691666620429,
71.3949807856125, 87.8931998204771)),
.Names = c("Participant", "xVarCondition", "Measure",
"Sample", "Condition", "Timepoint", "DV"),
row.names = c(NA, 5L), class = "data.frame")
如Measure 所示,每个Participant 在三个Timepoints 中每个Condition 执行两次试验;但是,缺少数据,因此不一定每个参与者有 12 个级别。 xVarCondition 列只是一个虚拟变量,其中 Condition 中的每个 AM 条目都包含一个 1。 Sample 列是指每个 Condition 在每个 Timepoint 的 2 次试验。
我是 R 用户,但统计学家是 SAS 用户,他认为模型的代码应该是:
proc mixed data=RawData covtest cl alpha=α
class Participant Condition Timepoint Measure Sample;
model &dep=Condition Timepoint/s ddfm=sat outp=pred residual noint;
random int xVarCondition xVarCondition*TimePoint*Sample
TimePoint/subject=Participant s;
上面的 SAS 代码给出了合理的答案并且运行良好。我们相信上述模型的 lme4 语法是:
TestModel = lmer(DV ~ Condition + Timepoint +
(1 | Participant/Timepoint) +
(0 + xVarCondition | Participant) +
(1 | Participant:xVarCondition:Measure), data = RawData)
但是,运行此模型时出现以下错误:
Error: number of levels of each grouping factor must be < number of observations
是否正确指定了随机效应?
【问题讨论】:
-
我注意到您的固定效应
Condition和Timepoint都是因素。您确定混合线性模型是这种情况下的最佳方法吗?另外,我不明白xVarCondition和Condition之间的区别。 -
我相信线性混合模型是合适的,因为我们对参与者内部和参与者之间的变化感兴趣。 xVarCondition 只是一个虚拟变量,每次参与者完成 AM 条件时为 1。
标签: r sas lme4 mixed-models