【问题标题】:How to replicate random effects in lme4 from SAS?如何从 SAS 复制 lme4 中的随机效应?
【发布时间】: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

是否正确指定了随机效应?

【问题讨论】:

  • 我注意到您的固定效应ConditionTimepoint 都是因素。您确定混合线性模型是这种情况下的最佳方法吗?另外,我不明白xVarConditionCondition 之间的区别。
  • 我相信线性混合模型是合适的,因为我们对参与者内部和参与者之间的变化感兴趣。 xVarCondition 只是一个虚拟变量,每次参与者完成 AM 条件时为 1。

标签: r sas lme4 mixed-models


【解决方案1】:

我无法从您的描述中完全看出,但很可能您的 Participant:xVarCondition:Measure 术语构造了一个分组变量,该变量在每个分类级别中不超过一个观察值,这将使 (1|Participant:xVarCondition:Measure) 术语与lmer 模型中始终包含的残差项。如果你真的想通过包含来覆盖错误,你可以覆盖

control=lmerControl(check.nobs.vs.nlev = "ignore")

在您的函数调用中,但是(如果我已正确诊断问题)这将导致剩余方差和 Participant:xVarCondition:Measure 方差共同无法识别。这种不可识别性通常不会对模型的其余部分造成任何问题,但我更喜欢可识别的模型(这种不可识别性总是有可能导致数值问题)。

有一个类似的例子here

你可以检查我的猜想如下:

ifac <- with(RawData,
   interaction(Participant,xVarCondition,Measure,drop=TRUE))
length(levels(ifac)) == nrow(RawData)

【讨论】:

  • 感谢您提供类似的示例,即使我尝试覆盖错误,我仍然会收到错误消息。我是否能够指定随机效应以使其与 SAS 中的模型相匹配?它在 SAS 中运行平稳,答案合理。
  • 你可以试试 r-sig-mixed-models@r-project.org(我今天可能没时间)。 reproducible example 也会有所帮助
猜你喜欢
  • 2020-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-21
  • 1970-01-01
  • 2019-09-19
相关资源
最近更新 更多