Create a data table in long format from all combinations of specified tables from an object of class hesim_data and optionally time intervals. See "Details" for an explanation of how the expansion is done.

# S3 method for hesim_data
expand(object, by = c("strategies", "patients"), times = NULL)

Arguments

object

An object of class hesim_data.

by

A character vector of the names of the data tables in hesim_data to expand by.

times

Either a numeric vector of distinct times denoting the start of time intervals or a time_intervals object.

Value

An object of class expanded_hesim_data, which is a data.table with an "id_vars" attribute containing the names of the ID variables in the data table and, if times is not NULL, a time_intervals object derived from times.

Details

This function is similar to expand.grid(), but works for data frames or data tables. Specifically, it creates a data.table from all combinations of the supplied tables in object and optionally the start of times intervals in times. The supplied tables are determined using the by argument. The resulting dataset is sorted by prioritizing ID variables as follows: (i) strategy_id, (ii) patient_id, (iii) the health-related ID variable (either state_id or transition_id, and (iv) the time intervals from times.

Examples

strategies <- data.frame(strategy_id = c(1, 2)) patients <- data.frame(patient_id = seq(1, 3), age = c(65, 50, 75), gender = c("Female", "Female", "Male")) states <- data.frame(state_id = seq(1, 3), state_var = c(2, 1, 9)) hesim_dat <- hesim_data(strategies = strategies, patients = patients, states = states) expand(hesim_dat, by = c("strategies", "patients"))
#> strategy_id patient_id age gender #> 1: 1 1 65 Female #> 2: 1 2 50 Female #> 3: 1 3 75 Male #> 4: 2 1 65 Female #> 5: 2 2 50 Female #> 6: 2 3 75 Male
expand(hesim_dat, by = c("strategies", "patients"), times = c(0, 2, 10))
#> strategy_id patient_id time_id age gender time_start time_stop #> 1: 1 1 1 65 Female 0 2 #> 2: 1 1 2 65 Female 2 10 #> 3: 1 1 3 65 Female 10 Inf #> 4: 1 2 1 50 Female 0 2 #> 5: 1 2 2 50 Female 2 10 #> 6: 1 2 3 50 Female 10 Inf #> 7: 1 3 1 75 Male 0 2 #> 8: 1 3 2 75 Male 2 10 #> 9: 1 3 3 75 Male 10 Inf #> 10: 2 1 1 65 Female 0 2 #> 11: 2 1 2 65 Female 2 10 #> 12: 2 1 3 65 Female 10 Inf #> 13: 2 2 1 50 Female 0 2 #> 14: 2 2 2 50 Female 2 10 #> 15: 2 2 3 50 Female 10 Inf #> 16: 2 3 1 75 Male 0 2 #> 17: 2 3 2 75 Male 2 10 #> 18: 2 3 3 75 Male 10 Inf