Repository navigation
Feat/multi group compare - #33
Merged
Merged
Conversation
…n columns
Two pre-existing defects found while building multi-group comparison, both
reachable through the public API and neither covered by the existing tests.
`phv_chisq()`, `phv_fisher()` and `phv_bcpnn_mcmc()` built their result from a
list of per-row results and then named the columns unconditionally, so a
zero-length call aborted with `无法将 N 个名字赋值给一个包含 0 列的
data.table`. They now return their full schema with zero rows, which keeps the
result bindable with a populated one:
faers_phv_signal(faers_keep(obj, character()), .events = "pt",
.full = obj, .methods = "chisq")
The SQL builder in `db_counts_query()` qualified every event column with the
MedDRA hierarchy alias `m.`, but `pt`/`meddra_code`/`meddra_pt` live in `reac`
itself and are not columns of the hierarchy table, so on a duckdb-backed object
`.events = "pt"` failed with a binder error while the in-memory path worked.
Only the columns the join actually adds (`soc_name`, `pt_name`, ...) are now
qualified; a new `db_meddra_columns()` gives the callers that list.
…contrasts Adds one orchestrated entry point for comparing several drug exposure definitions in a single study scope, plus the report-set layer beneath it. `faers_group_ids()` (R/compare-groups.R) is the set layer: it validates the definitions, resolves each one through `faers_reports_with()` so the matching semantics (including "two patterns may be satisfied by the same drug row" for fixed-dose combinations, and report-level, role-agnostic `.exclude_drugs`) are inherited rather than reimplemented, reconciles overlaps with `.overlap` (`"keep"`/`"exclude"`/`"repartition"`/`"error"`), derives the mutually exclusive `A-only`/`B-only`/`A+B`/`Neither` groups for `.split = "joint"`, and returns the ids, a report x group membership matrix, a summary and every pairwise intersection with the strategy applied to it. `faers_compare()` (R/compare.R) is the orchestration layer and adds no statistics of its own: it builds the 2x2 tables, counts every event per group, hands each table to the same `phv_signal()` a single-group analysis uses, and returns seven components - `group_summary`, `event_profile`, `comparisons`, `signal_results`, `matrices`, `metadata` and `group_overlaps`. The two modes stay strictly separated and are stamped on every row: * `"background"` compares each group G with the rest of the shared scope U (`a + b + c + d == |U|`, one universe for every group), identical to `faers_phv_table(.object = G, .full = U)`. * `"pairwise"` compares two selected groups (`a + b + c + d == |G1| + |G2|`, a denominator that changes per pair) and never runs implicitly: every pair must be listed in `.comparisons`, because per-pair denominators invite uncorrected multiple comparisons. The background is `U` itself, so a study scope is narrowed first with `faers_restrict()` rather than by passing a second universe. `R/compare-db.R` provides the duckdb path: the group's ids are registered as a session TEMP table and counted with a single read-only JOIN. `faers_keep()` cannot be reused here - `faers_keep_db()` physically DELETEs rows from the connection every object shares, and the only safe alternative deep-copies the whole database once per group, which is not acceptable for a multi-quarter on-disk database. Numeric honesty is explicit: `.min_a` is 0 by default (no implicit threshold, unlike the 3 `faers_phv_scan()` applies) and the number of dropped rows is reported as an attribute; zero cells and NaNs are kept as-is rather than imputed; `.top_n` truncates only the display layer (event spectrum and matrices) while `signal_results` keeps every row, and the subset is flagged as `display_subset`; joint-group output is a descriptive comparison of co-reported drugs, NOT a formal interaction test, which `metadata$interaction_test` states. Verified end to end on the bundled 200-report sample: the four joint groups are mutually exclusive and sum to |U|, duplicated drug/event rows do not double-count, `a + b + c + d` is non-negative and conserved in every mode, batch results are `identical()` to the equivalent standalone calls, and the memory and duckdb backends agree component by component while the source database is left untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
faers_group_ids()to build report groups from drug exposure definitions, with optional drug role filters and exclusions. For example, split a set of FAERS reports into warfarin only, aspirin only, both drugs, and neither drug, then inspect the report IDs and counts for each group.Add
faers_compare()to compare adverse event reporting across drug groups. For example, for gastrointestinal bleeding, compare each drug group with the rest of the study scope, or directly compare reports listing both drugs with reports listing warfarin only. The results include event counts and proportions, 2×2 tables, and signal metrics such as ROR and PRR.