我想计算我在 R 中的贝叶斯混合效应模型中不同级别的参数之间的对比,并产生贝叶斯因子。我的结果(Jud)是二元的(1=是/同步,0=否/不同步),参数 SOAsF 是一个具有 6 个级别(0、100、200、300、400、500)的因子。
遵循不同的教程/功能[#1]、[#2]和[#3],这是我的代码,具有 3 种不同的方式:
library(emmeans)
library(brms)
library(modelbased)
brm_acc_1<-brm(Jud ~ SOAsF +(1|pxID),data =dat_long, family=bernoulli("logit"), prior = set_prior('normal(0,10)'), iter = 2000, chains=4, save_all_pars = TRUE)
summary(brm_acc_1)
brms::conditional_effects(brm_acc_1)
####1
groups <- emmeans(brm_acc_1, ~ SOAsF)
group_diff <- pairs(groups)
(groups_all <- rbind(groups, group_diff))
bayesfactor_parameters(groups_all, prior = brm_acc_1, direction = "two-sided", effects = c("fixed", "random", "all"))
####2
ppc <- pp_check(brm_acc_1, type = "stat_grouped", group = "SOAsF")
#contrast 200 - 300
contrast_300_200 <- ppc$data$value[ppc$data$group == "200"] - ppc$data$value[ppc$data$group == "300"]
quantile(contrast_300_200*100, probs = c(.5, .025, .975))
####3
h_1 <- hypothesis(brm_acc_1, "SOAsF200 < SOAsF300")
print(h1, digits = 4)
h2 <- hypothesis(brm_acc_1, "SOAsF200 > SOAsF300")
print(h2, digits = 4)
结果:
####1
# Bayes Factor (Savage-Dickey density ratio)
Parameter | BF
-----------------------
0, . | 8.08e-03
100, . | 0.61
200, . | 7.29e+03
300, . | 67.77
400, . | 21.81
500, . | 0.28
., 0 - 100 | 2.75
., 0 - 200 | 1.90e+05
., 0 - 300 | 410.42
., 0 - 400 | 570.11
., 0 - 500 | 1.03
., 100 - 200 | 0.5
., 100 - 300 | 0.05
., 100 - 400 | 0.02
., 100 - 500 | 7.13e-03
., 200 - 300 | 0.01
., 200 - 400 | 0.01
., 200 - 500 | 1.11
., 300 - 400 | 7.21e-03
., 300 - 500 | 0.1
., 400 - 500 | 0.04
* Evidence Against The Null: [0]
####2
50% 2.5% 97.5%
1.988631 -3.707585 7.680694
####3
Hypothesis Tests for class b:
Hypothesis Estimate Est.Error CI.Lower CI.Upper
1 (SOAsF200)-(SOAsF... < 0 0.0881 0.0903 -0.0612 0.2372
Evid.Ratio Post.Prob Star
1 0.1919 0.161
---
'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
'*': For one-sided hypotheses, the posterior probability exceeds 95%;
for two-sided hypotheses, the value tested against lies outside the 95%-CI.
Posterior probabilities of point hypotheses assume equal prior probabilities.
Hypothesis Tests for class b:
Hypothesis Estimate Est.Error CI.Lower CI.Upper
1 (SOAsF200)-(SOAsF... > 0 0.0881 0.0903 -0.0612 0.2372
Evid.Ratio Post.Prob Star
1 5.2112 0.839
---
'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
'*': For one-sided hypotheses, the posterior probability exceeds 95%;
for two-sided hypotheses, the value tested against lies outside the 95%-CI.
Posterior probabilities of point hypotheses assume equal prior probabilities.
因此,以对比 200 与 300 为例。与 SOA 300 上呈现的声音相比,SOA 200 上呈现的声音是否同样被判断为同步(是)?
方式 #1 似乎提供了零假设 SOA 200 - SOA 300 = 0 且 BF = 0.01 的证据;所以他们似乎同样被认为是同步的?
方式 #2 似乎几乎没有提供零假设 SOA 200 = SOA 300 的证据,证据为 1.988631% 95%CI [-3.707585, 7.680694]。
方式 #3 似乎提供了支持替代假设 SOA 200 > SOA 300 或 SOA 200 - SOA 300 < 0 且 BF = 5.2112 的证据。
我是否发现差异是因为 #1 是双面的,而 #3 是单面的?
但是,我没有设法单面运行#1(方向=“左”或“右”)
bayesfactor_parameters(groups_all, prior = brm_acc_1, direction = ">", effects = c("fixed", "random", "all") )
Computation of Bayes factors: sampling priors, please wait...
Error in `$<-.data.frame`(`*tmp*`, "ind", value = 8L) :
replacement has 1 row, data has 0
或 #3 双面(假设(brm_acc_1,“SOAsF200 - SOAsF300 = 0”))
Hypothesis Tests for class b:
Hypothesis Estimate Est.Error CI.Lower CI.Upper
1 (SOAsF200-SOAsF300) = 0 0.0881 0.0903 -0.0914 0.2682
Evid.Ratio Post.Prob Star
1 NA NA
---
'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
'*': For one-sided hypotheses, the posterior probability exceeds 95%;
for two-sided hypotheses, the value tested against lies outside the 95%-CI.
Posterior probabilities of point hypotheses assume equal prior probabilities.
我被卡住了,任何帮助将不胜感激。谢谢。