Skip to contents

Fits sequential CART models to a real casualty cohort with synthpop::syn() and draws a synthetic replica from them. Use this when the real data cannot be shared but its multivariate structure should survive into something that can be.

Usage

sdt_synthesise(data, n = NULL, method = "cart", seed = NULL, verbose = FALSE)

Arguments

data

A real cohort, or any data frame carrying the cohort columns.

n

Number of synthetic rows to draw. Defaults to nrow(data).

method

synthpop method, passed to synthpop::syn(). "cart" is the default and handles mixed types without distributional assumptions.

seed

Optional integer seed, applied with withr::local_seed().

verbose

If TRUE, let synthpop report its progress.

Value

A cohort object of n rows. Identifier and ordering columns are regenerated rather than synthesised, because carrying them over would leak the seed data's row identities.

Details

Unlike sdt_synthetic_cohort(), which generates from marginals alone, this reproduces the joint structure of the seed data, including relationships nobody thought to specify. That is the point, and also the risk: a synthetic record that lands too close to a real one is a disclosure. Score the replica with sdt_synthesis_utility() before releasing it.

See also

sdt_synthesis_utility() to score the replica against its seed.

Examples

seed_cohort <- sdt_synthetic_cohort(n = 60, seed = 1)
if (requireNamespace("synthpop", quietly = TRUE)) {
  replica <- sdt_synthesise(seed_cohort, n = 30, seed = 2)
  replica
}
#> # A cohort: 30 casualties
#> # Triage:   red: 9 yellow: 12 green: 9
#>    id      age sex   life_points ventilated injury_region triage therapy
#>    <chr> <int> <chr>       <int> <lgl>      <chr>         <chr>  <chr>  
#>  1 P001     33 d               2 FALSE      multiple      red    TASC   
#>  2 P002     42 m               5 FALSE      multiple      green  TASC   
#>  3 P003     31 m               2 FALSE      abdomen       red    TASC   
#>  4 P004     53 f               3 FALSE      head          yellow DCS    
#>  5 P005     49 f               1 TRUE       head          red    DCS    
#>  6 P006     41 m               4 FALSE      multiple      yellow none   
#>  7 P007     43 m               5 FALSE      multiple      green  none   
#>  8 P008     40 f               1 TRUE       extremity     red    TASC   
#>  9 P009     40 m               3 FALSE      abdomen       yellow DCS    
#> 10 P010     37 m               1 TRUE       multiple      red    TASC   
#> # ℹ 20 more rows
#> # ℹ 1 more variable: arrival_order <int>