Sequential Probabiltiy Ratio Test

Definition

Consider how a bank monitor credit card transaction in real time:

\[ H_0: \text{The transactions are consistent with the customer’s usual behavior.} \]

\[ H_1: \text{The transactions are fraudulent.} \]

Each new transaction provides a piece of evidence. If it aligns with the customer’s typical spending pattern, the evidence shifts toward \(H_0\). If it looks suspicious—such as unusual overseas charges or abnormally large purchases—the evidence shifts toward \(H_1\).

Let’s translate this scenario into technical formulas.

We want to test whether a sequence of transactions belongs to a normal customer or a fraudulent account.

\[ H_0: \text{legitimate: Transaction features follow distribution } f_0(x) \]

\[ H_1: \text{fraudulent: Transaction features follow distribution } f_1(x) \]

Here, \(x\) represents a transaction feature vector (e.g., amount, location, time, merchant type).

In hypothesis test, we define the Type I error as rejecting the null hypothesis \(H_0\) when it is actually true. We define the Type II error as failing to reject the null hypothesis \(H_0\) when the alternative \(H_1\) is true. Because the alternative hypothesis is typically treated as the “positive” case and the null hypothesis as the “negative” case, a Type I error is also called a false positive, while a Type II error is called a false negative. The probabilities of making Type I and Type II Error are \(\alpha\) and \(\beta\), respectively.

The power of a test is \(1-\beta\), i.e., the probability of correctly detecting a real effect.

Hypothesis Test

For a traditional hypothesis test, we first calculate a test statistic (such as Z, t, chi-square, or F). From this, we obtain a p-value, which represents the probability of observing data at least as extreme as the current dataset, assuming the null hypothesis is true. We then compare the p-value with a pre-defined significance level \(\alpha\). If the p-value is less than \(\alpha\), we reject the null hypothesis, ensuring that the probability of a Type I error does not exceed \(\alpha\).

Likelihood Ratio Test

The likelihood ratio test is a specific kind of hypothesis test based on likelihood functions:

After observing \(n\) transactions \(X_1, X_2, ..., X_n\), the likelihood under \(H_0\) is

\[ L_0(X_1,X_2,...,X_n)=\Pi_{i=1}^n f_0(x_i) \]

The likelihood under \(H_1\) is

\[ L_1(X_1,X_2,...,X_n)=\Pi_{i=1}^n f_1(x_i) \]

Intuitively, if \(L_0<L_1\) , or equivalently, \(\Lambda=\frac{L_0}{L_1}<1\) the data in favor of the alternative hypothesis. The key question is: how small must the \(\Lambda\) be in order to reject the null hypothesis \(H_0\) at the significance level \(\alpha\) ?

Mathematically, the likelihood ratio can be transfer to a Chi Squared distribution where the degree of freedom is the difference between the free parameters in full model and the null model.

Likelihood Ratio Test Example

Suppose we fit a regression model for \(Y\), indicating whether a transaction is fraudulent. In the full model, both transaction time and amount are used as predictors, while in the reduced model only transaction amount is included. Thus:

\[ H_0:logit(P(Y=1))=\beta_0 + \beta_1 X_1 \]

$$

$$

\[ H_1: logit(P(Y=1)) = \beta_0 + \beta_1 X_1 + \beta_2 X_2 \]

Here we are testing whether \(\beta_2=0\).

First, we fit both models and compute their maximum log-likelihood \(l_0=logL(\hat{\beta}_0, \hat{\beta}_1)\) , \(l_1=logL(\hat{\beta}_0,\hat{\beta}_1,\hat{\beta}_2)\) . Then calculate the likelihood ratio statistic:

\[ -2log\Lambda = -2(l_0-l_1) \]

Under \(H_0\) , \(-2log\Lambda\sim \chi^2_1\) because the full model has 1 extra parameter compared to the reduced model. At \(\alpha=0.05\), the critical value in \(\chi^2_1\) is 3.84. Thus if the observed likelihood ratio statistic exceeds 3.84, reject \(H_0\).

Conclusion: there is significant evidence that \(\beta_2\neq0\) , transaction time is significant. This is exactly how the likelihood ratio tests are used in **linear regression, generalized linear regression, and survival analysis**.

Sequential Probability Ratio Test (SPRT)

In a traditional test and the likelihood ratio test, the sample size is fixed in advance, and a decision is made only once after all data are collected. But in many real-world settings — like fraud detection, industrial quality control, or clinical trials — it’s costly or risky to wait for a full dataset before making a decision.

The SPRT is the sequential version of the likelihood ratio test. Instead of committing to a fixed \(n\) , the SPRT evaluates the likelihood ratio as data arrive sequentially:

\[ \Lambda_n = \frac{L_1(\text{data up to }n|H_1)}{L_0(\text{data up to }n|H_0)} \]

The decision-making process now differs from that of a fixed-sample likelihood ratio test. Instead of one critical value, we compare \(\Lambda_n\) to two thresholds:

\[ \text{If } \Lambda_n >A \Rightarrow \text{accept } H_1 \]

\[ \text{If } \Lambda_n <B \Rightarrow \text{accept } H_0 \]

\[ \text{Otherwise, continue sampling} \]

where

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

Wald proved that the SPRT minimizes the expected sample size among all tests with the same error rates. This means it often reaches a conclusion much faster than fixed-sample tests.

SPRT Example

Suppose we are collecting a group of normal distribution data, and test for

\[ H_0: \mu = 0 \text{ vs. } H_1: \mu = 1 \]

Assuming that the population variance \(\sigma=1\).

After taking \(n\) observations, the likelihood under \(H_0\) and \(H_1\) are

\[ L_{0,n} =\prod_{i=1}^n \left( \frac{1}{\sqrt{2\pi}} e^{-\frac{x_i^2}{2}}\right )=\left(\frac{1}{\sqrt{2\pi}}\right)^n e^{-\frac{\sum_{i=1}^nx_i^2}{2}} \]

\[ L_{1,n} =\prod_{i=1}^n \left( \frac{1}{\sqrt{2\pi}} e^{-\frac{(x_i-1)^2}{2}}\right )=\left(\frac{1}{\sqrt{2\pi}}\right)^n e^{-\frac{\sum_{i=1}^n (x_i-1)^2}{2}} \]

So the likelihood ratio is

\[ \Lambda_n=\frac{L_{1,n}}{L_{0,n}} = e^{-\frac{\sum_{i=1}^n(x_i-1)^2 - \sum_{i=1}^n x_i^2}{2}} = e^{-\frac{\sum_{i=1}^nx_i^2 - 2\sum_{i=1}^nx_i +n-\sum_{i=1}^nx_i^2}{2}}=e^{\sum_{i=1}^n x_i - \frac{n}{2}} \]

and

\[ log(\Lambda_n)=\sum_{i=1}^n x_i - \frac{n}{2} \]

Let \(log(A) = log(\frac{1-\beta}{\alpha})\) and \(log(B)=log(\frac{\beta}{1-\alpha})\) , then the stopping rule is

\[ \text{If } \sum_{i=1}^n x_i - \frac{n}{2} >log(\frac{1-\beta}{\alpha}) \Rightarrow \text{accept } H_1 \]

\[ \text{If } \sum_{i=1}^n x_i - \frac{n}{2}<log(\frac{\beta}{1-\alpha}) \Rightarrow \text{accept } H_0 \]

\[ \text{Otherwise, continue sampling} \]

Test on a few numbers at this Shiny App on SPRT.