Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

variation = TRUE inflates the mean intervention delta

Cerrado
#154 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
r
Área
data

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
R
Estrellas
8
Forks
4
Merge medio
3 d 18 h
PR fusionados (30 d)
3

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de petal-code/helios

Todos los issues de petal-code/helios

Issues similares

Más issues de R

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.