Creates a data.table that combines the transition probability matrices and ID variables from a tparams_transprobs object. This is often useful for debugging.

# S3 method for 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

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)
#> sample strategy_id patient_id time_id time_start time_stop prob_s1_s1 #> 1: 1 1 1 1 0 Inf 0.3649139 #> 2: 1 1 2 1 0 Inf 0.3661345 #> 3: 1 1 3 1 0 Inf 0.3897945 #> 4: 1 2 1 1 0 Inf 0.2952595 #> 5: 1 2 2 1 0 Inf 0.2936636 #> 6: 1 2 3 1 0 Inf 0.3029685 #> 7: 2 1 1 1 0 Inf 0.3418968 #> 8: 2 1 2 1 0 Inf 0.3645832 #> 9: 2 1 3 1 0 Inf 0.3852402 #> 10: 2 2 1 1 0 Inf 0.2553074 #> 11: 2 2 2 1 0 Inf 0.2761609 #> 12: 2 2 3 1 0 Inf 0.2710729 #> prob_s1_s2 prob_s2_s1 prob_s2_s2 #> 1: 0.6350861 0 1 #> 2: 0.6338655 0 1 #> 3: 0.6102055 0 1 #> 4: 0.7047405 0 1 #> 5: 0.7063364 0 1 #> 6: 0.6970315 0 1 #> 7: 0.6581032 0 1 #> 8: 0.6354168 0 1 #> 9: 0.6147598 0 1 #> 10: 0.7446926 0 1 #> 11: 0.7238391 0 1 #> 12: 0.7289271 0 1
as.data.table(tprobs, prefix = "")
#> sample strategy_id patient_id time_id time_start time_stop s1_s1 #> 1: 1 1 1 1 0 Inf 0.3649139 #> 2: 1 1 2 1 0 Inf 0.3661345 #> 3: 1 1 3 1 0 Inf 0.3897945 #> 4: 1 2 1 1 0 Inf 0.2952595 #> 5: 1 2 2 1 0 Inf 0.2936636 #> 6: 1 2 3 1 0 Inf 0.3029685 #> 7: 2 1 1 1 0 Inf 0.3418968 #> 8: 2 1 2 1 0 Inf 0.3645832 #> 9: 2 1 3 1 0 Inf 0.3852402 #> 10: 2 2 1 1 0 Inf 0.2553074 #> 11: 2 2 2 1 0 Inf 0.2761609 #> 12: 2 2 3 1 0 Inf 0.2710729 #> s1_s2 s2_s1 s2_s2 #> 1: 0.6350861 0 1 #> 2: 0.6338655 0 1 #> 3: 0.6102055 0 1 #> 4: 0.7047405 0 1 #> 5: 0.7063364 0 1 #> 6: 0.6970315 0 1 #> 7: 0.6581032 0 1 #> 8: 0.6354168 0 1 #> 9: 0.6147598 0 1 #> 10: 0.7446926 0 1 #> 11: 0.7238391 0 1 #> 12: 0.7289271 0 1
as.data.table(tprobs, prefix = "", sep = ".")
#> sample strategy_id patient_id time_id time_start time_stop s1.s1 #> 1: 1 1 1 1 0 Inf 0.3649139 #> 2: 1 1 2 1 0 Inf 0.3661345 #> 3: 1 1 3 1 0 Inf 0.3897945 #> 4: 1 2 1 1 0 Inf 0.2952595 #> 5: 1 2 2 1 0 Inf 0.2936636 #> 6: 1 2 3 1 0 Inf 0.3029685 #> 7: 2 1 1 1 0 Inf 0.3418968 #> 8: 2 1 2 1 0 Inf 0.3645832 #> 9: 2 1 3 1 0 Inf 0.3852402 #> 10: 2 2 1 1 0 Inf 0.2553074 #> 11: 2 2 2 1 0 Inf 0.2761609 #> 12: 2 2 3 1 0 Inf 0.2710729 #> s1.s2 s2.s1 s2.s2 #> 1: 0.6350861 0 1 #> 2: 0.6338655 0 1 #> 3: 0.6102055 0 1 #> 4: 0.7047405 0 1 #> 5: 0.7063364 0 1 #> 6: 0.6970315 0 1 #> 7: 0.6581032 0 1 #> 8: 0.6354168 0 1 #> 9: 0.6147598 0 1 #> 10: 0.7446926 0 1 #> 11: 0.7238391 0 1 #> 12: 0.7289271 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 #> 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 #> 1: 0.3649139 #> 2: 0.6350861 #> 3: 0.0000000 #> 4: 1.0000000 #> 5: 0.3661345 #> 6: 0.6338655 #> 7: 0.0000000 #> 8: 1.0000000 #> 9: 0.3897945 #> 10: 0.6102055 #> 11: 0.0000000 #> 12: 1.0000000 #> 13: 0.2952595 #> 14: 0.7047405 #> 15: 0.0000000 #> 16: 1.0000000 #> 17: 0.2936636 #> 18: 0.7063364 #> 19: 0.0000000 #> 20: 1.0000000 #> 21: 0.3029685 #> 22: 0.6970315 #> 23: 0.0000000 #> 24: 1.0000000 #> 25: 0.3418968 #> 26: 0.6581032 #> 27: 0.0000000 #> 28: 1.0000000 #> 29: 0.3645832 #> 30: 0.6354168 #> 31: 0.0000000 #> 32: 1.0000000 #> 33: 0.3852402 #> 34: 0.6147598 #> 35: 0.0000000 #> 36: 1.0000000 #> 37: 0.2553074 #> 38: 0.7446926 #> 39: 0.0000000 #> 40: 1.0000000 #> 41: 0.2761609 #> 42: 0.7238391 #> 43: 0.0000000 #> 44: 1.0000000 #> 45: 0.2710729 #> 46: 0.7289271 #> 47: 0.0000000 #> 48: 1.0000000 #> prob