Generates a mock observation table and integrates it into an existing CDM object.
Source:R/mockObservation.R
mockObservation.Rd
This function simulates observation records for individuals within a specified cohort. It creates a realistic dataset by generating observation records based on the specified number of records per person. Each observation record is correctly associated with an individual within valid observation periods, ensuring the integrity of the data.
Arguments
- cdm
A `cdm_reference` object that must already include 'person', 'observation_period', and 'concept' tables. This object serves as the base CDM structure where the observation data will be added. The 'person' and 'observation_period' tables must be populated as they are necessary for generating accurate observation records.
- recordPerson
An integer specifying the expected number of observation records to generate per person. This parameter allows for the simulation of varying frequencies of healthcare observations among individuals in the cohort, reflecting real-world variability in patient monitoring and health assessments.
- seed
An optional integer used to set the seed for random number generation, ensuring reproducibility of the generated data. If provided, this seed enables the function to produce consistent results each time it is run with the same inputs. If 'NULL', the seed is not set, which can lead to different outputs on each run.
Value
Returns the modified `cdm` object with the new 'observation' table added. This table includes the simulated observation data for each person, ensuring that each record is correctly linked to individuals in the 'person' table and falls within valid observation periods.
Examples
library(omock)
# Create a mock CDM reference and add observation records
cdm <- mockCdmReference() |>
mockPerson() |>
mockObservationPeriod() |>
mockObservation(recordPerson = 3)
# View the generated observation data
print(cdm$observation)
#> # A tibble: 180 × 18
#> observation_concept_id person_id observation_date observation_id
#> * <int> <int> <date> <int>
#> 1 437738 4 2012-12-11 1
#> 2 437738 1 1978-05-06 2
#> 3 437738 6 2016-06-22 3
#> 4 437738 9 1985-07-20 4
#> 5 437738 5 2012-02-29 5
#> 6 437738 4 2013-02-11 6
#> 7 437738 6 2015-10-03 7
#> 8 437738 2 1981-01-12 8
#> 9 437738 7 2010-06-18 9
#> 10 437738 3 2014-07-05 10
#> # ℹ 170 more rows
#> # ℹ 14 more variables: observation_type_concept_id <int>,
#> # observation_datetime <dttm>, value_as_number <dbl>, value_as_string <chr>,
#> # value_as_concept_id <int>, qualifier_concept_id <int>,
#> # unit_concept_id <int>, provider_id <int>, visit_occurrence_id <int>,
#> # visit_detail_id <int>, observation_source_value <chr>,
#> # observation_source_concept_id <int>, unit_source_value <chr>, …