
Compare runPregnancyIdentifier results with the OMOP Pregnancy Extension Table (PET)
Source:R/compareWithPET.R
comparePregnancyIdentifierWithPET.RdCompares algorithm output (from final_pregnancy_episodes.rds) to the PET
table and writes comparison summaries to exportFolder. Comparisons include:
pregnancy episode and person counts; raw and filtered (gestation 0-308, end >= start)
person overlap; Venn counts (both, PET only, algorithm only); a 2x2 confusion matrix
(TP, FN, FP, TN) with sensitivity and PPV (no gold-standard negatives, so specificity
and NPV are not defined); date differences for matched pairs (start, end, duration,
overall and stratified by outcome); outcome confusion matrix and accuracy;
outcome comparison by year (same-year pairs, cross-tab LB/SB/AB vs PET outcome);
and pregnancy duration distributions.
Usage
comparePregnancyIdentifierWithPET(
cdm,
outputFolder,
exportFolder,
petSchema,
petTable,
startDate = NULL,
endDate = NULL,
minOverlapDays = 1L,
removeWithinSourceOverlaps = FALSE,
minCellCount = 5L,
outputLogToConsole = TRUE
)Arguments
- cdm
A
cdm_reference(from CDMConnector) with a database connection. The PET table is read viapetSchemaandpetTable.- outputFolder
character(1). Directory containing pipeline outputs (final_pregnancy_episodes.rds), i.e. the episode-level input to the comparison.- exportFolder
character(1). Directory where comparison CSVs andlog.txtare written. Created if it does not exist. Log file is appended if it already exists.- petSchema
character(1). Schema name of the PET table (e.g."omop_cmbd").- petTable
character(1). Table name of the pregnancy episode table (e.g."pregnancy_episode"). Must contain at leastperson_id,pregnancy_start_date,pregnancy_end_date, andpregnancy_outcome(concept_id). Gestational length in days is computed from start and end dates in the database viaCDMConnector::datediff(); the table need not have agestational_length_in_daycolumn.- startDate
Date(1)orNULL. If provided, the PET table is filtered to episodes that overlap the study period defined by[startDate, endDate]. An episode overlaps if its end date is on or afterstartDateand its start date is on or beforeendDate. Must be beforeendDate. DefaultNULL(no date filtering).- endDate
Date(1)orNULL. End of the study period. Required whenstartDateis provided and vice versa. DefaultNULL.- minOverlapDays
integer(1). Minimum overlap in days to consider an algorithm episode and a PET episode as the same pregnancy (default 1).- removeWithinSourceOverlaps
logical(1). IfTRUE, before matching the code removes overlapping episodes within PET and within the algorithm (greedy non-overlapping by start date per person), which can reduce many-to-many candidate pairs. DefaultFALSE.- minCellCount
integer(1). Minimum count threshold for suppression. Any record count or person count less thanminCellCountis replaced withNAin the exported summarised result. Default 5.- outputLogToConsole
logical(1). Whether to log to the console as well as tofile.path(exportFolder, "log.txt").
Value
Nothing. The summarised result is written to
file.path(exportFolder, "pet_comparison_summarised_result.csv").
Use omopgenerics::importSummarisedResult() to read it and
visOmopResults::visTable() to display it.