Simulation and Quantiles for the Scaled Inverse Chi-Square Distribution

icon3 , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted October 27, 2008 at 19:20 (UTC)

Although R supports a lot of different probability distributions, it does not support the scaled inverse chi-square distribution - well, not directly. But it can of course be implemented.

Let X \sim S \chi_\nu^{-2}. Because of how the scaled inverse chi-square distribution is defined, it's possible to simulate from it in R as follows (checking the arguments is not included in the following code):

rinvchisq <- function(n, df, scale)
{
  return(scale * (1 / rchisq(n, df)))
}

When we're able to simulate from the distribution, we're able to find quantiles. But we can actually find those directly by using the definition of quantiles and the chi-squared distribution. Assume that we want to find the $\alpha$-quantile $x_\alpha$. Notice that with informal notation, the following holds:

<br />
\alpha =<br />
P\left (X \leq x_\alpha\right ) =<br />
P\left (S \chi_\nu^{-2} \leq x_\alpha\right ) =<br />
P\left (\chi_\nu^2 \geq \frac{S}{x_\alpha}\right ) =<br />
1 - P\left (\chi_\nu^2 \leq \frac{S}{x_\alpha}\right ) ,<br />


and hence

P\left (\chi_\nu^2 \leq \frac{S}{x_\alpha}\right ) = 1 - \alpha.

If Y \sim \chi_\nu^2, then \frac{S}{x_\alpha} is the 1-\alpha-quantile y_{1-\alpha} for Y. All together we now have:

x_\alpha = \frac{S}{y_{1-\alpha}}.

Because of this, we can implement the following in R (checking the arguments is still not included in the following code):

qinvchisq <- function(p, df, scale)
{
  return(scale / qchisq(1 - p, df))
}

Checking the functions can be done like this:

invchisqcheck <- function(p, n, df, scale)
{
  cat("Check of rinvchisq and qinvchisq...\n")
  cat("Quantiles:", p, "\n")
  cat("Simulated with rinvchisq:\n")
  cat(quantile(rinvchisq(simulations, df, scale), quantiles), "\n")
  cat("Calculated with qinvchisq:\n")
  cat(qinvchisq(quantiles, df, scale), "\n")
}

invchisqcheck(c(0.025, 0.975), 100000, 10, 1)
invchisqcheck(c(0.025, 0.975), 100000, 11, 68)

For further information, please refer to http://en.wikipedia.org/wiki/Scale-inverse-chi-square_distribution.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.