Learn R Programming

hesim (version 0.5.0)

tpmatrix: Transition probability matrix

Description

tpmatrix() both defines and evaluates a transition probability matrix in which elements are expressions. It can be used within define_tparams() to create a transition probability matrix or directly to create a tparams_transprobs() object. These are, in turn, ultimately used to create a CohortDtstmTrans object for simulating health state transitions.

Usage

tpmatrix(...)

Arguments

...

Named values of expressions defining elements of the matrix. Each element of ... should either be a vector or a 2-dimensional tabular object such as a data frame. See "Details" and the examples below.

Value

Returns a tpmatrix object that inherits from data.table where each column is an element of the transition probability matrix with elements ordered rowwise.

Details

A tpmatrix is a 2-dimensional tabular object that stores flattened square transition probability matrices in each row. Each transition probability matrix is filled rowwise. The complementary probability (equal to \(1\) minus the sum of the probabilities of all other elements in a row of a transition probability matrix) can be conveniently referred to as C. There can only be one complement for each row in a transition probability matrix.

See Also

define_model(), define_tparams(), tpmatrix_id(), tparams_transprobs(), CohortDtstmTrans()

Examples

Run this code
# NOT RUN {
# Pass vectors
p_12 <- c(.7, .6)
tpmatrix(
  C, p_12,
  0, 1
)

tpmatrix(
  C, p_12,
  C, 1
)

# Pass matrix
pmat <- matrix(c(.5, .5, .3, .7), byrow = TRUE, ncol = 4)
tpmatrix(pmat)

# Pass vectors and data frames
p1 <- data.frame(
  p_12 = c(.7, .6), 
  p_13 = c(.1, .2)
)

p2 <- data.frame(
  p_21 = 0,
  p_22 = c(.4, .45),
  p_23 = c(.6, .55)
)

p3 <- data.frame(
  p_31 = c(0, 0),
  p_32 = c(0, 0),
  p_33 = c(1, 1)
)

tpmatrix(
  C, p1,
  p2,
  p3
)


# }

Run the code above in your browser using DataLab