Generates a mock death table and integrates it into an existing CDM object.
Source:R/mockDeath.R
mockDeath.Rd
This function simulates death records for individuals within a specified cohort. It creates a realistic dataset by generating death records according to the specified number of records per person. The function ensures that each death record is associated with a valid person within the observation period to maintain the integrity of the data.
Arguments
- cdm
A `cdm_reference` object that must already include 'person' and 'observation_period' tables.This object is the base CDM structure where the death data will be added. It is essential that the 'person' and 'observation_period' tables are populated as they provide necessary context for generating death records.
- recordPerson
An integer specifying the expected number of death records to generate per person. This parameter helps simulate varying frequencies of death occurrences among individuals in the cohort, reflecting the variability seen in real-world medical data. Typically, this would be set to 1 or 0, assuming most datasets would only record a single death date per individual if at all.
- seed
An optional integer used to set the seed for random number generation, ensuring reproducibility of the generated data. If provided, it allows the function to produce the same results each time it is run with the same inputs. If 'NULL', the seed is not set, which can result in different outputs on each run.
Value
Returns the modified `cdm` object with the new 'death' table added. This table includes the simulated death data for each person, ensuring that each record is linked correctly to individuals in the ' person' table and falls within valid observation periods.
Examples
# \donttest{
library(omock)
# Create a mock CDM reference and add death records
cdm <- mockCdmReference() |>
mockPerson() |>
mockObservationPeriod() |>
mockDeath(recordPerson = 1)
# View the generated death data
print(cdm$death)
#> # A tibble: 10 × 7
#> person_id death_date death_type_concept_id death_datetime
#> * <int> <date> <int> <dttm>
#> 1 3 2012-06-08 1 NA
#> 2 9 2015-10-03 1 NA
#> 3 4 2013-12-31 1 NA
#> 4 8 2005-06-26 1 NA
#> 5 5 2016-12-23 1 NA
#> 6 1 2015-12-30 1 NA
#> 7 10 2012-03-22 1 NA
#> 8 2 2017-12-13 1 NA
#> 9 7 2014-05-17 1 NA
#> 10 6 2009-09-05 1 NA
#> # ℹ 3 more variables: cause_concept_id <int>, cause_source_value <chr>,
#> # cause_source_concept_id <int>
# }