Calculates the (co)variance of continuous, discrete and multivariate phase-type distributions generated by PH, DPH, MPH and MDPH.

var(obj, ...)

# S3 method for cont_phase_type
var(obj, ...)

# S3 method for disc_phase_type
var(obj, ...)

# S3 method for mult_cont_phase_type
var(obj, v = NULL, ...)

# S3 method for mult_disc_phase_type
var(obj, v = NULL, ...)

Arguments

obj

a cont_phase_type, disc_phase_type, mult_cont_phase_type or mult_disc_phase_type object

...

other arguments passed to methods

v

NULL, integer or vector of length 2.

Value

The value returned is either the variance (for univariate distributions) or the variance-covariance matrix (for multivariate distributions).

Details

For the univariate case (cont_phase_type and disc_phase_type), the variance of the distribution is returned.

In the case of multivariate phase-type distributions three different usages can be distinguished:

  • If v = NULL (default), then a variance-covariance matrix of all the variables specified in the reward matrix are returned, where variances are in the diagonal and covariances in the rest of the matrix element.

  • If v is an integer, then the variance of the variable encoded by the v index in the reward matrix is returned.

  • If v is a vector of length 2, then the covariance between the two variables encoded by the v indices in the reward matrix is returned.

Examples

# For univariate continuous phase-type distributions
ph1 <- PH(matrix(c(-3, 0, 0, 1, -2, 0, 0, 1, -1), ncol = 3), c(0.25,0.25,0.5))
var(ph1)
#> [1] 0.9375

# For multivariate continuous phase-type distributions
subintensity_matrix <- matrix(c(-3, 0, 0,
                               2, -2, 0,
                               0, 1, -1), nrow = 3, ncol = 3)
reward_matrix = matrix(sample(seq(0, 10), 6), nrow = 3, ncol = 2)
ph2 <- MPH(subintensity_matrix, reward_mat = reward_matrix)
#> Warning: 
#>  The initial probability vector is automatically generated.
## Variance-covariance matrix
var(ph2)
#>          [,1]     [,2]
#> [1,] 18.11111 19.22222
#> [2,] 19.22222 74.66667
## Variance for the first state in the reward matrix
var(ph2, 1)
#> [1] 18.11111
## Variance for the second state in the reward matrix
var(ph2, 2)
#> [1] 74.66667