expand.hesim_data: Expand hesim_data

View source: R/hesim_data.R

expand.hesim_dataR Documentation

Expand hesim_data

Description

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.

Usage

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

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.

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.

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"))
expand(hesim_dat, by = c("strategies", "patients"),
       times = c(0, 2, 10))

hesim-dev/hesim documentation built on Feb. 14, 2024, 1:18 a.m.