Skip to content

Feature/lago sensitivity - #94

Merged
correspondMerchant merged 2 commits into
mainfrom
feature/lago-sensitivity
Aug 21, 2026
Merged

Feature/lago sensitivity#94
correspondMerchant merged 2 commits into
mainfrom
feature/lago-sensitivity

Conversation

@correspondMerchant

Copy link
Copy Markdown
Owner

What this changes

Adds lago_sensitivity(), a robustness analysis for a LAGO recommendation, and
lets it be driven by a fitted result.

  • lago_sensitivity() re-runs lago_optimization() across a sweep of one input
    and reports how the recommended intervention, its cost, and the estimated
    outcome move — a stringency curve for the outcome goal, or a line for a uniform
    cost rescaling. parameter is a scalar numeric argument that affects the
    recommendation (e.g. "outcome_goal", "power_goal") or the special
    "cost_multiplier" (scales all costs); values is the sweep.
  • Fit-then-sweep flow: lago_optimization() now records its call arguments
    on the result (as a "lago_call_args" attribute, leaving the printed output
    and $ fields unchanged), so you can pass the fitted result and skip retyping:
    opt <- lago_optimization(...); lago_sensitivity(opt, parameter=..., values=...).
    ... overrides stored args; the direct-arguments form still works, identically.
  • Returns a tidy "lago_sensitivity" data frame (value, the recommended value
    of each component, rec_int_cost, est_outcome_goal, status) with print()
    and plot() methods. Each run forces include_confidence_set = FALSE for
    speed and is wrapped so a failing run is NA + a status note (one warning),
    not an aborted sweep. Confidence-set-only scalars like confidence_set_alpha
    are rejected.
  • Docs: roxygen + examples, a README "Sensitivity analysis" section, a vignette
    section, pkgdown reference entries; NEWS updated.

Related issue

Closes #

Checklist

  • Tests added or updated under tests/testthat/ (argmin-invariance, goal-cost monotonicity, graceful failure, validation, object-form
    equivalence + override + error paths)
  • devtools::document() run (new man/*.Rd, NAMESPACE export + S3methods)
  • devtools::check() passes locally (suite 1319 pass / 0 fail; vignette knits; pkgdown clean)
  • NEWS.md updated

Adds an exported lago_sensitivity() that re-runs lago_optimization() across a
sweep of one input and reports how the recommended intervention, its cost, and
the estimated outcome move, so a user can see how robust the recommendation is
to inputs they are unsure about.

Pass the same arguments as lago_optimization() plus `parameter` (what to vary)
and `values` (the sweep). `parameter` is either the name of a scalar numeric
argument that affects the recommendation (e.g. "outcome_goal", "power_goal") or
the special "cost_multiplier", which scales every cost coefficient by each value.
Each run forces include_confidence_set = FALSE for speed and is wrapped so a
failing run is recorded as NA with a status note rather than aborting the sweep;
one warning names any failed values. Returns a tidy "lago_sensitivity" data
frame (value, the recommended value of each component, rec_int_cost,
est_outcome_goal, status) with print() and plot() methods. Confidence-set-only
scalars such as confidence_set_alpha are rejected, since the confidence set is
not computed during a sweep and sweeping them would return identical rows.

Includes tests (cost_multiplier argmin-invariance, outcome_goal cost
monotonicity, graceful single-run failure, and validation), roxygen with a
runnable example, a README section, a vignette section, and pkgdown reference
entries.
lago_optimization() now records its evaluated call arguments on the result (as
a "lago_call_args" attribute, so the printed output and $-accessible fields are
unchanged), and lago_sensitivity() gains an optional first `object` argument.
Passing the fitted result reuses that call, so the whole optimization does not
have to be retyped: `opt <- lago_optimization(...)` then
`lago_sensitivity(opt, parameter = "outcome_goal", values = ...)`. Any arguments
in ... override the stored ones. Calling lago_sensitivity() without a result
(passing the arguments directly) still works exactly as before.

The two forms produce identical results. Adds object-form tests (equivalence to
the direct form, ... override, missing-attribute and non-lago errors), and
updates the roxygen, README, and vignette to lead with the fit-then-sweep flow.
@correspondMerchant
correspondMerchant merged commit 97f6d2b into main Aug 21, 2026
7 checks passed
@correspondMerchant
correspondMerchant deleted the feature/lago-sensitivity branch August 21, 2026 21:31
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.15447% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
R/lago_sensitivity.R 97.09% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant