Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c6380fd
Fix likelihood correctness: rounding, zero-values, mean/SD moments
cm401 Aug 1, 2026
3642588
Fix likelihood correctness: rounding, zero-values, mean/SD moments
cm401 Aug 1, 2026
4a538db
Add detect_resolution
cm401 Aug 1, 2026
327c607
Improved stan model, so we can have 0 rather than 0.1 to be consisten…
cm401 Aug 1, 2026
ead8803
Extend rounding treatment to dc_log_lik Cases 2/3, fix Case 1's kerne…
cm401 Aug 1, 2026
1ccda0f
add documentation
cm401 Aug 1, 2026
76f1675
Add family-gated per-study dispersion hierarchy and computational-eff…
cm401 Aug 3, 2026
987cb62
Add utility functions for adaptive quadrature panel count
cm401 Aug 3, 2026
ab008ef
allow for shared phi models
cm401 Aug 3, 2026
46e7701
Add functions to check datasets + heuristics
cm401 Aug 4, 2026
a60e080
Fix to ensure that background jobs run properly and don't leave any z…
cm401 Aug 4, 2026
0bd4e73
update documentation
cm401 Aug 4, 2026
256757e
update test for code change
cm401 Aug 4, 2026
2841406
update documentation
cm401 Aug 4, 2026
2992083
update DESCRIPTION
cm401 Aug 4, 2026
2aac7be
update NAMESPACE
cm401 Aug 4, 2026
a4daab8
update global variables
cm401 Aug 4, 2026
bccd413
update comment
cm401 Aug 4, 2026
c94e8d7
update documentation
cm401 Aug 4, 2026
d3fbad2
update documentation
cm401 Aug 4, 2026
e57551a
bug fix (found by copilot code review!)
cm401 Aug 4, 2026
0a924a4
Bug fix (thanks copilot)
cm401 Aug 4, 2026
b8c9fef
add gamma_shared_phi_reliable
cm401 Aug 6, 2026
f7f1b0b
add gamma_shared_phi_reliable
cm401 Aug 6, 2026
51795e3
add smooth log-barrier
cm401 Aug 6, 2026
b40ba3b
time limit on pre-inference checks
cm401 Aug 6, 2026
049e6bb
add documentation
cm401 Aug 6, 2026
00b63c4
fix test
cm401 Aug 6, 2026
a3d2176
fix to plots of fits
cm401 Aug 7, 2026
1179a4c
improvements on how we kill processes
cm401 Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ URL: https://cm401.github.io/ddsynth, https://github.com/cm401/ddsynth
BugReports: https://github.com/cm401/ddsynth/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
BSL,
bridgesampling,
Expand Down Expand Up @@ -44,3 +43,4 @@ Suggests:
tidyverse
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(bsl_make_trace_df)
export(bsl_run_diagnostics)
export(bsl_summarise_posteriors)
export(bsl_to_mcmc_list_multi)
export(burr_phid_reliable)
export(check_coverage)
export(compile_stan_model)
export(compute_iqd)
Expand All @@ -31,10 +32,16 @@ export(create_pred_q95_coverage_plot)
export(create_results_summary)
export(create_scenario)
export(create_wis_plot)
export(detect_resolution)
export(extract_dataset_summary)
export(extract_posterior_draws)
export(extract_quantiles)
export(filter_datasets)
export(fit_corpus_parallel)
export(fit_model)
export(fit_with_escalation)
export(gamma_phi_extreme_safe)
export(gamma_shared_phi_reliable)
export(gamma_type2_reliable)
export(generate_cdf_plot_simulation_study_input)
export(generate_data_table)
Expand All @@ -45,12 +52,14 @@ export(generate_scenario_library)
export(generate_simulation_table1)
export(generate_simulation_table2)
export(make_stan_init_fn)
export(merge_parallel_fit_results)
export(plot_main_figure)
export(plot_main_figure_split)
export(plot_simulation_study_figure)
export(plot_simulation_study_figure2)
export(plot_simulation_study_sens_figure)
export(plot_simulation_study_si_figure)
export(plot_temporal_trend)
export(pre_inference_checks)
export(prepare_stan_data_from_datasets)
export(run_simulation_study_generalized)
Expand Down
106 changes: 52 additions & 54 deletions R/ddsynth_datasets.R

Large diffs are not rendered by default.

40 changes: 37 additions & 3 deletions R/ploting_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1210,17 +1210,51 @@ compute_pathogen_model_bayes_factors <- function(all_results, analysis = "filter
dist_results <- all_results[[pathogen]][[analysis]]
if (is.null(dist_results)) next

# Only fits usable at all: not NULL/skipped-sentinel, has a fit and the
# dataset list used to build it (needed below to identify which
# observations are common across families).
usable <- Filter(function(nm) {
r <- dist_results[[nm]]
!is.null(r) && !isTRUE(r$skipped) && !is.null(r$fit) && !is.null(r$datasets)
}, names(dist_results))
if (length(usable) == 0L) next

# Since "filtered" is now family-specific (see POINT4_LIKELIHOOD_MATHS.md
# Part E.10), each family may have excluded a different subset of
# datasets. elpd_loo is a SUM over observations, so comparing it across
# families with different observation counts/membership would bias
# weights toward whichever family happened to filter out more data,
# regardless of genuine relative fit quality. Restricting every family's
# LOO computation to the datasets common to all of them makes the
# comparison apples-to-apples; each family's own final reported fit
# (e.g. in Table 1) is unaffected - only this cross-family weighting
# step is restricted.
common_datasets <- Reduce(intersect, lapply(usable, function(nm) names(dist_results[[nm]]$datasets)))
if (length(common_datasets) == 0L) {
message(" [WARN] ", pathogen, ": no datasets common to every family's '",
analysis, "' fit - skipping model comparison.")
next
}

elpds <- c()

for (dist_name in names(dist_results)) {
for (dist_name in usable) {
r <- dist_results[[dist_name]]
# Skip: NULL slot, skipped-GG sentinel, or failed fit
if (is.null(r) || isTRUE(r$skipped) || is.null(r$fit)) next

elpd <- tryCatch({
# Extract log_lik matrix (draws × log_lik slots)
ll_mat <- rstan::extract(r$fit, "log_lik")$log_lik

# log_lik has 3 columns per dataset (vector[n_datasets*3] in Stan,
# filled dataset-by-dataset with idx += 3 each time), in the same
# order as r$datasets. Map the common dataset names to THIS fit's
# own column indices - a given dataset can sit at a different index
# in different families' filtered lists.
own_idx <- match(common_datasets, names(r$datasets))
if (anyNA(own_idx)) stop("a common dataset is missing from this fit's own datasets")
keep_cols <- as.vector(vapply(own_idx, function(d) (3L * (d - 1L)) + 1:3, integer(3)))
ll_mat <- ll_mat[, keep_cols, drop = FALSE]

# The Stan model stores zero-filled placeholder columns for unused
# summary-statistic slots (e.g. slot 3 for mean+SD datasets, slots
# 2 and 3 for frequency-table datasets). Remove them before LOO so
Expand Down
Loading
Loading