我希望在因变量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")
每个Participant
每Condition
次Timepoint
执行两次试验,如Measure
所示;但是,缺少数据,因此每个参与者不一定有12个级别。列xVarCondition
只是一个虚拟变量,它包含条件中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
是否正确指定了随机效果?
答案 0 :(得分:1)
我无法从您的说明中说出来,但很可能您的Participant:xVarCondition:Measure
术语构建了一个分组变量,在每个分类级别中只有一个以上的观察值,这将使{{1带有剩余误差项的术语冗余,它始终包含在(1|Participant:xVarCondition:Measure)
模型中。如果你真的想通过包含
lmer
在您的函数调用中,但(如果我已正确诊断出问题),这将导致残差方差和control=lmerControl(check.nobs.vs.nlev = "ignore")
方差无法识别。这种不可识别性通常不会导致模型的其他部分出现任何问题,但我对可识别的模型更为满意(这种不可识别性总会导致数值问题)。
有一个类似的例子here。
您可以按如下方式检查我的猜想:
Participant:xVarCondition:Measure