library(MCMCpack) n <- 50000 nu <- 100 sigma02 <- 50 x <- rchisq(n=n, df=nu) x <- nu*sigma02 / x y <- rinvgamma(n=n, nu/2, nu*sigma02/2 ) print(mean(x)) print(mean(y)) print(var(x)) print(var(y)) dx <- density(x) dy <- density(y) matplot( dx$x, dx$y, type="l",col="red") matlines( dy$x, dy$y, type="l", lty=2)