简体   繁体   English

在R中找到95个可截断的伽马分布的可信区间

[英]Find 95 credible interval of a truncated gamma distribution in R

I have a Gamma(shape=50, scale=0.1) with support [4,6]. 我有一个Gamma(形状= 50,比例= 0.1),支持[4,6]。 I was able to find its distribution by dividing the full gamma distribution by F(6) - F(4). 通过将完整的伽马分布除以F(6) - F(4),我能够找到它的分布。

p1 = seq(1,10,length=100)
d1 = dgamma(p1, shape=50, scale=0.1)

p2 = seq(4,6,length=100)
d2.full = dgamma(p2, shape=50, scale=0.1)
d2 = d2.full / (pgamma(6, shape=50, scale=0.1) - pgamma(4, shape=50, scale=0.1))

How would I find the central 95 credible interval of this truncated distribution (ie, d2)? 如何找到这个截断分布的中心95可信区间(即d2)?

EDIT: Please note that my truncated gamma does not have the same pdf as the standard gamma. 编辑:请注意我的截断伽玛与标准伽马不具有相同的pdf。 The reason is because the truncated gamma must be renormalized so that it integrates to 1 over the support [4,6]. 原因是因为截断的伽马必须重新归一化,以便它在支撑[4,6]上积分为1。 That's why d2 = d2.full / (F(6) - F(4)) 这就是为什么d2 = d2.full /(F(6) - F(4))

If I understand right, what you need is the interval (lower, upper) over where the prob from your truncated gamma is 95%, and the prob for interval (4, lower) is 2.5%, and for interval (upper, 6) is 2.5%. 如果我理解正确的,你需要的是区间(lower, upper)在哪里从您的截断伽马的概率是95%,而区间的概率(4, lower)为2.5%,而区间(upper, 6)是2.5%。 If so, by straightforward algebra: 如果是这样,通过直截了当的代数:

R > F = function(x){ pgamma(x, shape = 50, scale = 0.1) }
R > F(4)
[1] 0.07034
R > F(6)
[1] 0.9156
R > gap = 0.025*(F(6)-F(4))
R > gap
[1] 0.02113
R > (lower = qgamma(F(4) + gap, shape = 50, scale = 0.1))
[1] 4.087
R > (upper = qgamma(F(6) - gap, shape = 50, scale = 0.1))
[1] 5.9

I really like the answer by @liuminzhao but I already coded a much dirtier but perhaps complementary answer: 我非常喜欢@liuminzhao的答案,但我已经编写了一个更脏的但可能是互补的答案:

plot(p2, d2)  # you have most of the probability mass in the interval 4-6
 rd2.full = rgamma(100000, shape=50, scale=0.1)
 rd2 = rd2.full[rd2.full >= 4 & rd2.full <6]  # rejection sampling
 quantile(rd2, probs=c(0.025, 0.975))
#     2.5%    97.5% 
# 4.087765 5.897290 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM