Skip to content

feat: simulate_chain_stats() returns both size and length statistics#341

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/simulate-chain-stats-limit
Draft

feat: simulate_chain_stats() returns both size and length statistics#341
Copilot wants to merge 3 commits into
mainfrom
copilot/simulate-chain-stats-limit

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown

simulate_chain_stats() only returned the statistic used as the stopping criterion, making it impossible to limit by one stat (e.g., generation length) while observing the other (e.g., outbreak size).

Changes

Core API change: <epichains_summary> is now a data frame

  • <epichains_summary> changes from a single-column numeric vector to a data.frame with size and length columns
  • statistic remains the stopping criterion; only that stat is censored at stat_threshold (the complementary stat reflects its actual value when the chain stopped)
# Limit by generation length, observe outbreak sizes
simulate_chain_stats(
  n_chains = 10, offspring_dist = rpois,
  statistic = "length", stat_threshold = 5, lambda = 1.5
)
#> `epichains_summary` object
#>
#>    size length
#> 1    14      8   # length hit threshold → Inf; size is actual count
#> 2     2      2
#> 3    44    Inf   # censored at threshold
#> ...
#>  Stopping criterion: length (threshold: 5)

Updated consumers

  • format.epichains_summary() — displays both stats with stopping criterion and threshold
  • summary.epichains_summary() — returns max_size/min_size/max_length/min_length (replaces max_stat/min_stat)
  • summary.epichains() — computes and returns both stats
  • likelihood() — extracts the relevant column from the data frame; uses stat_threshold only when the requested statistic matches the stopping criterion (otherwise Inf, since the non-stopping stat is never censored)
  • .offspring_ll() (stat_likelihoods.R) — extracts statistic column before passing to ecdf()
  • rborel() (borel.R) — extracts size column from the new data frame

Tests & snapshots

  • Tests updated throughout to use $size/$length, nrow(), and the renamed summary fields
  • Snapshots regenerated to reflect the new data frame print format

Copilot AI added 2 commits June 8, 2026 23:27
- simulate_chain_stats() now tracks both chain size and chain length
  simultaneously; `statistic` is only the stopping criterion
- <epichains_summary> changed from a numeric vector to a data.frame
  with `size` and `length` columns
- format/summary methods updated to display both stats
- summary.epichains() also computes and returns both stats
- likelihood() updated to extract the relevant column from the data.frame
- .offspring_ll() updated to extract statistic column before ecdf()
- rborel() updated to extract `size` column from new data.frame
- Tests and snapshots updated to match new data.frame API
Copilot AI changed the title [WIP] Add simulate_chain_stats with limit on one stat reporting both stats feat: simulate_chain_stats() returns both size and length statistics Jun 8, 2026
Copilot AI requested a review from jamesmbaazam June 8, 2026 23:28
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.

Feature Request: simulate_chain_stats with limit on one stat, but reporting both stats out

2 participants