as.data.table.tparams_transprobs {hesim} | R Documentation |
Coerce to data.table
Description
Creates a data.table
that combines the transition probability matrices
and ID variables from a tparams_transprobs
object. This is often useful for
debugging.
Usage
## S3 method for class 'tparams_transprobs'
as.data.table(x, ..., prefix = "prob_", sep = "_", long = FALSE)
Arguments
x |
A |
... |
Currently unused. |
prefix , sep |
Arguments passed to |
long |
If |
Value
The output always contains columns for the ID variables and the
transition probabilities, but the form depends on on the long
argument.
If FALSE
, then a data.table
with one row for each transition probability
matrix is returned; otherwise, the data.table
contains one row for each
transition and columns from
(the state being transitioned from) and
to
(the state being transitioned to) are added.
See Also
Examples
# Create tparams_transprobs object
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"))
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)
# Convert to data.table in "wide" format
as.data.table(tprobs)
as.data.table(tprobs, prefix = "")
as.data.table(tprobs, prefix = "", sep = ".")
# Convert to data.table in "long: format
as.data.table(tprobs, long = TRUE)