GitHub

@@ -4,7 +4,7 @@ jupytext:

44

extension: .md

55

format_name: myst

66

format_version: 0.13

7-

jupytext_version: 1.17.2

7+

jupytext_version: 1.17.1

88

kernelspec:

99

display_name: Python 3 (ipykernel)

1010

language: python

@@ -53,7 +53,7 @@ alternative **hypotheses**, key ideas in this lecture

53535454

- Type I and type II statistical errors

5555

- a type I error occurs when you reject a null hypothesis that is true

56-

- a type II error occures when you accept a null hypothesis that is false

56+

- a type II error occurs when you accept a null hypothesis that is false

5757

- The **power** of a frequentist statistical test

5858

- The **size** of a frequentist statistical test

5959

- The **critical region** of a statistical test

@@ -109,9 +109,9 @@ Let's listen to Milton Friedman tell us what happened

109109

> can be so regarded.

110110111111

> When Allen Wallis was discussing such a problem with (Navy) Captain

112-

> Garret L. Schyler, the captain objected that such a test, to quote from

112+

> Garret L. Schuyler, the captain objected that such a test, to quote from

113113

> Allen's account, may prove wasteful. If a wise and seasoned ordnance

114-

> officer like Schyler were on the premises, he would see after the first

114+

> officer like Schuyler were on the premises, he would see after the first

115115

> few thousand or even few hundred [rounds] that the experiment need not

116116

> be completed either because the new method is obviously inferior or

117117

> because it is obviously superior beyond what was hoped for

@@ -128,7 +128,7 @@ That set Wald on a path that led him to create *Sequential Analysis* {cite}`W

128128

It is useful to begin by describing the theory underlying the test

129129

that the U.S. Navy told Captain G. S. Schuyler to use.

130130131-

Captain Schulyer's doubts motivated him to tell Milton Friedman and Allan Wallis his conjecture

131+

Captain Schuyler's doubts motivated him to tell Milton Friedman and Allen Wallis his conjecture

132132

that superior practical procedures existed.

133133134134

Evidently, the Navy had told Captain Schuyler to use what was then a state-of-the-art

@@ -256,13 +256,13 @@ Wald summarizes Neyman and Pearson's setup as follows:

256256

> will have the required size $\alpha$.

257257258258

Wald goes on to discuss Neyman and Pearson's concept of *uniformly most

259-

powerful* test.

259+

powerful* test.

260260261261

Here is how Wald introduces the notion of a sequential test

262262263263

> A rule is given for making one of the following three decisions at any stage of

264-

> the experiment (at the m th trial for each integral value of m ): (1) to

265-

> accept the hypothesis H , (2) to reject the hypothesis H , (3) to

264+

> the experiment (at the $m$ th trial for each integral value of $m$): (1) to

265+

> accept the hypothesis $H$, (2) to reject the hypothesis $H$, (3) to

266266

> continue the experiment by making an additional observation. Thus, such

267267

> a test procedure is carried out sequentially. On the basis of the first

268268

> observation, one of the aforementioned decision is made. If the first or

@@ -271,8 +271,8 @@ Here is how Wald introduces the notion of a sequential test

271271

> the first two observations, one of the three decision is made. If the

272272

> third decision is made, a third trial is performed, and so on. The

273273

> process is continued until either the first or the second decisions is

274-

> made. The number n of observations required by such a test procedure is

275-

> a random variable, since the value of n depends on the outcome of the

274+

> made. The number $n$ of observations required by such a test procedure is

275+

> a random variable, since the value of $n$ depends on the outcome of the

276276

> observations.

277277278278

## Wald's Sequential Formulation

@@ -334,7 +334,7 @@ random variables is also independently and identically distributed (IID).

334334335335

But the observer does not know which of the two distributions generated the sequence.

336336337-

For reasons explained in [Exchangeability and Bayesian Updating](https://python.quantecon.org/exchangeable.html), this means that the observer thinks that sequence is not IID.

337+

For reasons explained in [Exchangeability and Bayesian Updating](https://python.quantecon.org/exchangeable.html), this means that the observer thinks that the sequence is not IID.

338338339339

Consequently, the observer has something to learn, namely, whether the observations are drawn from $f_0$ or from $f_1$.

340340

@@ -414,7 +414,7 @@ B \approx b(\alpha,\beta) & \equiv \frac{\beta}{1-\alpha}

414414

\end{aligned}

415415

$$ (eq:Waldrule)

416416417-

For small values of $\alpha $ and $\beta$, Wald shows that approximation {eq}`eq:Waldrule` provides a good way to set $A$ and $B$.

417+

For small values of $\alpha$ and $\beta$, Wald shows that approximation {eq}`eq:Waldrule` provides a good way to set $A$ and $B$.

418418419419

In particular, Wald constructs a mathematical argument that leads him to conclude that the use of approximation

420420

{eq}`eq:Waldrule` rather than the true functions $A (\alpha, \beta), B(\alpha,\beta)$ for setting $A$ and $B$

@@ -515,12 +515,12 @@ def sprt_single_run(a0, b0, a1, b1, logA, logB, true_f0, seed):

515515

return n, True # Accept H0

516516517517

@njit(parallel=True)

518-

def run_sprt_simulation(a0, b0, a1, b1, alpha, βs, N, seed):

518+

def run_sprt_simulation(a0, b0, a1, b1, α, β, N, seed):

519519

"""SPRT simulation described by the algorithm."""

520520521521

# Calculate thresholds

522-

A = (1 - βs) / alpha

523-

B = βs / (1 - alpha)

522+

A = (1 - β) / α

523+

B = β / (1 - α)

524524

logA = np.log(A)

525525

logB = np.log(B)

526526

@@ -690,9 +690,7 @@ results_3 = run_sprt(params_3)

690690

```

691691692692

```{code-cell} ipython3

693-

---

694-

tags: [hide-input]

695-

---

693+

:tags: [hide-input]

696694697695

def plot_sprt_results(results, params, title=""):

698696

"""Plot SPRT simulation results."""

@@ -781,7 +779,7 @@ When two distributions are "close", it should takes longer to decide which one

781779782780

It is tempting to link this pattern to our discussion of [Kullback–Leibler divergence](rel_entropy) in {doc}`likelihood_ratio_process`.

783781784-

While, KL divergence is larger when two distribution differ more, KL divergence is not symmetric, meaning that the KL divergence of distribution $f$ from distribution $g$ is not necessarily equal to the KL

782+

While, KL divergence is larger when two distributions differ more, KL divergence is not symmetric, meaning that the KL divergence of distribution $f$ from distribution $g$ is not necessarily equal to the KL

785783

divergence of $g$ from $f$.

786784787785

If we want a symmetric measure of divergence that actually a metric, we can instead use [Jensen-Shannon distance](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.jensenshannon.html).

@@ -793,7 +791,7 @@ We shall compute Jensen-Shannon distance and plot it against the average stoppi

793791

```{code-cell} ipython3

794792

def kl_div(h, f):

795793

"""KL divergence"""

796-

integrand = lambda w: f(w) * np.log(f(w) / h(w))

794+

integrand = lambda w: h(w) * np.log(h(w) / f(w))

797795

val, _ = quad(integrand, 0, 1)

798796

return val

799797

@@ -896,7 +894,7 @@ plt.tight_layout()

896894

plt.show()

897895

```

898896899-

Again, we find that the stopping time is shorter when the distributions are more separated

897+

Again, we find that the stopping time is shorter when the distributions are more separated, as

900898

measured by Jensen-Shannon distance.

901899902900

Let's visualize individual likelihood ratio processes to see how they evolve toward the decision boundaries.

@@ -981,12 +979,12 @@ In the code below, we adjust Wald's rule by adjusting the thresholds $A$ and $B

981979982980

```{code-cell} ipython3

983981

@njit(parallel=True)

984-

def run_adjusted_thresholds(a0, b0, a1, b1, alpha, βs, N, seed, A_f, B_f):

982+

def run_adjusted_thresholds(a0, b0, a1, b1, α, β, N, seed, A_f, B_f):

985983

"""SPRT simulation with adjusted thresholds."""

986984987985

# Calculate original thresholds

988-

A_original = (1 - βs) / alpha

989-

B_original = βs / (1 - alpha)

986+

A_original = (1 - β) / α

987+

B_original = β / (1 - α)

990988991989

# Apply adjustment factors

992990

A_adj = A_original * A_f

Read the original on github.com ↗