Sampling from an inverse gamma distribution in R

user2005253 picture user2005253 · Aug 23, 2013 · Viewed 14.1k times · Source

In order to sample from an inverse gamma distribution in R, is the following the correct way to do it:

#I want to sample an inverse-gamma(a,b)

a = 4
b = 9

x = 1/rgamma(1,a,b)

Answer

Paul Hiemstra picture Paul Hiemstra · Aug 23, 2013

Although @Dason and @Stephane already commented that your approach is valid, there are several packages in R that do this (found googling for r inverse gamma:

See also the wikipedia page for the gamma distribution and the inverse gamma distribution for the probability density function of both distributions:

enter image description here

for the gamma distribution versus:

enter image description here

for the inverse gamma.