GeneralizedInverseGaussian {boodist}R Documentation

Generalized inverse Gaussian distribution

Description

A R6 class to represent a generalized inverse Gaussian distribution.

Details

See Wikipedia.

Active bindings

theta

Get or set the value of theta.

eta

Get or set the value of eta.

lambda

Get or set the value of lambda.

Methods

Public methods


Method new()

New generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$new(theta, eta, lambda)
Arguments
theta

concentration parameter, >0

eta

scale parameter, >0

lambda

parameter (denoted by p on Wikipedia)

Returns

A GeneralizedInverseGaussian object.


Method d()

Density function of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$d(x, log = FALSE)
Arguments
x

vector of positive numbers

log

Boolean, whether to return the log-density

Returns

The density or the log-density evaluated at x.


Method p()

Cumulative distribution function of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$p(q)
Arguments
q

numeric vector of quantiles (>= 0)

Returns

The cumulative probabilities corresponding to q, with two attributes (see the Note).


Method q()

Quantile function of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$q(p, bounds = NULL)
Arguments
p

numeric vector of probabilities

bounds

bounds enclosing the quantiles to be found (see the Note), or NULL for automatic bounds

Returns

The quantiles corresponding to p.


Method r()

Sampling from the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$r(n)
Arguments
n

number of simulations

Returns

A numeric vector of length n.


Method mean()

Mean of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$mean()
Returns

The mean of the generalized inverse Gaussian distribution.


Method mode()

Mode of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$mode()
Returns

The mode of the generalized inverse Gaussian distribution.


Method sd()

Standard deviation of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$sd()
Returns

The standard deviation of the generalized inverse Gaussian distribution.


Method variance()

Variance of the generalized inverse Gaussian distribution.

Usage
GeneralizedInverseGaussian$variance()
Returns

The variance of the generalized inverse Gaussian distribution.


Method clone()

The objects of this class are cloneable with this method.

Usage
GeneralizedInverseGaussian$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Note

The cumulative distribution function is evaluated by integrating the density function (in C++). Its returned value has two attributes: a numeric vector "error_estimate" and an integer vector "error_code". The error code is 0 if no problem is detected. If an error code is not 0, a warning is thrown. The quantile function is evaluated by root-finding and then the user must provide some bounds enclosing the values of the quantiles or choose the automatic bounds. A maximum number of iterations is fixed in the root-finding algorithm. If it is reached, a warning is thrown.

Examples

if(require("plotly")) {
library(boodist)

x_ <- seq(0, 3, length.out = 100L)
lambda_ <- seq(-1, 1, length.out = 100L)
dsty <- vapply(lambda_, function(lambda) {
  GeneralizedInverseGaussian$new(theta = 1, eta = 1, lambda)$d(x_)
}, numeric(length(x_)))
#
txt <- matrix(NA_character_, nrow = length(x_), ncol = length(lambda_))
for(i in 1L:nrow(txt)) {
  for(j in 1L:ncol(txt)) {
    txt[i, j] <- paste0(
      "x: ", formatC(x_[i]),
      "<br> lambda: ", formatC(lambda_[j]),
      "<br> density: ", formatC(dsty[i, j])
    )
  }
}
#
plot_ly(
  x = ~lambda_, y = ~x_, z = ~dsty, type = "surface",
  text = txt, hoverinfo = "text", showscale = FALSE
) %>% layout(
  title = "Generalized inverse Gaussian distribution",
  margin = list(t = 40, r= 5, b = 5, l = 5),
  scene = list(
    xaxis = list(
      title = "lambda"
    ),
    yaxis = list(
      title = "x"
    ),
    zaxis = list(
      title = "density"
    )
  )
)
}

[Package boodist version 1.0.0 Index]