Creates transition intensity matrices where elements represent the instantaneous risk of moving between health states.

# S3 method for matrix
qmatrix(x, trans_mat, ...)

# S3 method for data.table
qmatrix(x, trans_mat, ...)

# S3 method for data.frame
qmatrix(x, trans_mat, ...)

Arguments

x

A two-dimensional tabular object containing elements of the transition intensity matrix. A column represents a transition from state \(r\) to state \(s\). Each row represents elements of a different transition intensity matrix. See "Details" for more information.

trans_mat

Just as in IndivCtstmTrans, a transition matrix describing the states and transitions in a multi-state model.

...

Further arguments passed to or from other methods. Currently unused.

Value

An array of transition intensity matrices with the third dimension equal to the number of rows in x.

Details

The object x must only contain non-zero and non-diagonal elements of a transition intensity matrix. The diagonal elements are automatically computed as the negative sum of the other rows.

See also

Examples

# 3 state irreversible model
tmat <- rbind(c(NA, 1, 2),
              c(NA, NA, 3),
              c(NA, NA, NA)) 
q12 <- c(.8, .7)
q13 <- c(.2, .3)
q23 <- c(1.1, 1.2)
q <- data.frame(q12, q13, q23)
qmat <- qmatrix(q, trans_mat = tmat)
print(qmat)
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,]   -1  0.8  0.2
#> [2,]    0 -1.1  1.1
#> [3,]    0  0.0  0.0
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3]
#> [1,]   -1  0.7  0.3
#> [2,]    0 -1.2  1.2
#> [3,]    0  0.0  0.0
#> 

# Matrix exponential of each matrix in array
expmat(qmat)
#> , , 1
#> 
#>           [,1]      [,2]      [,3]
#> [1,] 0.3678794 0.2800669 0.3520537
#> [2,] 0.0000000 0.3328711 0.6671289
#> [3,] 0.0000000 0.0000000 1.0000000
#> 
#> , , 2
#> 
#>           [,1]      [,2]      [,3]
#> [1,] 0.3678794 0.2333983 0.3987223
#> [2,] 0.0000000 0.3011942 0.6988058
#> [3,] 0.0000000 0.0000000 1.0000000
#>