2

我正在尝试使用BayesFactorR 中的包计算其中一个固定效应的贝叶斯因子(BF)。

数据结构如下:

  • rating是因变量

  • cond"A"是具有 3 个水平 ( , "B", "C") 的自变量

  • C1cond是从与"A"(coded -0.50)"B""C"(both coded -0.25)对应的对比码派生而来的对比码

  • C2是从(coded ) 到(coded ; 并且是 coded cond)派生的对比码"B"-0.50"C"+0.5"A"0

  • judgeface是随机因素,因此face与交叉judge但嵌套在其中cond(因此也嵌套在C1and中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

请随时在您的答案中使用任何其他包(例如,,)rstanbridgesampling


一些额外的问题:

  • 我是否需要对 BF10 进行任何转换,或者我可以将其解释为它吗?
  • 什么是默认先验?
4

1 回答 1

0

协变量必须是一个“因素”。在你的情况下,不仅仅是“法官”、“面孔”、“C1”和“C2”也需要成为一个因素。

DT$C1 = factor(DT$C1)
于 2020-08-26T14:44:19.960 回答