Skip to content

Support for multiarm ancova, Draft v2 - #590

Open
luwidmer wants to merge 36 commits into
145-multi-ancovafrom
145-multi-ancova-v2
Open

Support for multiarm ancova, Draft v2#590
luwidmer wants to merge 36 commits into
145-multi-ancovafrom
145-multi-ancova-v2

Conversation

@luwidmer

Copy link
Copy Markdown
Collaborator

First draft to further iterate onaccording to to the discussion in #520 so far @gowerc @tobiasmuetze @bailliem @wwojciech @danielinteractive: this branch builds on the original multi-arm ANCOVA prototype (#520 ) with a more flexible contrast API.

Let me know what you think, this definitely will need further review and iteration.

Flexible custom contrasts

  • group_contrasts now accepts, in addition to pairwise c(minuend, subtrahend) character vectors, general linear contrasts as named numeric weight vectors over the group levels (e.g. c(Placebo = -1, A = 0.5, B = 0.5) for pooled active-vs-control, or dose-response trends). Weights must sum to zero; evaluation is coding-agnostic and preserves the trt estimand (evaluated at the covariate reference).
  • Default two-arm and multi-arm output is unchanged (trt, lsm_ref, lsm_alt, trt_alt2, ...).

Correctness & robustness

  • Contrast coding-agnostic evaluation: ancova_linear_contrast() now maps group-level weights onto the model coefficients via the factor's own contrast matrix instead of parsing rbmiGroupL* coefficient names. Results are correct under any options("contrasts") (e.g. contr.sum), not just contr.treatment, and reduce exactly to the previous coefficient contrast for the pairwise/default case. Rank-deficient designs (missing/aliased/NA group coefficients) now error instead of silently dropping a term.
  • as_data_frame_internal() errors if pooled parameters have no matching metadata rather than emitting silent NA columns.

Named contrasts & output metadata

  • Explicit contrasts must be named: the list name becomes the output parameter and a new contrast_label metadata column (surfaced by pool() / as.data.frame()). The auto-derived trt_alt2_alt-style names are used only for the default (group_contrasts = NULL) set, preserving backward compatibility. Naming a contrast trt reproduces the classic name.
  • Names starting with lsm_ are rejected (reserved for least-squares means) to prevent output collisions.
  • pool() / as.data.frame() output gains contrast_label alongside the existing estimate_type, group, group_level_1, group_level_2, visit columns; the legacy parameter column is retained.

Documentation

  • Fixed stale ancova() @return (now documents the extended default scheme and named custom contrasts); added an @details note clarifying that trt is the model-coefficient contrast and differs from lsm_alt − lsm_ref under group×covariate interactions.
  • Added runnable multi-arm/custom-contrast examples to ancova() and worked pairwise + weight-vector blocks to the FAQ and quickstart vignettes.
  • NEWS updated.

Tests

  • Coefficient-contrast reproduction, pooled/weight-vector correctness, contr.sum invariance, named-label propagation through pool(), reserved-name and validation errors, an end-to-end ancova()pool()as.data.frame() metadata integration test.

Housekeeping

  • Project formatted with air.

Compatibility

  • Two-arm and default multi-arm results and names are unchanged. group_contrasts and the metadata columns are new (unreleased), so tightening explicit contrasts to require names introduces no break for released behaviour.
  • The covariate reference point for trt is fixed at 0 to preserve the historic estimand (documented in @details).

gravesti and others added 30 commits September 22, 2025 15:35
- use correct cluster in test
- make sure no left over .stan files after tests
- import stats::plogis
This adds spell-check and fixes a bunch of spelling mistakes (see #544).
In addition, NMAR and MNAR are consistently called MNAR.

However, one of the exported arguments is also `nmar.rm`, which I
renamed to `mnar.rm` here - this will need an additional pull request
adding the lifecycle package (#188) and deprecating the old argument

---------

Signed-off-by: Lukas Widmer <l.widmer@gmail.com>
Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Signed-off-by: Lukas Widmer <l.widmer@gmail.com>
Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Co-authored-by: Isaac Gravestock <83659704+gravesti@users.noreply.github.com>
Fixes #557

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #550

---------

Signed-off-by: Lukas Widmer <l.widmer@gmail.com>
Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Merge remote-tracking branch 'origin/main' into 145-multi-ancova

# Conflicts:
#	vignettes/FAQ.html
#	vignettes/quickstart.html
#582)

Fixes #581

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #567

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Addsmissing example code for exported functions, where possible this is based on the existing code from the quick start and advanced vignettes.
Fixes #570

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #572

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #583

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #578

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #574

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Fixes #576

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
rbmi release 1.6.1 (#584).
Also fixes #548.

---------

Co-authored-by: Lukas Widmer <lukas_andreas.widmer@novartis.com>
Merge branch 'main' into 145-multi-ancova-v2

# Conflicts:
#	DESCRIPTION
#	NEWS.md
#	man/control.Rd
#	vignettes/advanced.html
#	vignettes/quickstart.html
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.

3 participants