贝叶斯统计R语言操作3——假设检验

文章目录


前言

此篇文章对于贝叶斯假设检验不做定义以及公式的推导,仅仅是想通过实例R语言操作来理解贝叶斯假设检验。


一、贝叶斯假设检验的优点

  • 简单,无需抽样分布和显著性水平
  • 可以推广至多重检验

二、R语言实例操作

1.题目叙述

  • Measurements~ N ( μ , σ 2 ) N(\mu,\sigma^2) N(μ,σ2), μ \mu μ is true weight and σ \sigma σ = 3 pounds.
  • Interested in accessing if his true weight >175 pounds, test : H 0 : μ ≤ 175 H_0: \mu \leq175 H0​:μ≤175, H 1 : μ > 175 H_1: \mu >175 H1​:μ>175.
  • Normal prior N(170,25)
  • Measurement:182, 172, 173,176,176,180,173,174,179,175

2. 先验概率

代码如下(示例):

pmean=170;pvar=25
probH=pnorm(175,pmean,sqrt(pvar))
probA=1-probH
prior.odds=probH/probA
prior.odds#5.302974

2.后验概率

weights=c(182, 172, 173, 176, 176, 180, 173, 174, 179, 175)
xbar=mean(weights)
sigma2=3^2/length(weights)
post.precision=1/sigma2+1/pvar
post.var=1/post.precision
post.mean=(xbar/sigma2+pmean/pvar)/post.precision
c(post.mean,sqrt(post.var))#175.7915058   0.9320546
post.odds=pnorm(175,post.mean,sqrt(post.var))/
(1-pnorm(175,post.mean,sqrt(post.var)))
post.odds# 0.2467017

3. 贝叶斯因子

BF = post.odds/prior.odds
BF#0.04652139

4. H 0 H_0 H0​的后验概率

postH=probH*BF/(probH*BF+probA)
postH#0.1978835

5. 结论

Conclude: unlikely that his weight is at most 175 pounds.

上一篇:在java 9下运行时将jar添加到类路径


下一篇:SQL0901N Reason "Non-SYSTEM tenant for 3rd part name is not supported"