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 tparams_transprobs object.

...

Currently unused.

prefix, sep

Arguments passed to tpmatrix_names() for naming the transition probability columns. The states argument is based on the column names (i.e., names of the second dimension) of the ⁠$value⁠ element of x; if NULL, then states are named s1, ..., sh where h is the number of states. Only used if long = FALSE.

long

If TRUE, then output is returned in a longer format with one row for each transition; if FALSE, then each row contains an entire flattened transition probability matrix.

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

tparams_transprobs()

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)


[Package hesim version 0.5.4 Index]