R: The Phase-type Distribution

PhaseType {actuar} | R Documentation

## The Phase-type Distribution

### Description

Density, distribution function, random generation, raw moments and moment generating function for the (continuous) Phase-type distribution with parameters `prob` and `rates`.

### Usage

    dphtype(x, prob, rates, log = FALSE)
    pphtype(q, prob, rates, lower.tail = TRUE, log.p = FALSE)
    rphtype(n, prob, rates)
    mphtype(order, prob, rates)
    mgfphtype(t, prob, rates, log = FALSE)

### Arguments

`x, q` | vector of quantiles.
`n` | number of observations. If `length(n) > 1`, the length is taken to be the number required.
`prob` | vector of initial probabilities for each of the transient states of the underlying Markov chain. The initial probability of the absorbing state is `1 - sum(prob)`.
`rates` | square matrix of the rates of transition among the states of the underlying Markov chain.
`log, log.p` | logical; if `TRUE`, probabilities/densities p are returned as log(p).
`lower.tail` | logical; if `TRUE` (default), probabilities are P[X <= x], otherwise, P[X > x].
`order` | order of the moment.
`t` | numeric vector.

### Details

The phase-type distribution with parameters `prob` = pi and `rates` = T has density:

f(x) = pi %*% exp(T * x) %*% t

for x ≥ 0 and f(0) = 1 - pi %*% e, where e is a column vector with all components equal to one, t = -T %*% e is the exit rates vector and exp(T * x) denotes the matrix exponential of T * x. The matrix exponential of a matrix M is defined as the Taylor series

exp(M) = sum(n = 0:Inf; (M^n)/(n!)).

The parameters of the distribution must satisfy pi %*% e <= 1, T[i, i] < 0, T[i, j] >= 0 and T %*% e <= 0.

The kth raw moment of the random variable X is E[X^k] and the moment generating function is E[e^{tX}].

### Value

`dphasetype` gives the density, `pphasetype` gives the distribution function, `rphasetype` generates random deviates, `mphasetype` gives the kth raw moment, and `mgfphasetype` gives the moment generating function in `x`.

Invalid arguments will result in return value `NaN`, with a warning.

### Note

The `"distributions"` package vignette provides the interrelations between the continuous size distributions in actuar and the complete formulas underlying the above functions.

### Author(s)

Vincent Goulet vincent.goulet@act.ulaval.ca and Christophe Dutang

### References

https://en.wikipedia.org/wiki/Phase-type_distribution

Neuts, M. F. (1981), Generating random variates from a distribution of phase type, WSC '81: Proceedings of the 13th conference on Winter simulation, IEEE Press.

### Examples

    ## Erlang(3, 2) distribution
    T <- cbind(c(-2, 0, 0), c(2, -2, 0), c(0, 2, -2))
    pi <- c(1,0,0)
    x <- 0:10

    dphtype(x, pi, T)		# density
    dgamma(x, 3, 2)			# same
    pphtype(x, pi, T)		# cdf
    pgamma(x, 3, 2)			# same

    rphtype(10, pi, T)		# random values

    mphtype(1, pi, T)		# expected value

    curve(mgfphtype(x, pi, T), from = -10, to = 1)

[Package actuar version 3.1-2 Index]