我正在尝试使用BayesFactor
R 中的包计算其中一个固定效应的贝叶斯因子(BF)。
数据结构如下:
rating
是因变量cond
"A"
是具有 3 个水平 ( ,"B"
,"C"
) 的自变量C1
cond
是从与"A"
(coded-0.50
)"B"
和"C"
(both coded-0.25
)对应的对比码派生而来的对比码C2
是从(coded ) 到(coded ; 并且是 codedcond
)派生的对比码"B"
-0.50
"C"
+0.5
"A"
0
judge
和face
是随机因素,因此face
与交叉judge
但嵌套在其中cond
(因此也嵌套在C1
and中C2
)
DT <- fread("http://matschmitz.github.io/dataLMM.csv")
DT[, judge := factor(judge)]
DT[, face := factor(face)]
# > DT
# judge face cond C1 C2 rating
# 1: 66 13 A -0.50 0.0 1
# 2: 20 13 A -0.50 0.0 4
# 3: 22 13 A -0.50 0.0 7
# 4: 69 13 A -0.50 0.0 1
# 5: 7 13 A -0.50 0.0 3
# ---
# 4616: 45 62 C 0.25 0.5 2
# 4617: 30 62 C 0.25 0.5 6
# 4618: 18 62 C 0.25 0.5 4
# 4619: 40 62 C 0.25 0.5 3
# 4620: 65 62 C 0.25 0.5 1
理想情况下,我想测试“完整”模型,如下所示:
library(lmerTest)
lmer(rating ~ C1 + C2 + (1 + C1 + C2|judge) + (1|face), data = DT)
并计算 BF C1
。
我设法计算了BF,C1
但仅使用随机截距:
library(BayesFactor)
BF1 <- lmBF(rating ~ C1 + C2 + judge + face, whichRandom = c("judge", "face"), data = DT)
BF0 <- lmBF(rating ~ C2 + judge + face, whichRandom = c("judge", "face"), data = DT)
BF10 <- BF1 / BF0
# > BF10
# Bayes factor analysis
# --------------
# [1] C1 + C2 + judge + face : 0.4319222 ±15.49%
#
# Against denominator:
# rating ~ C2 + judge + face
# ---
# Bayes factor type: BFlinearModel, JZS
我尝试了这个解决方案以包括随机斜率但没有成功:
BF1 <- lmBF(rating ~ C1 + C2 + judge + face + C1:judge + C2:judge,
whichRandom = c("judge", "face", "C1:judge", "C2:judge"), data = DT)
# Some NAs were removed from sampling results: 10000 in total.
我还需要包括(如果可能的话)随机截距和斜率之间的相关性judge
。
请随时在您的答案中使用任何其他包(例如,,)rstan
。bridgesampling
一些额外的问题:
- 我是否需要对 BF10 进行任何转换,或者我可以将其解释为它吗?
- 什么是默认先验?