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)
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:
for the gamma distribution versus:
for the inverse gamma.