Changelog
Source:NEWS.md
ri2 0.5.0
CRAN release: 2026-07-29
- Fixed wrong null distributions when the assignment variable appears in more than one term of the formula, such as
Y ~ Z * X. Only the assignment columns of the design matrix were updated for each permutation, so interaction columns kept their observed values and the design matrix disagreed with itself about what the assignment was. The resulting null distribution was too narrow and p-values were anti-conservative. Such formulas now rebuild the design matrix from the permuted assignment; the single-term case keeps the faster column-patching path. - Added a
potential_outcomesargument toconduct_ri()(#19). Naming one column ofdataper treatment condition states the sharp hypothesis as a full schedule of potential outcomes, which allows hypothesized effects that vary across units;sharp_hypothesiscan only express a constant shift per arm. Build the columns however you like, holding each unit’s observed outcome fixed for the condition it was assigned to. Supplied columns are checked against the observed outcomes, which catches columns given in the wrong order and schedules that do not preserve what was observed. - Supplying a non-zero
sharp_hypothesistoconduct_ri()alongsidetest_functionwithout also namingoutcomeis now an error.outcomedefaults toNULL, in which case the switching equation never ran and the hypothesis was silently ignored. -
conduct_ri()now errors when the assignment variable does not appear in the formula, or in either model of a nested-model comparison. Only the assignment column is permuted, so columns derived from it are never recomputed; previously such a call ran and returned a degenerate null distribution with a p-value of 1 regardless of the data. - Supplying
sampling_weightsalongsidetest_functionis now an error rather than being silently ignored. ri2 cannot weight an arbitrary scalar statistic, so weighting belongs inside the test function; the error message says how. - Vignette gains a “Factorial designs” section (#27) showing that a factorial is a multi-arm trial over its cells, and how to test any factorial estimand by deriving the factors inside a
test_function. - Fixed multi-arm trial bug (#33): arms 2+ now each get a fresh conditional permutation matrix instead of reusing the first arm’s matrix, giving correct p-values for all arms.
- Fixed silent outcome transformation dropping (#20):
log(Y) ~ Zand other formula transformations now apply correctly viamodel.frame(). - Fixed S3 class name conflict with
bit::ri(#28): class is now"ri2". - Fixed histogram bar stacking (#6): use
fillaesthetic instead ofalphainplot.ri2(). - Fixed
plot()failing to draw any bars when the number of simulations is not a multiple of 20 (#32, thanks @mreece13): the bin count is now floored to a whole number, asgeom_histogram()requires. -
plot()no longer over-bins multi-arm results. The bin count came from the total number of simulated estimates, but the plot facets by term, so a four-arm trial drew three times as many bins per panel as a two-arm trial over the same number of simulations per panel. Bins are now chosen per panel. - Replaced floating-point rounding hack with tolerance-based comparison in
summary.ri2()andplot.ri2(). - Implemented
sampling_weightsargument (#16): pass a column name containing sampling weights; multiplied with the auto-computed IPW weights when both are present. - Removed
IPW_weightsargument: pre-specified IPW weights are incoherent for RI because weights must vary with each permuted assignment. IPW is always computed from the declaration viaobtain_condition_probabilities(). - Implemented clustered standard errors for
studentize = TRUE: add aclustersargument; CR2 SEs are used automatically when clusters are supplied. - Added
ri_ci()for randomization inference confidence intervals by test inversion (#31). - Added explicit NA checks with informative messages (#2).
- Moved
randomizrandestimatrfromDependstoImports. To keeplibrary(ri2)self-sufficient,declare_ra(),conduct_ra(), the*_ra()assignment functions, and theobtain_*()helpers are now re-exported from ri2, so existing scripts that relied onrandomizrbeing attached continue to work.
ri2 0.4.1
CRAN release: 2025-10-14
- Minor patch release fixing package documentation and link anchors.