Create a list containing predicted transition probabilities at discrete times. Since the transition probabilities have presumably already been predicted based on covariate values, no input data is required for simulation. The class can be instantiated from either an array, a data.table, a data.frame, or a tpmatrix. This is the object in hesim used to specify the transition probabilities required to simulate Markov chains with the CohortDtstmTrans class.

tparams_transprobs(object, ...)

# S3 method for array
tparams_transprobs(
  object,
  tpmatrix_id = NULL,
  times = NULL,
  grp_id = NULL,
  patient_wt = NULL,
  ...
)

# S3 method for data.table
tparams_transprobs(object, ...)

# S3 method for data.frame
tparams_transprobs(object, ...)

# S3 method for tpmatrix
tparams_transprobs(object, tpmatrix_id, ...)

Arguments

object

An object of the appropriate class.

...

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

tpmatrix_id

An object of class tpmatrix_id (or an equivalent data.table with the same ID columns as returned by tpmatrix_id()).

times

An optional numeric vector of distinct times to pass to time_intervals representing time intervals indexed by the 4th dimension of the array. May either be the start or the end of intervals. This argument is not required if there is only one time interval.

grp_id

An optional numeric vector of integers denoting the subgroups. Must be the same length as the 3rd dimension of the array.

patient_wt

An optional numeric vector denoting the weight to apply to each patient within a subgroup. Must be the same length as the 3rd dimension of the array.

Value

An object of class tparams_transprobs, which is a list containing value and relevant ID attributes. The element value is an array of predicted transition probability matrices from the probability distribution of the underlying statistical model. Each matrix in value is a prediction for a sample, strategy_id, patient_id, and optionally time_id combination.

Details

The format of object depends on its class:

array

Either a 3D or a 6D array is possible.

  • If a 3D array, then each slice is a square transition probability matrix. In this case tpmatrix_id is required and each matrix slice corresponds to the same numbered row in tpmatrix_id. The number of matrix slices must equal the number of rows in tpmatrix_id.

  • If a 6D array, then the dimensions of the array should be indexed as follows: 1st (sample), 2nd (strategy_id), 3rd (patient_id), 4th (time_id), 5th (rows of transition matrix), and 6th (columns of transition matrix). In other words, an index of [s, k, i, t] represents the transition matrix for the sth sample, kth treatment strategy, ith patient, and tth time interval.

data.table

Must contain the following:

  • ID columns for the parameter sample (sample), treatment strategy (strategy_id), and patient (patient_id). If the number of time intervals is greater than 1 it must also contain the column time_start denoting the starting time of a time interval. A column patient_wt may also be used to denote the weight to apply to each patient.

  • Columns for each element of the transition probability matrix. They should be prefixed with "prob_" and ordered rowwise. For example, the following columns would be used for a 2x2 transition probability matrix: prob_1 (1st row, 1st column), prob_2 (1st row, 2nd column), prob_3 (2nd row, 1st column), and prob_4 (2nd row, 2nd column).

data.frame

Same as data.table.

tpmatrix

An object of class tpmatrix.

A tparams_transprobs object is also instantiated when creating a cohort discrete time state transition model using define_model().

See also

A tparams_transprobs object is used to store the "parameters" of the transition component of a cohort discrete time state transition model (cDTSTM). You can create such an object with CohortDtstmTran$new().

tpmatrix() and tpmatrix_id() provide a convenient way to construct a tparams_transprobs object in a flexible way. define_model() is, in turn, a convenient way to construct a tpmatrix object using mathematical expressions; in this case, an entire cDTSTM can be instantiated from a model definition using create_CohortDtstm.model_def(). Detailed examples are provided in vignette("markov-cohort") and vignette("markov-inhomogeneous-cohort")

The output of a tparams_transprobs object is rather verbose. It can be helpful to check the output by converting it to a data.table (containing both the ID variables and flattened transition probability matrices) with as.data.table.tparams_transprobs(). Transition probabilities can also be summarized (across parameter samples) using summary.tparams_transprobs().

Examples

hesim_dat <- hesim_data(strategies = data.frame(strategy_id = 1:2),
                        patients = data.frame(patient_id = 1:3))
input_data <- expand(hesim_dat, by = c("strategies", "patients"))    

# tpmatrix objects provide a convenient way to construct
# tparams_transprobs() objects
tpmat_id <- tpmatrix_id(input_data, n_samples = 2)      
p_12 <- runif(nrow(tpmat_id), .6, .7) + 
  .05 * (tpmat_id$strategy_id == 2)
tpmat <- tpmatrix(
  C, p_12,
  0, 1
)
tprobs <- tparams_transprobs(tpmat, tpmat_id)
names(tprobs) # Names of list elements
#>  [1] "value"          "strategy_id"    "n_strategies"   "patient_id"    
#>  [5] "n_patients"     "time_id"        "time_intervals" "n_times"       
#>  [9] "sample"         "n_samples"      "grp_id"        

# Convert to data.table in wide format
as.data.table(tprobs)
#>     sample strategy_id patient_id time_id time_start time_stop prob_s1_s1
#>      <int>       <int>      <int>   <num>      <num>     <num>      <num>
#>  1:      1           1          1       1          0       Inf  0.3573288
#>  2:      1           1          2       1          0       Inf  0.3976430
#>  3:      1           1          3       1          0       Inf  0.3899896
#>  4:      1           2          1       1          0       Inf  0.2951765
#>  5:      1           2          2       1          0       Inf  0.2647194
#>  6:      1           2          3       1          0       Inf  0.3103232
#>  7:      2           1          1       1          0       Inf  0.3301205
#>  8:      2           1          2       1          0       Inf  0.3916309
#>  9:      2           1          3       1          0       Inf  0.3103174
#> 10:      2           2          1       1          0       Inf  0.2870937
#> 11:      2           2          2       1          0       Inf  0.2700455
#> 12:      2           2          3       1          0       Inf  0.2631438
#>     prob_s1_s2 prob_s2_s1 prob_s2_s2
#>          <num>      <num>      <num>
#>  1:  0.6426712          0          1
#>  2:  0.6023570          0          1
#>  3:  0.6100104          0          1
#>  4:  0.7048235          0          1
#>  5:  0.7352806          0          1
#>  6:  0.6896768          0          1
#>  7:  0.6698795          0          1
#>  8:  0.6083691          0          1
#>  9:  0.6896826          0          1
#> 10:  0.7129063          0          1
#> 11:  0.7299545          0          1
#> 12:  0.7368562          0          1

# Convert to data.table in long format
as.data.table(tprobs, long = TRUE)
#>     sample strategy_id patient_id time_id time_start time_stop   from     to
#>      <int>       <int>      <int>   <num>      <num>     <num> <char> <char>
#>  1:      1           1          1       1          0       Inf     s1     s1
#>  2:      1           1          1       1          0       Inf     s1     s2
#>  3:      1           1          1       1          0       Inf     s2     s1
#>  4:      1           1          1       1          0       Inf     s2     s2
#>  5:      1           1          2       1          0       Inf     s1     s1
#>  6:      1           1          2       1          0       Inf     s1     s2
#>  7:      1           1          2       1          0       Inf     s2     s1
#>  8:      1           1          2       1          0       Inf     s2     s2
#>  9:      1           1          3       1          0       Inf     s1     s1
#> 10:      1           1          3       1          0       Inf     s1     s2
#> 11:      1           1          3       1          0       Inf     s2     s1
#> 12:      1           1          3       1          0       Inf     s2     s2
#> 13:      1           2          1       1          0       Inf     s1     s1
#> 14:      1           2          1       1          0       Inf     s1     s2
#> 15:      1           2          1       1          0       Inf     s2     s1
#> 16:      1           2          1       1          0       Inf     s2     s2
#> 17:      1           2          2       1          0       Inf     s1     s1
#> 18:      1           2          2       1          0       Inf     s1     s2
#> 19:      1           2          2       1          0       Inf     s2     s1
#> 20:      1           2          2       1          0       Inf     s2     s2
#> 21:      1           2          3       1          0       Inf     s1     s1
#> 22:      1           2          3       1          0       Inf     s1     s2
#> 23:      1           2          3       1          0       Inf     s2     s1
#> 24:      1           2          3       1          0       Inf     s2     s2
#> 25:      2           1          1       1          0       Inf     s1     s1
#> 26:      2           1          1       1          0       Inf     s1     s2
#> 27:      2           1          1       1          0       Inf     s2     s1
#> 28:      2           1          1       1          0       Inf     s2     s2
#> 29:      2           1          2       1          0       Inf     s1     s1
#> 30:      2           1          2       1          0       Inf     s1     s2
#> 31:      2           1          2       1          0       Inf     s2     s1
#> 32:      2           1          2       1          0       Inf     s2     s2
#> 33:      2           1          3       1          0       Inf     s1     s1
#> 34:      2           1          3       1          0       Inf     s1     s2
#> 35:      2           1          3       1          0       Inf     s2     s1
#> 36:      2           1          3       1          0       Inf     s2     s2
#> 37:      2           2          1       1          0       Inf     s1     s1
#> 38:      2           2          1       1          0       Inf     s1     s2
#> 39:      2           2          1       1          0       Inf     s2     s1
#> 40:      2           2          1       1          0       Inf     s2     s2
#> 41:      2           2          2       1          0       Inf     s1     s1
#> 42:      2           2          2       1          0       Inf     s1     s2
#> 43:      2           2          2       1          0       Inf     s2     s1
#> 44:      2           2          2       1          0       Inf     s2     s2
#> 45:      2           2          3       1          0       Inf     s1     s1
#> 46:      2           2          3       1          0       Inf     s1     s2
#> 47:      2           2          3       1          0       Inf     s2     s1
#> 48:      2           2          3       1          0       Inf     s2     s2
#>     sample strategy_id patient_id time_id time_start time_stop   from     to
#>          prob
#>         <num>
#>  1: 0.3573288
#>  2: 0.6426712
#>  3: 0.0000000
#>  4: 1.0000000
#>  5: 0.3976430
#>  6: 0.6023570
#>  7: 0.0000000
#>  8: 1.0000000
#>  9: 0.3899896
#> 10: 0.6100104
#> 11: 0.0000000
#> 12: 1.0000000
#> 13: 0.2951765
#> 14: 0.7048235
#> 15: 0.0000000
#> 16: 1.0000000
#> 17: 0.2647194
#> 18: 0.7352806
#> 19: 0.0000000
#> 20: 1.0000000
#> 21: 0.3103232
#> 22: 0.6896768
#> 23: 0.0000000
#> 24: 1.0000000
#> 25: 0.3301205
#> 26: 0.6698795
#> 27: 0.0000000
#> 28: 1.0000000
#> 29: 0.3916309
#> 30: 0.6083691
#> 31: 0.0000000
#> 32: 1.0000000
#> 33: 0.3103174
#> 34: 0.6896826
#> 35: 0.0000000
#> 36: 1.0000000
#> 37: 0.2870937
#> 38: 0.7129063
#> 39: 0.0000000
#> 40: 1.0000000
#> 41: 0.2700455
#> 42: 0.7299545
#> 43: 0.0000000
#> 44: 1.0000000
#> 45: 0.2631438
#> 46: 0.7368562
#> 47: 0.0000000
#> 48: 1.0000000
#>          prob

# Summary where each column is a vector
summary(tprobs)
#>     strategy_id patient_id time_id time_start time_stop   from     to      mean
#>           <int>      <int>   <num>      <num>     <num> <char> <char>     <num>
#>  1:           1          1       1          0       Inf     s1     s1 0.3437247
#>  2:           1          1       1          0       Inf     s1     s2 0.6562753
#>  3:           1          1       1          0       Inf     s2     s1 0.0000000
#>  4:           1          1       1          0       Inf     s2     s2 1.0000000
#>  5:           1          2       1          0       Inf     s1     s1 0.3946369
#>  6:           1          2       1          0       Inf     s1     s2 0.6053631
#>  7:           1          2       1          0       Inf     s2     s1 0.0000000
#>  8:           1          2       1          0       Inf     s2     s2 1.0000000
#>  9:           1          3       1          0       Inf     s1     s1 0.3501535
#> 10:           1          3       1          0       Inf     s1     s2 0.6498465
#> 11:           1          3       1          0       Inf     s2     s1 0.0000000
#> 12:           1          3       1          0       Inf     s2     s2 1.0000000
#> 13:           2          1       1          0       Inf     s1     s1 0.2911351
#> 14:           2          1       1          0       Inf     s1     s2 0.7088649
#> 15:           2          1       1          0       Inf     s2     s1 0.0000000
#> 16:           2          1       1          0       Inf     s2     s2 1.0000000
#> 17:           2          2       1          0       Inf     s1     s1 0.2673824
#> 18:           2          2       1          0       Inf     s1     s2 0.7326176
#> 19:           2          2       1          0       Inf     s2     s1 0.0000000
#> 20:           2          2       1          0       Inf     s2     s2 1.0000000
#> 21:           2          3       1          0       Inf     s1     s1 0.2867335
#> 22:           2          3       1          0       Inf     s1     s2 0.7132665
#> 23:           2          3       1          0       Inf     s2     s1 0.0000000
#> 24:           2          3       1          0       Inf     s2     s2 1.0000000
#>     strategy_id patient_id time_id time_start time_stop   from     to      mean
#>              sd
#>           <num>
#>  1: 0.019239113
#>  2: 0.019239113
#>  3: 0.000000000
#>  4: 0.000000000
#>  5: 0.004251159
#>  6: 0.004251159
#>  7: 0.000000000
#>  8: 0.000000000
#>  9: 0.056336744
#> 10: 0.056336744
#> 11: 0.000000000
#> 12: 0.000000000
#> 13: 0.005715383
#> 14: 0.005715383
#> 15: 0.000000000
#> 16: 0.000000000
#> 17: 0.003766132
#> 18: 0.003766132
#> 19: 0.000000000
#> 20: 0.000000000
#> 21: 0.033360839
#> 22: 0.033360839
#> 23: 0.000000000
#> 24: 0.000000000
#>              sd
summary(tprobs, probs = c(.025, .975))
#>     strategy_id patient_id time_id time_start time_stop   from     to      mean
#>           <int>      <int>   <num>      <num>     <num> <char> <char>     <num>
#>  1:           1          1       1          0       Inf     s1     s1 0.3437247
#>  2:           1          1       1          0       Inf     s1     s2 0.6562753
#>  3:           1          1       1          0       Inf     s2     s1 0.0000000
#>  4:           1          1       1          0       Inf     s2     s2 1.0000000
#>  5:           1          2       1          0       Inf     s1     s1 0.3946369
#>  6:           1          2       1          0       Inf     s1     s2 0.6053631
#>  7:           1          2       1          0       Inf     s2     s1 0.0000000
#>  8:           1          2       1          0       Inf     s2     s2 1.0000000
#>  9:           1          3       1          0       Inf     s1     s1 0.3501535
#> 10:           1          3       1          0       Inf     s1     s2 0.6498465
#> 11:           1          3       1          0       Inf     s2     s1 0.0000000
#> 12:           1          3       1          0       Inf     s2     s2 1.0000000
#> 13:           2          1       1          0       Inf     s1     s1 0.2911351
#> 14:           2          1       1          0       Inf     s1     s2 0.7088649
#> 15:           2          1       1          0       Inf     s2     s1 0.0000000
#> 16:           2          1       1          0       Inf     s2     s2 1.0000000
#> 17:           2          2       1          0       Inf     s1     s1 0.2673824
#> 18:           2          2       1          0       Inf     s1     s2 0.7326176
#> 19:           2          2       1          0       Inf     s2     s1 0.0000000
#> 20:           2          2       1          0       Inf     s2     s2 1.0000000
#> 21:           2          3       1          0       Inf     s1     s1 0.2867335
#> 22:           2          3       1          0       Inf     s1     s2 0.7132665
#> 23:           2          3       1          0       Inf     s2     s1 0.0000000
#> 24:           2          3       1          0       Inf     s2     s2 1.0000000
#>     strategy_id patient_id time_id time_start time_stop   from     to      mean
#>              sd      2.5%     97.5%
#>           <num>     <num>     <num>
#>  1: 0.019239113 0.3308008 0.3566486
#>  2: 0.019239113 0.6433514 0.6691992
#>  3: 0.000000000 0.0000000 0.0000000
#>  4: 0.000000000 1.0000000 1.0000000
#>  5: 0.004251159 0.3917812 0.3974927
#>  6: 0.004251159 0.6025073 0.6082188
#>  7: 0.000000000 0.0000000 0.0000000
#>  8: 0.000000000 1.0000000 1.0000000
#>  9: 0.056336744 0.3123092 0.3879978
#> 10: 0.056336744 0.6120022 0.6876908
#> 11: 0.000000000 0.0000000 0.0000000
#> 12: 0.000000000 1.0000000 1.0000000
#> 13: 0.005715383 0.2872958 0.2949744
#> 14: 0.005715383 0.7050256 0.7127042
#> 15: 0.000000000 0.0000000 0.0000000
#> 16: 0.000000000 1.0000000 1.0000000
#> 17: 0.003766132 0.2648525 0.2699123
#> 18: 0.003766132 0.7300877 0.7351475
#> 19: 0.000000000 0.0000000 0.0000000
#> 20: 0.000000000 1.0000000 1.0000000
#> 21: 0.033360839 0.2643233 0.3091437
#> 22: 0.033360839 0.6908563 0.7356767
#> 23: 0.000000000 0.0000000 0.0000000
#> 24: 0.000000000 1.0000000 1.0000000
#>              sd      2.5%     97.5%

# Summary where each column is a matrix
ps <- summary(tprobs, id = tpmat_id, unflatten = TRUE)
ps
#>    strategy_id patient_id time_id time_start time_stop
#>          <int>      <int>   <num>      <num>     <num>
#> 1:           1          1       1          0       Inf
#> 2:           1          2       1          0       Inf
#> 3:           1          3       1          0       Inf
#> 4:           2          1       1          0       Inf
#> 5:           2          2       1          0       Inf
#> 6:           2          3       1          0       Inf
#>                                       mean
#>                                     <list>
#> 1: 0.3437247,0.0000000,0.6562753,1.0000000
#> 2: 0.3946369,0.0000000,0.6053631,1.0000000
#> 3: 0.3501535,0.0000000,0.6498465,1.0000000
#> 4: 0.2911351,0.0000000,0.7088649,1.0000000
#> 5: 0.2673824,0.0000000,0.7326176,1.0000000
#> 6: 0.2867335,0.0000000,0.7132665,1.0000000
#>                                                 sd
#>                                             <list>
#> 1:     0.01923911,0.00000000,0.01923911,0.00000000
#> 2: 0.004251159,0.000000000,0.004251159,0.000000000
#> 3:     0.05633674,0.00000000,0.05633674,0.00000000
#> 4: 0.005715383,0.000000000,0.005715383,0.000000000
#> 5: 0.003766132,0.000000000,0.003766132,0.000000000
#> 6:     0.03336084,0.00000000,0.03336084,0.00000000
ps$mean
#> [[1]]
#>           s1        s2
#> s1 0.3437247 0.6562753
#> s2 0.0000000 1.0000000
#> 
#> [[2]]
#>           s1        s2
#> s1 0.3946369 0.6053631
#> s2 0.0000000 1.0000000
#> 
#> [[3]]
#>           s1        s2
#> s1 0.3501535 0.6498465
#> s2 0.0000000 1.0000000
#> 
#> [[4]]
#>           s1        s2
#> s1 0.2911351 0.7088649
#> s2 0.0000000 1.0000000
#> 
#> [[5]]
#>           s1        s2
#> s1 0.2673824 0.7326176
#> s2 0.0000000 1.0000000
#> 
#> [[6]]
#>           s1        s2
#> s1 0.2867335 0.7132665
#> s2 0.0000000 1.0000000
#>