savi2x2TestStat: Safe Anytime-Valid Test of Two Proportions

View source: R/newsafe2x2Test.R

savi2x2TestStatR Documentation

Safe Anytime-Valid Test of Two Proportions

Description

Tests thetaA = thetaB on a stream of 2x2 tables, one per block, with the e-process chosen by designObj[["eType"]]. Both effects are A minus B, propDiff = thetaA - thetaB and logOdds = logit(thetaA) - logit(thetaB), so "greater" means group A has the larger proportion, as in stats::t.test(). Block 1 of every e-process is replaced by the UMP conditional e-value of savi2x2TestStatUmp() when one exists at level alpha; otherwise it keeps its plain factor, with a warning.

Usage

savi2x2TestStat(
  ya,
  yb,
  designObj = NULL,
  wantCi = FALSE,
  wantConfidenceSequence = FALSE,
  ciValue = NULL
)

Arguments

ya

positive observations/ events per data block in group A: a numeric with integer values between (and including) 0 and na, the number of observations in group A per block.

yb

positive observations/ events per data block in group B: a numeric with integer values between (and including) 0 and nb, the number of observations in group B per block.

designObj

an object obtained from designSavi2x2(), which also supplies na and nb.

wantCi

default FALSE, compute a confidence interval.

wantConfidenceSequence

logical that can be set to true when the user wants a savi confidence sequence to be estimated, one row per block; takes precedence over wantCi.

ciValue

numeric representing the confidence level. Default ciValue=NULL yields ciValue = 1 - alpha

Details

  • "eBeta" (propDiff): independent Beta posterior means of thetaA and thetaB from the previous blocks, against the pooled null mean.

  • "grow" (propDiff or logOdds, whichever minimal effect the design holds): the alternative restricted to the signed minimal effect; "twoSided" averages the cumulative e-processes of both signs.

  • "eGauss" (logOdds): the conditional likelihood of Fisher's noncentral hypergeometric distribution mixed under the design's Normal prior on a logOdds grid, against the hypergeometric null. The mixture may include the current block because it conditions on the block's total.

Only "eBeta" and "eGauss" give a confidence interval or sequence, each on its own effect.

Value

Returns an object of class 'saviTest'. An object of class 'saviTest' is a list containing at least the following components:

n

The realised sample size(s): c(na = sum(na), nb = sum(nb), nBlocks = length(ya)).

eValue

the e-value of the savi test on all blocks; reject when it is at least 1 / alpha.

eValueVec

the realised e-values after each block, element i on blocks ⁠1..i⁠.

n1Vec

the block index, used for plotting.

estimate

the estimated proportions c(thetaA, thetaB), pooled over all blocks.

confSeq

a savi confidence interval for the design's effect at level ciValue on all blocks; NA when the set is empty, NULL for "grow" or when no interval was requested.

confSeqMatrix

with wantConfidenceSequence, the savi confidence sequence as an ⁠nBlocks x 2⁠ matrix, row i the interval on blocks ⁠1..i⁠; confSeq is its last row. With runningIntersection the rows are nested and stay NA after the first empty row.

ciValue

the confidence level used.

betaParameter

for "eBeta" only, list(betaA1, betaA2, betaB1, betaB2), the Beta prior updated with all blocks.

alternative

any of "twoSided", "greater", "less" copied from the design.

h0

the null value copied from the design.

dataName

a character string giving the name(s) of the data.

designObj

an object of class "saviDesign" described in designSavi2x2().

call

the expression with which this function is called.

References

Grünwald, P. D., de Heide, R., & Koolen, W. (2024). Safe testing. Journal of the Royal Statistical Society. Series B (Methodological), 86(5), 1091-1128. (With discussions), https://doi.org/10.1093/jrsssb/qkae011.

Turner, R., Ly, A., & Grünwald, P. D. (2024). Generic e-variables for exact sequential k-sample tests that allow for optional stopping. Journal of Statistical Planning and inference 230, 106116, https://doi.org/10.1016/j.jspi.2023.106116.

Turner, R., & Grünwald, P. D. (2024). Exact anytime-valid confidence intervals for contingency tables and beyond. Statistics and Probability letters, 198, 109835, https://doi.org/10.1016/j.spl.2023.109835.

Examples

designObj <- designSavi2x2(na = 10, nb = 10, eType = "eBeta")
ya <- c(8, 7, 9, 6)
yb <- c(4, 5, 3, 5)
savi2x2TestStat(ya, yb, designObj = designObj)

safestats documentation built on Oct. 5, 2026, 9:07 a.m.