Generate survival dates from their anchor dates
Source:R/mock_spec_survival.R
generate_survival_dates.RdComputes each type = "survival" variable in spec from its anchor column
in data: floor(n * event_prop) rows receive a date a follow-up time
after the anchor (whole days, within [followup_min, followup_max]), and
the rest are NA. Variables are processed in dependency order; each is
drawn and then has its rules applied: a date earlier than its anchor
becomes NA, and, if censored_by is set, a date later than the censoring
date becomes NA. Draws use the isolated survival sub-stream of the seed
contract.
Arguments
- data
Data frame of generated baseline values (from
generate_mock_data_native()orgenerate_mock_data_simstudy()), containing each anchor column as classDate.- spec
A
mock_spec. Strict-validated at entry.- seed
Optional whole-number seed. The caller's RNG state and kind are restored on exit.
Value
data with one appended Date column per survival variable.
Returns data unchanged if the spec has no survival variables.
Details
Survival dates describe true values. postprocess_mock_data() applies
missing codes and garbage afterwards, independently for each column.
Examples
spec <- mock_spec(
mock_spec_date("entry", range = as.Date(c("2001-01-01", "2005-12-31"))),
mock_spec_survival("death", anchor = "entry",
followup_min = 365, followup_max = 7300, event_prop = 0.2)
)
baseline <- generate_mock_data_native(spec, n = 10, seed = 1)
generate_survival_dates(baseline, spec, seed = 1)
#> entry death
#> 1 2004-10-26 <NA>
#> 2 2004-10-14 2009-01-17
#> 3 2001-09-28 <NA>
#> 4 2004-04-09 <NA>
#> 5 2003-04-21 <NA>
#> 6 2004-12-21 <NA>
#> 7 2002-10-18 <NA>
#> 8 2005-12-14 <NA>
#> 9 2005-06-09 2011-02-24
#> 10 2001-02-16 <NA>