英文:
Type 2 errors with Bayesian models (brms)
问题
以下是您要翻译的代码部分:
library(brms)
library(bayestestR)
# 创建分布
x <- rnorm(n = 6000, mean = 10, sd = 3.14)
# 复制到两个条件
df1 <- data.frame(val = x, cond = "yes")
df2 <- data.frame(val = x, cond = "no")
# 合并成一个数据框
df <- rbind(df1, df2)
# 设置先验分布
ipriors <- c(
prior(normal(0, 20), class = Intercept),
prior(normal(500, 3), class = b, coef="condyes"),
prior(normal(0, 5), class = sigma)
)
# 拟合模型
m <- brm(val ~ cond, data=df, family = gaussian(), prior = ipriors)
summary(m)
dat <- as.data.frame(m)
hypothesis(dat,"b_condyes > 0")
这部分代码用于拟合贝叶斯模型和进行假设检验。
英文:
Can anyone explain why the following model comes out as significant? I'm comparing one distribution with an exact copy of itself, but have tweaked the priors just right to get significance. I'm not sure why this can happen.
library(brms)
library(bayestestR)
# Create distribution
x <- rnorm(n = 6000, mean = 10, sd = 3.14)
# Copy it over two conditions
df1 <- data.frame(val = x, cond = "yes")
df2 <- data.frame(val = x, cond = "no")
# Join into one dataframe
df <- rbind(df1,df2)
# Set up priors
ipriors <- c(
prior(normal(0, 20), class = Intercept),
prior(normal(500, 3), class = b, coef="condyes"),
prior(normal(0, 5), class = sigma)
)
# Fit model
m <- brm(val ~ cond, data=df, family = gaussian(), prior = ipriors)
summary(m)
dat <- as.data.frame(m)
hypothesis(dat,"b_condyes > 0")
This yields a highly significant difference:
Hypothesis Tests for class :
Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
1 (b_condyes) > 0 0.18 0.06 0.09 0.27 1332.33 1 *
I expected Bayesian models to be resistant to Type II errors.
A posterior predictive check looks good to me:
答案1
得分: 1
根据我所看到的,你有一个非常强烈的先验假设,表明存在一个服从正态分布(500,3)的效应。你需要有大量的证据来克服这一先验假设。我建议将条件的先验假设中心化,例如使用正态分布(0,3)或者使用学生 t 分布。
对于正态分布(0,3):
类别的假设检验:
假设 估计 估计误差 置信下限 置信上限 证据比 后验概率 星号
1 (b_condyes) > 0 0 0.06 -0.1 0.09 0.98 0.5
另外,我认为在贝叶斯框架下使用假设检验时,人们不会声称不存在第二类错误(Type II errors)。
英文:
From what I can see you have a very strong prior which suggests an effect with a normal(500,3). You would need a lot of evidence to overcome this. I would suggest to center the prior for the condition such as normal(0,3) or use a student t distribution.
For normal(0,3):
Hypothesis Tests for class :
Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
1 (b_condyes) > 0 0 0.06 -0.1 0.09 0.98 0.5
Also I don't think people would claim that there are no Type II errors in a Bayesian framework when using hypothesis testing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论