View source: R/invgamma_couplings.R
Sample from inverse gamma with given parameters alpha, beta, with log-density at x given by
alpha * log(beta) - lgamma(alpha) - (alpha+1) * log(x) - beta / x
with given parameters mu, lambda, with log-density given by 0.5 * log(lambda/(2*pi)) - 1.5 * log(x) - lambda * (x-mu)^2 / (2 * mu^2 * x). The procedure goes as follows. Generate nu ~ Normal(0,1). Define y = nu^2. Define x = mu + mu^2 * y / (2 * lambda) - mu / (2 * lambda) * sqrt(4 * mu * lambda * y + mu^2 * y^2). Generate Z ~ Uniform(0,1). If z <= mu / (mu + x), output x, otherwise output mu^2 / x.
1 2 3 | rigamma(n, alpha, beta)
rinvgaussian(n, mu, lambda)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.