Description Usage Arguments Details Value Source Examples
View source: R/DocumentationMoments.R
Computing (factorial) moments of a given order of phase-type distributed random variables.
1 |
object |
either a continuous phase-type distributed object of class |
i |
a positive number stating the order of the desired moment |
all |
a logical value indicating whether the function should compute all moments up to the given order. The default is equal to FALSE. |
In the discrete case ( τ ~ DPH(initDist,P) ), the factorial moments are given by
E[τ(τ-1) ··· (τ-i+1)] = i! initDist P^(i-1) (I-P)^(-i) e,
where initDist
is the initial distribution and P is the sub-transition probability matrix.
For τ ~ PH(initDist, T), the i'th-order moment is defined as
E[τ^i] = i! initDist (-T)^(-i) e,
where initDist
is again the initial distribution and T is the sub-intensity rate matrix.
In both cases, e is a vector with one in each entry.
For all = FALSE
, the function either returns the i'th-order moment (if the object is continuous
phase-type distributed) or the i'th factorial moment (if the object is discrete
phase-type distributed). In both cases, the length of the output is one.
For all = TRUE
, the function computes all (factorial) moments up to the given order,
hence the output is a vector of length i.
Mogens Bladt and Bo Friis Nielsen (2017): Matrix-Exponential Distributions in Applied Probability. Probability Theory and Stochastic Modelling (Springer), Volume 81.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ## Using the function moments() to compute the mean
## and variance of a phase-type distribution
## For n=4, the time to the most recent common ancestor is
## phase-type distributed with initial distribution
initDist <- c(1,0,0)
## and sub-intensity rate matrix
T_Mat <- matrix(c(-6,6,0,
0,-3,3,
0,0,-1), nrow = 3, ncol = 3, byrow = TRUE)
## Defining an object of type "contphasetype"
TMRCA <- contphasetype(initDist, T_Mat)
## Computing all moments up to order 2
m <- moments(TMRCA, i=2, all = TRUE)
## We get the desired numbers
m[1]
phmean(TMRCA)
m[2] - m[1]^2
phvar(TMRCA)
## For theta=2, the number of segregating sites plus one is
## discrete phase-type distributed with initial distribution
initDist <- c(1,0,0,0)
## and sub-transition probability matrix
P_Mat <- matrix(c(0.4, 0.3, 4/30, 2/30,
0, 0.5, 2/9, 1/9,
0, 0, 2/3, 0,
0, 0, 0, 2/3), nrow = 4, ncol = 4, byrow = TRUE)
## Defining an object of type "discphasetype"
S_Total <- discphasetype(initDist, P_Mat)
## Computing all moments up to order 2
m <- moments(S_Total, i=2, all = TRUE)
## We get the desired numbers
m[1]
phmean(S_Total)
m[2] + m[1] - m[1]^2
phvar(S_Total)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.