R/generator_functions.R
, R/PH.R
, R/DPH.R
, and 2 more
generator_functions.Rd
Generator functions for the S3 classes cont_phase_type
, disc_phase_type
,
mult_cont_phase_type
, mult_disc_phase_type
, which represent the
different phase-type distributions.
PH(subint_mat = NULL, init_probs = NULL)
DPH(subint_mat = NULL, init_probs = NULL)
MPH(subint_mat = NULL, init_probs = NULL,
reward_mat = NULL)
MDPH(subint_mat = NULL, init_probs = NULL,
reward_mat = NULL)
a square matrix containing the transition rates or probabilities between transient states for continuous or discrete phase-type respectively. If the phase-type is continuous, the sub-intensity matrix diagonal should only contain negative values and the row sums should be non-positive. If the phase-type is discrete, the sub-intensity matrix should only contain values between 0 and 1.
a vector, a one-row matrix or NULL
which gives the
probabilities to start in each state. If init_probs
is NULL
,
the probability to start on the first state will be 1 and 0 otherwise.
a matrix NULL
(default) where each row is a reward
vector, and each column corresponds to a state. It should have the same
number of columns as the length of the initial probabilities.
A phase-type object of class cont_phase_type
for PH
, disc_phase_type
for DPH
,
mult_cont_phase_type
for MPH
, and mult_disc_phase_type
for MDPH
.
All these classes inherit from list
.
PH
, DPH
, MPH
and MDPH
are the generator functions
for the four types of phase-type distribution
classes, this is, the continuous univariate, the discrete univariate, the continuous multivariate
and the discrete multivariate respectively.
The class is generated by supplying a sub-intensity matrix and an optional
initial probability vector plus a reward matrix in the case of multivariate
phase-type.
If the initial probabilities are not specified, then the initial probability
will be init_probs = c(1, 0, 0, ...)
with the same length as the
number of transient states.
##===========================##
## For continuous univariate ##
##===========================##
subintensity_matrix <- matrix(c(-1.5, 1.5, 0,
0, -1, 1,
0, 0, -0.5),
ncol = 3,
byrow = TRUE)
PH(subintensity_matrix)
#> Warning:
#> The initial probability vector is automatically generated.
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] -1.5 1.5 0.0
#> [2,] 0.0 -1.0 1.0
#> [3,] 0.0 0.0 -0.5
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "cont_phase_type"
#---
subintensity_matrix <- matrix(c(-1.5, 1.5, 0,
0, -1, 1,
0, 0, -0.5),
ncol = 3,
byrow = TRUE)
initial_probabilities <- c(0.9, 0.1, 0)
PH(subintensity_matrix, initial_probabilities)
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] -1.5 1.5 0.0
#> [2,] 0.0 -1.0 1.0
#> [3,] 0.0 0.0 -0.5
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 0.9 0.1 0
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "cont_phase_type"
##=========================##
## For discrete univariate ##
##=========================##
subintensity_matrix <- matrix(c(0.4, 0.24, 0.12,
0, 0.4, 0.2,
0, 0, 0.5),
ncol = 3,
byrow = TRUE)
DPH(subintensity_matrix)
#> Warning:
#> The initial probability vector is automatically generated.
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] 0.4 0.24 0.12
#> [2,] 0.0 0.40 0.20
#> [3,] 0.0 0.00 0.50
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "disc_phase_type"
#---
subintensity_matrix <- matrix(c(0.4, 0.24, 0.12,
0, 0.4, 0.2,
0, 0, 0.5),
ncol = 3,
byrow = TRUE)
initial_probabilities <- c(0.9, 0.1, 0)
DPH(subintensity_matrix, initial_probabilities)
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] 0.4 0.24 0.12
#> [2,] 0.0 0.40 0.20
#> [3,] 0.0 0.00 0.50
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 0.9 0.1 0
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "disc_phase_type"
##=============================##
## For continuous multivariate ##
##=============================##
subintensity_matrix <- matrix(c(-3, 2, 0,
0, -2, 1,
0, 0, -1),
nrow = 3,
byrow = TRUE)
reward_matrix = matrix(sample(seq(0, 10, 0.1), 6), nrow = 3, ncol = 2)
initial_probabilities = c(1, 0, 0)
MPH(subintensity_matrix,
initial_probabilities,
reward_matrix)
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] -3 2 0
#> [2,] 0 -2 1
#> [3,] 0 0 -1
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#>
#> $reward_mat
#> [,1] [,2]
#> [1,] 4.7 2.0
#> [2,] 3.2 3.0
#> [3,] 4.4 1.6
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "mult_cont_phase_type"
##===========================##
## For discrete multivariate ##
##===========================##
subintensity_matrix <- matrix(c(0.4, 0.24, 0.12,
0, 0.4, 0.2,
0, 0, 0.5),
ncol = 3,
byrow = TRUE)
reward_matrix <- matrix(sample(seq(0, 10), 6), nrow = 3, ncol = 2)
initial_probabilities = c(1, 0, 0)
MDPH(subintensity_matrix,
initial_probabilities,
reward_mat = reward_matrix)
#> $subint_mat
#> [,1] [,2] [,3]
#> [1,] 0.4 0.24 0.12
#> [2,] 0.0 0.40 0.20
#> [3,] 0.0 0.00 0.50
#>
#> $init_probs
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#>
#> $reward_mat
#> [,1] [,2]
#> [1,] 8 2
#> [2,] 6 5
#> [3,] 9 1
#>
#> $defect
#> [1] 0
#>
#> attr(,"class")
#> [1] "mult_disc_phase_type"