tparams_transprobs {hesim} | R Documentation |
Transition probabilities
Description
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.
Usage
tparams_transprobs(object, ...)
## S3 method for class 'array'
tparams_transprobs(
object,
tpmatrix_id = NULL,
times = NULL,
grp_id = NULL,
patient_wt = NULL,
...
)
## S3 method for class 'data.table'
tparams_transprobs(object, ...)
## S3 method for class 'data.frame'
tparams_transprobs(object, ...)
## S3 method for class '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 |
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. |
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 intpmatrix_id
. The number of matrix slices must equal the number of rows intpmatrix_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 thes
th sample,k
th treatment strategy,i
th patient, andt
th 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 columntime_start
denoting the starting time of a time interval. A columnpatient_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), andprob_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()
.
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.
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
# Convert to data.table in wide format
as.data.table(tprobs)
# Convert to data.table in long format
as.data.table(tprobs, long = TRUE)
# Summary where each column is a vector
summary(tprobs)
summary(tprobs, probs = c(.025, .975))
# Summary where each column is a matrix
ps <- summary(tprobs, id = tpmat_id, unflatten = TRUE)
ps
ps$mean