2
$\begingroup$

I tried to use below R code to model inverse gamma distribution (alpha=1,beta=1). However, the resulting histogram is not alike the one plotted in the wiki. Could anyone provide any hint about this? Thank for you help.

v <- rgamma(1,1,100000) v <- 1 / v dv <- as.data.frame(v) ggplot(data=dv,aes(x=v)) + geom_histogram()

$\endgroup$
1
$\begingroup$

The line v <- rgamma(1,1,100000) draws one observation from a $\text{Gamma}(1,100000)$. You can't make a histogram of this, since you only have one point. Since you say you want to draw from an $\text{InvGamma}(1,1)$, you probably want

v <- rgamma(n=1000,shape=1,rate=1)
v <- 1/v

instead. Don't be afraid to check out the documentation for the parameter ordering for this function.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.