MyNixOS website logo
Description

The Inverse Gamma Distribution.

Light weight implementation of the standard distribution functions for the inverse gamma distribution, wrapping those for the gamma distribution in the stats package.

invgamma

invgamma implements the (d/p/q/r) statistics functions for the inverse gamma distribution in R. It is ideal for using in other packages since it is lightweight and leverages the (d/p/q/r)gamma() line of functions maintained by CRAN.

Getting invgamma

There are two ways to get invgamma. For the CRAN version, use

install.packages("invgamma")

For the development version, use

# install.packages("devtools")
devtools::install_github("dkahle/invgamma")

The (d/p/q/r)invgamma() functions

The functions in invgamma match those for the gamma distribution provided by the stats package. Namely, it uses as its density f(x) = (b^a / Gamma(a)) x^-(a+1) e^(-b/x), where a = shape and b = rate.

The PDF (the f(x) above) can be evaluated with the dinvgamma() function:

library(invgamma)
library(ggplot2); theme_set(theme_bw())
x <- seq(0, 5, .01)
qplot(x, dinvgamma(x, 7, 10), geom = "line")
#  Warning: Removed 1 rows containing missing values (geom_path).

The CDF can be evaluated with the pinvgamma() function:

f <- function(x) dinvgamma(x, 7, 10)
q <- 2
integrate(f, 0, q)
#  0.7621835 with absolute error < 7.3e-05
(p <- pinvgamma(q, 7, 10))
#  [1] 0.7621835

The quantile function can be evaluated with qinvgamma():

qinvgamma(p, 7, 10) # = q
#  [1] 2

And random number generation can be performed with rinvgamma():

set.seed(1)
rinvgamma(5, 7, 10)
#  [1] 1.9996157 0.9678268 0.9853343 1.3157697 3.1578177

rinvgamma() can be used to obtain a Monte Carlo estimate of the probability given by pinvgamma() above:

samples <- rinvgamma(1e5, 7, 10)
mean(samples <= q)
#  [1] 0.7621

Moreover, we can check the consistency and correctness of the implementation with

qplot(samples, geom = "density") + 
  stat_function(fun = f,  color = "red")

The (d/p/q/r)invchisq() and (d/p/q/r)invexp() functions

The gamma distribution subsumes the chi-squared and exponentialdistributions, so it makes sense to include the *invchisq() and *invexp() functions in invgamma. Their implementations, however, wrap *chisq() and *exp(), not *invgamma().

Metadata

Version

1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows