Get value labels for the ID variables in a hesim_data object and create a list of named vectors that can be passed to formatting and plotting functions. This lets users create nice labels for treatment strategies, subgroups, health states, and/or transitions when presenting results.

get_labels(
  object,
  strategy = "strategy_name",
  grp = "grp_name",
  state = "state_name",
  transition = "transition_name",
  death_label = "Death"
)

Arguments

object

An object of class hesim_data created with hesim_data().

strategy

The name of the column in the strategy element of object containing labels for strategy_id.

grp

The name of the column in the patient element of object containing labels for grp_id.

state

The name of the column in the state element of object containing labels for state_id.

transition

The name of the column in the transition element of object containing labels for transition_id.

death_label

The label to use for the death health state. By default a label named "Death" will be concatenated to the labels for the non-death health states. The death state can be omitted from labels for the health states by setting death_label = NULL.

Value

A list of named vectors containing the values and labels of variables. The elements of each vector are the values of a variable and the names are the labels. The names of the list are the names of the ID variables.

Examples

library("data.table")
strategies <- data.table(
  strategy_id = c(1, 2),
  strategy_name = c("Strategy 1", "Strategy 2")
)
patients <- data.table(
  patient_id = seq(1, 4),
  age = c(50, 55, 60, 65),
  grp_id = c(1, 1, 2, 2),
  grp_name = rep(c("Age 50-59", "Age 60-69"), each = 2)
)
states <- data.table(
  state_id =  seq(1, 2),
  state_name = c("State 1", "State 2")
)
hesim_dat <- hesim_data(
  strategies = strategies,
  patients = patients,
  states = states
)
labs <- get_labels(hesim_dat)
labs
#> $strategy_id
#> Strategy 1 Strategy 2 
#>          1          2 
#> 
#> $grp_id
#> Age 50-59 Age 60-69 
#>         1         2 
#> 
#> $state_id
#> State 1 State 2   Death 
#>       1       2       3 
#> 

# Pass to set_labels()
d <- data.table(strategy_id = c(1, 1, 2, 2),
                grp_id = c(1, 2, 1, 2))
set_labels(d, labs, new_name = c("strategy_name", "grp_name"))
d
#>    strategy_id grp_id strategy_name  grp_name
#>          <num>  <num>        <fctr>    <fctr>
#> 1:           1      1    Strategy 1 Age 50-59
#> 2:           1      2    Strategy 1 Age 60-69
#> 3:           2      1    Strategy 2 Age 50-59
#> 4:           2      2    Strategy 2 Age 60-69