在R公式中(|)语法是什么意思?

在R公式中(|)语法是什么意思?,r,lme4,r-formula,R,Lme4,R Formula,我正在学习一个教程,遇到了以下语法: # assume 'S' is the name of the subjects column # assume 'X1' is the name of the first factor column # assume 'X2' is the name of the second factor column # assume 'X3' is the name of the third factor column # assume 'Y' is the nam

我正在学习一个教程,遇到了以下语法:

# assume 'S' is the name of the subjects column
# assume 'X1' is the name of the first factor column
# assume 'X2' is the name of the second factor column
# assume 'X3' is the name of the third factor column
# assume 'Y' is the name of the response column
# run the ART procedure on 'df'

# linear mixed model syntax; see lme4::lmer
m = art(Y ~ X1 * X2 * X3 + (1|S), data=df) 

anova(m)
我对
(|)
语法有点困惑。我查看了线性混合模型语法的文档,发现: “随机效应项通过垂直条
(|)
将设计矩阵的表达式与分组因子分开来区分”


所以我假设
1
S
这里有两个随机效应项
S
作为一种随机效应是有意义的,因为它是一个可以代表参与者的随机变量。但是
1
是一个随机变量吗?这里的
1
|
是什么意思?

符号在公式中以不同的方式在不同的函数中使用。对于线性混合模型,其用于表示随机效应。混合模型中可以使用不同类型的随机效应:

  • 随机截距,截距(但不是斜率)在受试者之间变化
  • 随机斜率,其中斜率(但不是截距)在受试者之间变化
  • 随机斜率和截距,两者在受试者之间有所不同。坡度和截距可以建模为相关或不相关
公式中的
1
用于指定使用哪一个。以下是:

库(lme4)
#随机截获:

m1这篇文章可能会解释
1
explicit intercept:我也明白了,谢谢!(很荣幸得到您的回复,我在过去多次参考您的教科书:))
library(lme4)
# Random intercept:
m1 <- lmer(Reaction ~ Days + (1|Subject), data = sleepstudy)

# Random slope:
m2 <- lmer(Reaction ~ Days + (0 + Days|Subject), data = sleepstudy)

# Correlated random intercept and slope:
m3 <- lmer(Reaction ~ Days + (1 + Days|Subject), data = sleepstudy)

# Uncorrelated random intercept and slope:
m4 <- lmer(Reaction ~ Days + (1|Subject) + (0 + Days|Subject),
           data = sleepstudy)