Skip to contents

Sample a level of each subgroup variable for each patient, independently across patients, from the posterior probabilities estimated by group_analysis_probability().

Usage

group_sample_unconstrained(patient, summary)

Arguments

patient

Patient-level survival data, the output of group_data_patient().

summary

Summary subgroup statistics, the output of group_data_summary().

Value

A tibble with one row per patient, in the same order as the rows of patient. The columns are all the columns of patient, followed by one column per subgroup variable, in the order the subgroup variables first appear in summary$variable. Each subgroup column is a factor of the sampled levels whose levels are those of the subgroup variable in summary$level, in the same order.

Details

group_sample_unconstrained() implements the "Unconstrained sampling" section of vignette("sampling", package = "retrogroup"). For each subgroup variable and each patient \(i\), it draws \(x_i \sim \text{Categorical}(p_{i1}, \ldots, p_{iK})\) independently, where the \(p_{ik}\) come from group_analysis_probability(). All the requirements of group_analysis_probability() on patient and summary apply. In addition, no subgroup variable in summary may have the same name as a column of patient.

The sampled number of patients in each subgroup level is not guaranteed to equal the assumed number of patients in summary. Use group_sample_constrained() to preserve the assumed counts.

vignette("prognostic", package = "retrogroup") examines the prognostic information of reconstructed subgroups.

Sampling uses R's random number generator. Call set.seed() beforehand for reproducible results.

See also

Examples

  patient <- group_data_patient(
    group_example_patient(),
    arm = "arm",
    treatment = "Lev+5FU",
    time = "time",
    event = "event"
  )
  summary <- group_data_summary(
    group_example_summary(),
    variable = "variable",
    level = "level",
    patients = "patients",
    events = "events",
    hazard_ratio = "hazard_ratio"
  )
  set.seed(0)
  sample <- group_sample_unconstrained(patient, summary)
  sample
#> # A tibble: 619 × 6
#>    treatment  time event age        node4 sex   
#>        <int> <dbl> <int> <fct>      <fct> <fct> 
#>  1         1  1521     1 60 or over no    female
#>  2         1  3087     0 under 60   no    female
#>  3         0   963     1 under 60   yes   male  
#>  4         1   293     1 60 or over no    female
#>  5         0   659     1 60 or over yes   male  
#>  6         1  1767     1 under 60   no    female
#>  7         0  3192     0 60 or over no    female
#>  8         1  3308     0 60 or over no    male  
#>  9         1  3309     0 60 or over no    male  
#> 10         0  2085     1 60 or over no    male  
#> # ℹ 609 more rows
  table(sample$age)
#> 
#>   under 60 60 or over 
#>        284        335