[Bayes] qgamma & rgamma: Central Credible Interval
gamma分布的density的奇怪特性,如下:
Poisson的Gamma先验

h(x) 的置信区间 的 获取
> n =
> sumx=
>
> alpha=
> beta=0.01
> pmean=(alpha+sumx)/(beta+n)
> L=qgamma(0.025, alpha+sumx, beta+n) // 获得cdf的边界
> U=qgamma(0.975, alpha+sumx, beta+n)
>
> cat("Posterior mean: ", pmean, " (", L, ",",U,")")
Posterior mean: 382.8796 ( 378.1376 , 387.6506 )
// 95% 置信区间的边界值 还有期望。
Monte Carlo sampling:
N= # or 500 or 5000
L=U=rep(NA,length=)
for (i in :) {
dat=sort(rgamma(N,alpha+sumx,beta+n))
L[i]=dat[0.025*N]
U[i]=dat[0.975*N]
} // 获得某分位点的大量样本
widthL=max(L)-min(L)
widthU=max(U)-min(U)
par(mfrow=c(,))
hist(L,probability=T,xlab="Lower 95% CI bound")
points(qgamma(0.025,alpha+sumx,beta+n),,pch=,col=)
hist(U,probability=T,xlab="Upper 95% CI bound")
points(qgamma(0.975,alpha+sumx,beta+n),,pch=,col=)
cat("L interval variability (range):",widthL,"\n")
cat("U interval variability (range):",widthU,"\n")
Sampling估计的分位点,看来与True value差不多呢。
> mean(L)
[] 378.0747
> mean(U)
[] 387.5853
问题来了,N要多大才能保证要求的分位点估计精度:Sol 要 according to Central Limit Thearem.
p(y) 的预测
alpha=; beta=0.01
sumx=; n=65 theta=rgamma(,alpha+sumx,beta+n) // 后验sita
y=rpois(,theta) // poisson分布sampling,带入后验sita的f(y|sita),5000个相应的预测值
hist(y,probability=T,ylab="Density",main="Posterior predictive distribution")
// sampling法得到直方图。
// 相当吻合!
// 精确函数得到散点图。
xx=:
pr=dnbinom(xx,sumx+alpha,-/(beta+n+))
#lines(xx,pr,col=) # The (incorrect) continuous version - ok as an approx.
#The (correct) discrete version:
for (i in :length(xx)) {
lines(c(xx[i],xx[i+]),rep(pr[i],),col=,lwd=)
}

[Bayes] qgamma & rgamma: Central Credible Interval的更多相关文章
- [AI] 深度数学 - Bayes
数学似宇宙,韭菜只关心其中实用的部分. scikit-learn (sklearn) 官方文档中文版 scikit-learn Machine Learning in Python 一个新颖的onli ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- (main)贝叶斯统计 | 贝叶斯定理 | 贝叶斯推断 | 贝叶斯线性回归 | Bayes' Theorem
2019年08月31日更新 看了一篇发在NM上的文章才又明白了贝叶斯方法的重要性和普适性,结合目前最火的DL,会有意想不到的结果. 目前一些最直觉性的理解: 概率的核心就是可能性空间一定,三体世界不会 ...
- Simulation of empirical Bayesian methods (using baseball statistics)
Previously in this series: The beta distribution Empirical Bayes estimation Credible intervals The B ...
- BAYESIAN STATISTICS AND CLINICAL TRIAL CONCLUSIONS: WHY THE OPTIMSE STUDY SHOULD BE CONSIDERED POSITIVE(转)
Statistical approaches to randomised controlled trial analysis The statistical approach used in the ...
- R语言缺点
R的优点:免费,开源,体积小.缺点:对大文本处理差,另外一个也在于开源,package如果出错,烦死你.当你跑比较大的simulation,对效率有要求的时候,有时还是不得不用C,这可能是10小时和1 ...
- 疫情期,如何用A/B测试快速迭代你的产品?
作者:友盟+数据科学家 杨玉莲.陆子骏 冠状病毒来袭牵动着每个人的心,但是病毒影响的不仅仅是我们的健康,也以极快的速度极深远地影响了整个移动互联网的发展.主流阵地原本在线下的需求,如医疗和生鲜电商,快 ...
- maven 下载jar失败: resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Multiple annotations found at this line: - ArtifactTransferException: Failure to transfer com.faster ...
- maven执行报错resolution will not be reattempted until the update interval of nexus h
maven在执行过程中抛错: 引用 ... was cached in the local repository, resolution will not be reattempted until t ...
随机推荐
- unity 对象旋转,自转
1.对象具体的围绕哪个轴旋转,对应的设置值: transform.Rotate(new Vector3(1,0,0)); //绕x轴旋转 //默认是物体围绕世界坐标的XYZ轴旋转,即物体绕着世 ...
- PHP Redis 对象方法手册
redis(Remote Dictionary Server)是一种Nosql技术,它是一个开源的高级kv存储和数据结构存储系统. redis不仅仅是能够存储key和value这种简单的键值对,还能存 ...
- Linux.Centos安装scp反复失败的解决方式
现象 在A服务器用scp命令从B服务器拉文件时, 报找不到scp指令的错误 在A服务器运行 scp --help 发现是有指令的 在B服务器上 常规方式, 安装openssh-clients yum ...
- Detour3.0 win7 64bit下的安装
最近在做API hook相关的东西,用了inline hook后感觉不错,但是查找资料发现inline hook并不稳定 inline hook 的原理是在系统访问一个函数的时候先替换原函数入口处的内 ...
- android:碎片的生命周期
和活动一样,碎片也有自己的生命周期,并且它和活动的生命周期实在是太像了,我相 信你很快就能学会,下面我们马上就来看一下. 4.3.1 碎片的状态和回调 还记得每个活动在其生命周期内可能会有哪几种 ...
- 基于Socket网络编程
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/a2011480169/article/details/73602708 博客核心内容: 1.Sock ...
- eclipse-修改启动JDK版本
打开eclipse安装目录下的eclipse.ini文件,将红色内容加入 -vm ../Java/jdk1.6.0_26/bin (或者指向具体目录:D:/software/jdk_1.8u91/bi ...
- 学习Spring-Session+Redis实现session共享
1.添加依赖 <dependency> <groupId>org.springframework.session</groupId> <artifactId& ...
- 为什么和什么是 DevOps?
原文地址 本文内容 为什么 DevOps 什么是 DevOps DevOps 所带来的好处 如何将 DevOps 落到实处? 关于 DevOps 的澄清 参考资料 编写软件之所以难,是因为没有哪两个软 ...
- 微软BI 之SSIS 系列 - 在 SSIS 中将指定目录下的所有文件分类输出到不同文件夹
开篇介绍 比如有这样的一个需求,旧的一个业务系统通常将产出的文件输出到同一个指定的目录下的不同子目录,输出的文件类型有 XML,EXCEL, TXT 这些不同后缀的文件.现在需要在 SSIS 中将它们 ...

