Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

variation = TRUE inflates the mean intervention delta

Chiusa
#154 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
r
Ambito
data

Direzione di ricerca

Start at calculate_efficacy_from_ach() in R/interventions.R, then reproduce the bias from section 5 of inst/ach_pipeline_walkthrough.R. Review the floor-related test in tests/testthat/test-ach-interventions.R and extend it to verify that the intervention delta remains mean-preserving while staying nonnegative. Document the chosen variation convention in variation_params.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Found while running through the ACH pipeline added in #142.

calculate_efficacy_from_ach() floors the per-location delta at zero after adding noise (R/interventions.R:475):

delta_i <- pmax(0, delta_i + noise)

That's a floor, not a redistribution. Mass that should fall below zero piles up at zero with nothing compensating above it, so the mean moves up. For noise e ~ N(0, sigma):

E[max(0, delta + e)] = delta * Phi(delta/sigma) + sigma * phi(delta/sigma)   >   delta   for all sigma > 0

Measured with delta_function = function() 3 and variation_params = list(mean = 0, sd = 4) over 2000 locations: realised mean delta 3.51 (+17%), with 22% of covered locations getting exactly zero delta. So "add mean-zero unit-to-unit variation" in practice means "add ~17% more ventilation on average, and switch the device off in a fifth of the buildings".

The bias scales with sigma/delta, so it is worst exactly where variation is most wanted — representing heterogeneous real-world installations. At small sigma relative to delta it is negligible (at sd = 1 the realised mean is 2.99).

Reproducible from section 5 of inst/ach_pipeline_walkthrough.R (on branch claude/epidemic-model-pr-review-f9o3k4).

The existing test at tests/testthat/test-ach-interventions.R:395 ("never produces a negative delta even with downward variation noise") checks that the floor works, which it does — it does not check that the mean survives.

Suggested fix

Use a variation distribution that is positive by construction and mean-preserving, rather than clipping a symmetric one. Multiplicative lognormal with mean 1 is the natural choice:

delta_i <- delta_i * rlnorm(n, meanlog = -sdlog^2 / 2, sdlog = sdlog)

Alternatively keep the additive form but draw from a truncated normal on [0, Inf) re-centred so E[delta] is preserved (truncnorm is already a dependency).

Either way variation_params should document which convention it follows — list(mean = 0, sd = 4) currently reads as mean-preserving and is not.

Lingua principale
R
Stelle
8
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di petal-code/helios

Tutte le issue di petal-code/helios

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.