Skip to contents

Computes, for each site and drug class (plus a pooled ALL row), the 2x2 agreement table of the two strategies, Cohen's kappa, raw concordance and prevalences, and flags data-quality anomalies. Sites with broken drug mappings stand out; nothing is hardcoded to particular sites. Mirror of omop_etl.medication_classes.audit_medication_strategies in Python.

Usage

audit_medication_strategies(
  flags,
  classes = NULL,
  site_col = "site",
  kappa_threshold = 0.6,
  concordance_threshold = 0.9,
  prevalence_gap_threshold = 0.1,
  peer_kappa_gap = 0.25,
  min_n = 10,
  min_prevalence = NULL,
  explain = FALSE,
  con = NULL,
  medication_specs = NULL,
  cohort_table = "cohort",
  vocab_schema = NULL,
  vocab_db = NULL,
  ...
)

Arguments

flags

Output of extract_medication_classes() with strategy = "both".

classes

Classes to audit (default: every class with both _source and _standard columns).

site_col

Site column in flags; if absent all rows are audited as one site, "all".

kappa_threshold

Flag Cohen's kappa below this.

concordance_threshold

Flag raw agreement below this.

prevalence_gap_threshold

Flag |prevalence_source - prevalence_standard| above this.

peer_kappa_gap

With at least 3 sites, flag a site whose kappa trails the median of the other sites by more than this.

min_n

Minimum cohort size to audit (default 10).

min_prevalence

Minimum expected prevalence threshold (default NULL).

explain

If TRUE, joins disagreement explanation (requires con and medication_specs).

con

Active DuckDB DBI connection (needed if explain = TRUE).

medication_specs

Medication class specifications (needed if explain = TRUE).

cohort_table

Cohort table name (default 'cohort').

vocab_schema

Optional schema containing vocabulary tables.

vocab_db

Optional attached database containing vocabulary tables.

...

Forwarded to explain_medication_disagreement() if explain = TRUE.

Value

A data frame with one row per (site, class): site, medication_class, n, both, source_only, standard_only, neither, source_prevalence, standard_prevalence, concordance, kappa, reason (both_blind, source_blind, standard_blind, below_min_prevalence, low_kappa, low_concordance, prevalence_gap, peer_outlier) and flagged. If explain = TRUE, returns a list list(audit =, explanation =).