Skip to content

feat: add stratified whole-database signal scanning - #30

Merged
MadDERt merged 1 commit into
WangLabCSU:develfrom
MadDERt:feat/phv-strata
Sep 29, 2026
Merged

MadDERt merged 1 commit into
WangLabCSU:develfrom
MadDERt:feat/phv-strata

Conversation

@MadDERt

@MadDERt MadDERt commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add faers_phv_scan_stratified(), a stratified variant of the whole-database
    scanner: it splits the database into strata defined by categorical demo
    columns (sex, age_grp, occp_cod, ...) and builds one 2x2 contingency
    table per stratum x drug x event combination against the stratum-internal
    background (n_stratum).

Details

  • Missing strata values are grouped into an explicit "Missing" stratum by
    default (.na_stratum = "keep"), or excluded with "drop"; a warning is
    issued when a stratification column is missing for >30% of reports.
  • .min_a applies per stratum; strata columns must be categorical
    (character/VARCHAR) demo columns so both backends produce identical output.
  • Memory backend: stratum key carried through the integer-coded, chunked join
    (reports are atomic per stratum, so chunk counts stay exact).
  • duckdb backend: the whole stratified aggregation is pushed into a single SQL
    query with a strata CTE (CASE ... 'Missing' coalescing / WHERE for
    drop mode).
  • No changes to existing scan.R / scan-db.R code paths.

Tests

  • New tests/testthat/test_scan-strata.R: 94 assertions covering per-stratum
    2x2 correctness vs direct computation, keep/drop semantics, cross-strata,
    per-stratum .min_a, chunked vs unchunked identity, and memory-vs-duckdb
    identical() parity (pt / soc_name / hlgt_name).
  • Full suite: 455 passed, no regressions. R CMD check shows no new issues
    (env-only items unchanged).

@MadDERt
MadDERt merged commit 17fba8b into WangLabCSU:devel Sep 29, 2026
11 checks passed
@MadDERt
MadDERt deleted the feat/phv-strata branch September 29, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant