Question

I have a Gamma(shape=50, scale=0.1) with support [4,6]. I was able to find its distribution by dividing the full gamma distribution by 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)?

EDIT: Please note that my truncated gamma does not have the same pdf as the standard gamma. The reason is because the truncated gamma must be renormalized so that it integrates to 1 over the support [4,6]. That's why d2 = d2.full / (F(6) - F(4))

Was it helpful?

Solution

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%. 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

OTHER TIPS

I really like the answer by @liuminzhao but I already coded a much dirtier but perhaps complementary answer:

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 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top