Skip to contents

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.

Usage

mockDeath(cdm, recordPerson = 1, seed = NULL)

Arguments

cdm

A local cdm_reference object used as the base structure to update.

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 random seed for reproducibility. If NULL, the seed is not set.

Value

A modified cdm_reference object.

Examples

# \donttest{
library(omock)
library(dplyr)

# Create a mock CDM reference and add death records
cdm <- mockCdmReference() |>
  mockPerson() |>
  mockObservationPeriod() |>
  mockDeath(recordPerson = 1)

# View the generated death data
cdm$death |>
glimpse()
#> Rows: 10
#> Columns: 7
#> $ person_id               <int> 8, 1, 4, 9, 7, 5, 2, 10, 3, 6
#> $ death_date              <date> 2012-08-31, 2010-01-19, 1986-11-16, 2007-02-24…
#> $ death_type_concept_id   <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#> $ death_datetime          <dttm> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ cause_concept_id        <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ cause_source_value      <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ cause_source_concept_id <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
# }