Introduction to SPRT package"

Overview

The Sequential Probability Ratio Test (SPRT), proposed by Abraham Wald (1945), is a method of hypothesis testing that evaluates data sequentially rather than fixing the sample size in advance.
It is widely used in quality control, clinical trials, and agricultural research where early stopping can save both time and resources.


Theoretical Background

We test simple hypotheses:

[ H_0: \theta = \theta_0 \quad \text{vs.} \quad H_1: \theta = \theta_1 ]

After (n) observations ((X_1, X_2, \ldots, X_n)), the likelihood ratio is:

[ \Lambda_n = \prod_{i=1}^n \frac{f(X_i; \theta_1)}{f(X_i; \theta_0)} ]

or equivalently,

[ \log \Lambda_n = \sum_{i=1}^n \log \left( \frac{f(X_i; \theta_1)}{f(X_i; \theta_0)} \right). ]


Derivation of Decision Boundaries

To control Type I error ((\alpha)) and Type II error ((\beta)), Wald proposed comparing the likelihood ratio (\Lambda_n) with two thresholds.

where

[ A = \frac{1-\beta}{\alpha}, \qquad B = \frac{\beta}{1-\alpha}. ]

Why these thresholds?

  1. Type I error control: Probability of wrongly rejecting (H_0) should not exceed (\alpha).
    This sets the upper boundary (A).

  2. Type II error control: Probability of wrongly rejecting (H_1) should not exceed (\beta).
    This sets the lower boundary (B).

Thus, the SPRT is designed so that:

[ P(\text{Reject } H_0 | H_0 \text{ true}) \leq \alpha, \qquad P(\text{Reject } H_1 | H_1 \text{ true}) \leq \beta. ]

This guarantees the desired error rates in the sequential framework.


Example 1: Binomial Data

Suppose we want to test whether the probability of success is (p_0 = 0.1) vs (p_1 = 0.3).

```r library(SPRT)

Simulated binary outcomes (1 = success, 0 = failure)

x <- c(0,0,1,0,1,1,1,0,0,1,0,0)

Run SPRT

res <- sprt(x, alpha = 0.05, beta = 0.1, p0 = 0.1, p1 = 0.3)

Print results

res

Plot sequential test path

sprt_plot(res)

Observations from a Normal distribution

x1 <- c(52, 55, 58, 63, 66, 70, 74)

result1 <- sprt( x1, alpha = 0.05, beta = 0.1, p0 = 50, p1 = 65, dist = "normal", sigma = 10 )

result1 sprt_plot(result1)

Yields from a fertilizer trial (kg/plot)

yield <- c(47, 50, 52, 49, 58, 61, 63, 54, 57)

fert_test <- sprt( yield, alpha = 0.05, beta = 0.1, p0 = 45, p1 = 55, dist = "normal", sigma = 8 )

fert_test sprt_plot(fert_test)



Try the SPRT package in your browser

Any scripts or data that you put into this service are public.

SPRT documentation built on Sept. 15, 2025, 9:08 a.m.