Type 2 errors with Bayesian models (brms) 第二类错误在贝叶斯模型(brms)中发生

huangapple go评论48阅读模式
英文:

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 &lt;- rnorm(n = 6000, mean = 10, sd = 3.14)

# Copy it over two conditions
df1 &lt;- data.frame(val = x, cond = &quot;yes&quot;)
df2 &lt;- data.frame(val = x, cond = &quot;no&quot;)

# Join into one dataframe
df &lt;- rbind(df1,df2)

# Set up priors
ipriors &lt;- c(
  prior(normal(0, 20), class = Intercept),
  prior(normal(500, 3), class = b, coef=&quot;condyes&quot;),
  prior(normal(0, 5), class = sigma)
)

# Fit model
m &lt;- brm(val ~ cond,  data=df, family = gaussian(), prior = ipriors)

summary(m)

dat &lt;- as.data.frame(m)
hypothesis(dat,&quot;b_condyes &gt; 0&quot;)

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) &gt; 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:

plot

答案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) &gt; 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.

huangapple
  • 本文由 发表于 2023年2月23日 22:37:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546276.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定