Density, probability distribution, quantile, moment, hazard and random number generation functions for the Coxian phase-type distribution with any number of phases.
Source:R/nphase.r
nphase.RdDensity, probability distribution, quantile, moment, hazard and random number generation functions for the Coxian phase-type distribution with any number of phases.
Usage
dnphase(x, prate, arate, initp = NULL, method = "expm")
pnphase(q, prate, arate, initp = NULL, method = "expm", lower.tail = TRUE)
hnphase(x, prate, arate, initp = NULL, method = "expm")
mean_nphase(prate, arate, initp = NULL)
var_nphase(prate, arate, initp = NULL)
skewness_nphase(prate, arate, initp = NULL)
ncmoment_nphase(prate, arate, i, initp = NULL)
rnphase(n, prate, arate)
qnphase(p, prate, arate, lower.tail = TRUE, log.p = FALSE, method = "expm")Arguments
- x
Value at which to evaluate the PDF, CDF, or hazard.
- prate
Progression rates. Either a vector of length
nphase-1, or a matrix withnparrows andnphase-1columns.- arate
Absorption rates. Either a vector of length
nphase, or a matrix withnparrows andnphasecolumns.- initp
Vector of probabilities of occupying each phase at the start of the sojourn. By default, the first phase has probability 1.
- method
If
"analytic"then fornphase5 or less, an analytic solution to the matrix exponential is employed in the calculation. Fornphase6 or more, or ifmethod="mexp"the matrix exponential is determined using numerical methods, viaexpm::expm().- q
Value at which to evaluate the CDF.
- lower.tail
If
TRUEreturn P(X<x), else P(X>=x).- i
which moment to return from
ncmoment_nphase- n
Number of random samples to generate, for
rnphase. Ifprateorarateis a matrix with more than one row, its rows are recycled to lengthnand one random number is generated per row, in the same fashion as themeanandsdarguments ofrnorm. In particular ifnequals the number of rows ofarate, then exactly one random number is generated for the parameters given by each row.- p
Probability at which to evaluate the quantile
- log.p
return log probability
Details
The number of phases, nphase, is taken from the
dimensions of the object supplied as arate. If arate is a
vector, then the number of phases is assumed to equal the length
of this vector. If arate is a matrix, then the number of
phases is assumed to be the number of columns.
mean_nphase, var_nphase, skewness_nphase and
ncmoment_nphase return the mean, variance, skewness and general
non-central moments of the distribution.
These functions work in a vectorised way, so that alternative
parameter values or evaluation values x can be supplied. The
number of alternative values is determined from the number of rows
of arate. Then if necessary, prate and x are
replicated to match the size of arate.