# Test Optimality (cont.)

Optimality for tests with simple null and alternative hypotheses has been established by the Neyman-Pearson lemma.

For one-sided tests, the Neyman-Pearson lemma is also useful:

Consider the testing problem $H_{0}:\theta=\theta_{0}$ vs. $H_{1}:\theta\gt \theta_{0}$. We consider each value of the alternative hypothesis $\theta_{1}\gt \theta_{0}$. Each value yields the simple test $H_{0}:\theta=\theta_{0}$ vs. $H_{1}^{*}:\theta=\theta_{1}$. We then use the Neyman-Pearson lemma at each value of $\theta_{1}\gt \theta_{0}$. If all values of $\theta_{1}$ yield the same UMP level $\alpha$ test, then we have found the unique UMP level $\alpha$ test.

The lemma implies that:

• If these tests coincide for all values of $\theta_{1}\gt \theta_{0}$, then the UMP test is $\frac{f\left(\left.x\right|\theta_{1}\right)}{f\left(\left.x\right|\theta_{0}\right)}\gt k$.
• If the tests do not coincide for all values of $\theta_{1}\gt \theta_{0}$, then no UMP level $\alpha$ test exists.

When we say that the tests coincide for all values of $\theta_{1}\gt \theta_{0}$, we mean that no matter the specific value of $\theta_{1}$, we will obtain the same exact test. This will be clearer with the following example.

# Example: Normal

Suppose $X_{i}\overset{iid}{\sim}N\left(\mu,\sigma^{2}\right)$ where $\sigma^{2}$ is known. Let us derive the UMP level $\alpha$ test of

$H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu=\mu_{1}\gt \mu_{0}$ for a given $\mu_{1}$ at a time.

The Neyman-Pearson lemma suggests a test of the form $\frac{f\left(\left.x\right|\theta_{1}\right)}{f\left(\left.x\right|\theta_{0}\right)}\gt k$. With some algebra, the left-hand side yields:

\begin{aligned} \frac{\frac{1}{\sqrt{2\pi\sigma^{2}}}\exp\left(-\sum_{i=1}^{n}\frac{\left(x_{i}-\mu_{1}\right)^{2}}{2\sigma^{2}}\right)}{\frac{1}{\sqrt{2\pi\sigma^{2}}}\exp\left(-\sum_{i=1}^{n}\frac{\left(x_{i}-\mu_{0}\right)^{2}}{2\sigma^{2}}\right)} & =\exp\left(\sum_{i=1}^{n}\frac{\left(x_{i}-\mu_{0}\right)^{2}}{2\sigma^{2}}-\frac{\left(x_{i}-\mu_{1}\right)^{2}}{2\sigma^{2}}\right)\\ & =\exp\left(\frac{1}{2\sigma^{2}}\left(\sum_{i=1}^{n}x_{i}^{2}-2\mu_{0}x_{i}+\mu_{0}^{2}-\left(x_{i}^{2}-2\mu_{1}x_{i}+\mu_{1}^{2}\right)\right)\right)\\ & =\exp\left(\frac{1}{2\sigma^{2}}\left(\sum_{i=1}^{n}2x_{i}\left(\mu_{1}-\mu_{0}\right)+\mu_{0}^{2}-\mu_{1}^{2}\right)\right)\\ & =\exp\left(\frac{1}{2\sigma^{2}}\left(2n\overline{x}\left(\mu_{1}-\mu_{0}\right)+n\left(\mu_{0}-\mu_{1}\right)\left(\mu_{0}+\mu_{1}\right)\right)\right)\\ & =\exp\left(\frac{n\left(\mu_{1}-\mu_{0}\right)}{2\sigma^{2}}\left(2\overline{x}-\left(\mu_{0}+\mu_{1}\right)\right)\right)\end{aligned}

Going back to the original condition and solving it w.r.t. $\overline{x}$ yields “reject iff”:

\begin{aligned} & \exp\left(\frac{n\left(\mu_{1}-\mu_{0}\right)}{2\sigma^{2}}\left(2\overline{x}-\left(\mu_{0}+\mu_{1}\right)\right)\right)\gt k\\ \Leftrightarrow & \overline{x}\gt \frac{1}{2}\left(\mu_{0}+\mu_{1}+\frac{2\sigma^{2}\log\left(k\right)}{n\left(\mu_{1}-\mu_{0}\right)}\right)\end{aligned}

Apparently, our test does depend on $\mu_{1}$, and so it does not seem UMP. However, we will now show that for different values of $\mu_{1}$, we will end up with the exact same test.

For example, let $\alpha=0.05$, $n=30$, $\sigma^{2}=1$, $\mu_{0}=0$ and $\mu_{1}=0.1$. In this case, the probability of a type 1 error can be written as:

\begin{aligned} Pr\left(\overline{X}\gt \underset{=k^{'}}{\underbrace{\frac{1}{2}\left(0+0.1+\frac{2\log\left(k\right)}{3}\right)}}\right) & =0.05\end{aligned}

Using the fact that $\overline{x}\sim N\left(\mu_{0},\frac{\sigma^{2}}{n}\right)$ and solving for $k$ is approximately equal to $2.12$, which yields $k^{'}=0.3$. So, we will reject the null hypothesis if $\overline{x}\gt 0.3$. This produces a level $\alpha$ test.

Now, suppose that $\mu_{1}=0.2$.

In this case, the probability of a type 1 error can be written as

$Pr\left(\overline{X}\gt \frac{1}{2}\left(0.2+\frac{2\log\left(k\right)}{6}\right)\right)=0.05$

where $k$ now approximately equals $3.33$, while $k^{'}=0.3$ as before.

Our test turns out to be the same, independently of the value of $\mu_{1}$, i.e., the test does not depend on the value of $\mu_{1}$. The intuition for the test not depending on the alternative hypothesis is that the critical value is set so that the test rejects the null, when $\mu=\mu_{0}$, $\alpha\%$ of the time. This test only depends on the null hypothesis; not on the alternative hypothesis: We can write our rejection decision as $\overline{x}\gt k^{'},$ where $k^{'}$ is whatever constant we need to set the intended probability of type 1 errors.

The Neyman-Pearson lemma states that the inequality above produces the unique UMP level $\alpha$ test, with a probability of a type 1 error equal to:

\begin{aligned} & P_{\mu_{0}}\left(\overline{X}\gt k^{'}\right)=\alpha\\ \Leftrightarrow & 1-\Phi\left(\frac{\sqrt{n}\left(k^{'}-\mu_{0}\right)}{\sigma}\right)=\alpha.\end{aligned}

# Karlin-Rubin Theorem

In some cases, it is straightforward to derive the UMP test.

The Karlin-Rubin theorem states that the UMP level $\alpha$ test exists for one-sided testing,

$H_{0}:\theta\leq\theta_{0}$ vs. $H_{1}:\theta\gt \theta_{0}$

if $f\left(\left.X\right|\theta\right)$ belongs to the exponential family and $\omega\left(\theta\right)$ is monotone (i.e., the pdf/pmf satisfies the monotone likelihood ratio property).

In this case, we reject $H_{0}$ when $\sum_{i=1}^{n}t\left(X_{i}\right)$ is large.

# 2-sided tests

Consider now the testing problem $H_{0}:\theta=\theta_{0}vs.H_{1}:\theta\neq\theta_{0}$.

For values $\theta_{1}\gt \theta_{0}$, we have already seen that the UMP test rejects $H_{0}$ if $\overline{x}\lt k^{'}.$

For values of $\theta_{1}\lt \theta_{0}$, it is easy to show that the Neyman-Pearson lemma yields a test that rejects $H_{0}$ if $\overline{x}\gt k^{'}.$

Because the suggested UMP test depends on the values of $\theta_{1}$, the Neyman-Pearson lemma implies that there is a UMP $\alpha$-level test does not exist (the lemma is written in the form of “if and only if”, such that if it does not yield a unique test, then a UMP test does not exist).

If one restricts the class of tests further, it is often possible to obtain (a more restricted type of) optimality. We will restrict ourselves to the class of unbiased tests.

## Unbiased Tests

An unbiased test satisfies

$\text{sup}_{\theta\in\Theta_{0}}\,\beta\left(\theta\right)\leq\text{inf}_{\theta\in\Theta_{1}}\,\beta\left(\theta\right)$

that is, the value of the power function in the null set is always below the value in the alternative set.

Unbiased tests are important because UMP unbiased (UMPU) tests often exist, even when unrestricted UMP tests do not.

A typical example is the case of $N\left(\mu,1\right)$, with $H_{0}:\mu=\mu_{0}vs.H_{1}:\mu\neq\mu_{0}.$

(We will not go into the generalized Neyman-Pearson result applied to the optimal unbiased test.)

In the $N\left(\mu,1\right)$, it turns out that the UMPU is $T\left(X\right)=\left|\overline{X}\right|,$ i.e., we reject $H_{0}$ iff $\left|\overline{X}\right|\gt c.$

Consider the following figure, which plots the power functions of the UMP one-sided tests (in orange and blue), and the power function of the two-sided of the UMPU test (in green).

All curves intersect 0.05 at $\mu=0$, the null hypothesis in this case.

The blue curve is the power function for UMP test $H_{0}:\mu=0$ vs. $H_{1}:\mu\gt 0$: Notice it is relatively very likely to reject $H_{0}$ when $\mu\gt 0$.

The orange curve is the power function for UMP test $H_{0}:\mu=0$ vs. $H_{1}:\mu\lt 0$: It is more likely to reject $H_{0}$ when $\mu\lt 0$.

Each of these power curves is unsuitable for test problem $H_{0}:\mu=0vs.H_{1}:\mu\neq0.$

The green curve is the power function for the two-sided UMPU test. It does extremely well in the regions where the each of the one-sided power functions do the worst. However, notice that it doesn’t do as well where the other power functions do their best. This is expected, since the one-sided tests are UMP.

Intuitively, the two-sided test reallocates rejections by increasing the power function relative to the places where the one-sided tests do worst, at the expense of the cases where they do best.

# p-value

Consider the test $H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\lt \mu_{0}$, that rejects $H_{0}$ if $\overline{x}\lt c.$

Up to now, we have decided to reject $H_{0}$ by choosing $c$ to satisfy a given probability of type 1 error. Specifically, we have often selected

$c:\,P_{\mu_{0}}\left(\overline{X}\lt c\right)=.05.$

Let's define critical value $c$ above that establishes a type 1 error probability of 5% as $c_{0.05}.$

Now, suppose we replaced the generic critical value $c$ by the realized statistic in the data, $\overline{x}$. In this case, the probability of committing a type 1 error when $c=\overline{x}$ can be written as

$P_{\mu_{0}}\left(\overline{X}\lt \overline{x}\right)$

Why would we want to replace the critical value with the realization of the test statistic?

Consider what happens, for example, if we plugged in the realized value of $\overline{x}$, and obtained $P_{\mu_{0}}\left(\overline{X}\lt \overline{x}\right)=0.03.$ Clearly, this means that $\overline{x}\lt c_{0.05}$, and we should reject the null hypothesis. This is equivalent to comparing $P_{\mu_{0}}\left(\overline{X}\lt \overline{x}\right)=0.03$ to $P_{\mu_{0}}\left(\overline{X}\lt c_{0.05}\right)=0.05$, and noticing that we reject the null hypothesis as long as $P_{\mu_{0}}\left(\overline{X}\lt \overline{x}\right)\lt \alpha=0.05.$

In other words, if the type 1 error probability associated with critical value $\overline{x}$ falls below the probability threshold $\alpha$, we reject the null hypothesis.

As you may have suspected, the p-value is a statistic. One advantage of using p-values is that we obtain a quantitative measure of “by how much our hypothesis was rejected.” For example, a p-value of $0.01$ provides more evidence against the null hypothesis than a p-value of $0.04.$

We now provide a working definition of p-value (more formal and general definitions exist, for example for composite $H_{0}$).

## Definition

A p-value is the type 1 error probability of test statistic $T\left(X\right)$ with critical value $T\left(x\right)$, i.e.,

$p-value=P_{\theta_{0}}\left(T\left(X\right)\lt T\left(x\right)\right)$

for the case where $T\left(X\right)\lt T\left(x\right)$ implies that $\theta_{0}$ is rejected.

Again, consider the test $H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\lt \mu_{0}$, that rejects $H_{0}$ if $\overline{x}\lt c.$

We can calculate the p-value as:

\begin{aligned} & P_{\mu_{0}}\left(\overline{X}\lt \overline{x}\right)\\ = & P_{\mu_{0}}\left(\underset{\sim N\left(0,1\right)}{\underbrace{\frac{\overline{X}-\mu}{\frac{\sigma}{\sqrt{n}}}}}\lt \frac{\overline{x}-\mu}{\frac{\sigma}{\sqrt{n}}}\right)\\ = & \Phi\left(\frac{\overline{x}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right).\end{aligned}

# Some Notes: Notation, z-test, t-test

## $z_{\alpha}$ Notation

If you haven’t mastered the previous content, this section will be very confusing. So, please, make sure you feel well grounded, because we will now discuss other common ways in which you will see hypothesis tests written for the case of parameter $\mu$ in the normal distribution.

Consider the test $H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\lt \mu_{0}$, that rejects $H_{0}$ if $\overline{x}\lt c.$

As we have seen before, the probability of a type 1 error can be calculated as

\begin{aligned} & P_{\mu_{0}}\left(\overline{X}\lt c\right)\\ = & P_{\mu_{0}}\left(\frac{\overline{X}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\lt \frac{c-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right)\\ = & P_{\mu_{0}}\left(Z\lt \frac{c-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right)\\ = & \Phi\left(\frac{\sqrt{n}\left(c-\mu_{0}\right)}{\sigma}\right).\end{aligned}

Above, we transformed $\overline{X}$ by subtracting its mean and dividing by its standard deviation, so that we obtain a random variable with distribution $N\left(0,1\right).$

Let us define $z_{\alpha}$ implicitly, as the value of $z$ that satisfies $1-\Phi\left(z\right)=\alpha$, that is, $z_{\alpha}$ is a value s.t. a $N\left(0,1\right)$ random variable has $1-\alpha$ probability of being above it.

See the plot below for some examples:

Above, $z_{0.01}$ is given by $1-\Phi\left(z_{0.01}\right)=0.01\Leftrightarrow z_{0.01}=2.326$. By the same procedure, $z_{0.05}=1.645$ and $z_{0.15}=1.036.$

Also, notice that $z_{1-\alpha}$ is given by the value of $z$ that satisfies $\Phi\left(z\right)=\alpha$, and finally, because $N\left(0,1\right)$ is symmetric around zero, $z_{1-\alpha}=-z_{\alpha}.$

Let us now solve

$\Phi\left(\frac{\sqrt{n}\left(c-\mu_{0}\right)}{\sigma}\right)=\alpha$

with respect to $c.$

Notice that this equality is satisfied if $\frac{\sqrt{n}\left(c-\mu_{0}\right)}{\sigma}=z_{1-\alpha}=-z_{\alpha}.$

Solving this equation w.r.t. $c$ yields

$c=\mu_{0}-z_{\alpha}\frac{\sigma}{\sqrt{n}},$

such that the probability of rejecting $H_{0}$ is indeed $\alpha.$

Looking at this critical value, this means that we reject $H_{0}:\mu=0$ if

$\overline{X}\lt \mu_{0}-z_{\alpha}\frac{\sigma}{\sqrt{n}}.$

This is an equivalent way of writing our test, which you will see in many textbooks.

## The z-test: Using the Standardized Sample Mean as the Test (instead of the Sample Mean)

Up to now, we have mostly used $\overline{X}$ as the test statistic, when testing hypotheses about $\mu$, in the Normal context.

An alternative approach is to use the test statistic $Z=\frac{\overline{X}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}.$ This test statistic is the standardized sample mean, under the assumption that $\mu=\mu_{0}$.

This alternative statistic, often called the Z-score, can be useful. However, it is a priori less intuitive, because the test statistic involves a subtraction of $\mu$ under the null hypothesis. Why would we do this?

Let’s write the power function for the test:

$H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\lt \mu_{0},$

using the $Z$ statistic:

$\beta\left(\mu\right)=P\left(reject\,H_{0}\right)=P\left(Z\lt c\right)=P\left(\frac{\overline{X}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\lt c\right).$

We appear to have a bit of a problem: the power function is supposed to depend on $\mu$. However, $\mu$ does not show up in the expression; only $\mu_{0}.$

We can solve this by subtracting $\frac{\mu}{\frac{\sigma}{\sqrt{n}}}$ from both sides:

$Pr\left(\frac{\overline{X}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\lt c\right)=Pr\left(\frac{\overline{X}-\mu_{0}-\mu}{\frac{\sigma}{\sqrt{n}}}\lt c-\frac{\mu}{\frac{\sigma}{\sqrt{n}}}\right)=Pr\left(\frac{\overline{X}-\mu}{\frac{\sigma}{\sqrt{n}}}\lt c-\frac{\mu-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right).$

Now, the left-hand size is distributed as a $N\left(0,1\right)$ r.v., such that

$\beta\left(\mu\right)=Pr\left(\frac{\overline{X}-\mu}{\frac{\sigma}{\sqrt{n}}}\lt c-\frac{\mu-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right)=\Phi\left(c-\frac{\mu-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right).$

The use of statistic $Z$ appears to have yielded a slightly more complicated power function than we had when we used $\overline{X}$ directly as the test statistic. However, consider now the problem of setting $c$ to ensure the test is of level $\alpha$:

\begin{aligned} & \left.\Phi\left(c-\frac{\mu-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}\right)\right|_{\mu=\mu_{0}}=\alpha\\ \Leftrightarrow & \Phi\left(c\right)=\alpha\end{aligned}

such that we obtain the result that $c=-z_{\alpha}.$

The benefit of using statistic $Z$ (usually denoted as $Z$) is now clear: When we use statistic $Z=\frac{\overline{X}-\mu_{0}}{\frac{\sigma}{\sqrt{n}}}$, we simply need to compare the value of the transformed mean with $-z_{\alpha}.$ If $Z\lt -z_{\alpha}$, we reject the null hypothesis.

## The t-test: Unknown Population Variance

In all of the normal examples, we have maintained that $\sigma^{2}$ is known. This is for simplification purposes, but it is hardly the case in general.

Consider the hypothesis test $H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\gt \mu_{0}$.

We have just seen that one way to write the decision rule, is to reject $H_{0}$ iff

\begin{aligned} \Leftrightarrow Z= & \frac{\overline{X}-\mu}{\frac{\sigma}{\sqrt{n}}}\gt z_{\alpha}\end{aligned}

Now, suppose $\sigma$ is unknown. In this case, using the LRT, we would derive

$T_{LR}=2\left[\max_{\mu,\sigma}\,l\left(\mu,\sigma\right)-\max_{\sigma}\,l\left(\mu_{0},\sigma\right)\right]$

where the first term is the log-likelihood evaluated at the maximum-likelihood parameters, and the second term is the log-likelihood evaluated at the restricted maximum likelihood value of $\sigma$.

The maximizations will yield the following expressions for $\widehat{\sigma}_{ML}$ and $\widehat{\sigma}_{ML_{0}}$:

\begin{aligned} \widehat{\sigma}_{ML} & =\frac{1}{n}\sum_{i=1}^{n}\left(X_{i}-\widehat{\mu}_{ML}\right)^{2}=\frac{1}{n}\sum_{i=1}^{n}\left(X_{i}-\overline{X}\right)^{2}\\ \widehat{\sigma}_{ML_{0}} & =\frac{1}{n}\sum_{i=1}^{n}\left(X_{i}-\mu_{0}\right)^{2}\end{aligned}

Simplifying the LRT is tedious, but it yields the rejection rule

$T_{LR}=\frac{\overline{X}-\mu}{\frac{s}{\sqrt{n}}}$ where

$s=\sqrt{\frac{1}{n-1}\sum_{i=1}^{n}\left(X_{i}-\overline{X}\right)^{2}}$

It is possible to show that $T_{LR}$ follows a t-distribution, with pdf $f_{t}\left(\left.x\right|\nu\right)=\frac{\Gamma\left(\frac{\nu+1}{2}\right)}{\sqrt{\nu\pi}\Gamma\left(\frac{\nu}{2}\right)}\left(1+\frac{x^{2}}{\nu}\right)^{-\frac{1+\nu}{2}}$ where parameter $\nu=n-1$ and $\Gamma\left(\cdot\right)$ is the Gamma function.

# Interval Estimation/Confidence Intervals

In interval estimation, we would like to isolate plausible values of some parameter $\theta$.

Remember that in point estimation, we have attempted to find the “most plausible” value of $\theta$. In hypothesis testing, we assigned $\theta$ to one of two subsets of $\Theta$. In interval estimation, we produce an interval that is likely to contain the true parameter $\theta$.

Let $\Theta\subset\mathbb{R}$. An interval estimator of $\theta$ is a random interval $\left[L\left(X_{1}..X_{n}\right),U\left(X_{1}..X_{n}\right)\right]$ where $L\left(\cdot\right)$ and $U\left(\cdot\right)$ are statistics. We will use interval estimators and confidence intervals as synonymous. (This works well as long as we don't nitpick.)

• The coverage probability of the interval is the function (of $\theta$): $P_{\theta}\left(L\left(X_{1}..X_{n}\right)\leq\theta\leq U\left(X_{1}..X_{n}\right)\right)$ where the subscript in $P_{\theta}$ stresses the fact that $\theta$ is a scalar and not a random variable.
• The confidence coefficient is $\text{inf}_{\theta\in\Theta}P_{\theta}\left(L\left(X_{1}..X_{n}\right)\leq\theta\leq U\left(X_{1}..X_{n}\right)\right)$ i.e., for all values of $\theta\in\Theta$, the confidence coefficient is the minimum of the coverage probabilities.

## Example: Normal

Let $X_{i}\overset{iid}{\sim}N\left(\mu,\sigma^{2}\right)$, where $\sigma^{2}$ is known. The interval $\left[\overline{X}-1.96\frac{\sigma}{\sqrt{n}},\overline{X}+1.96\frac{\sigma}{\sqrt{n}}\right]$ is a 95% confidence interval (i.e., it has a confidence coefficient of 95%) of $\mu$. To see this, note that

\begin{aligned} & P_{\mu}\left(\overline{X}-1.96\frac{\sigma}{\sqrt{n}}\leq\mu\leq\overline{X}+1.96\frac{\sigma}{\sqrt{n}}\right)\\ = & P_{\mu}\left(-1.96\frac{\sigma}{\sqrt{n}}\leq\mu-\overline{X}\leq1.96\frac{\sigma}{\sqrt{n}}\right)\\ = & P_{\mu}\left(-1.96\frac{\sigma}{\sqrt{n}}\leq\overline{X}-\mu\leq1.96\frac{\sigma}{\sqrt{n}}\right)\\ = & P_{\mu}\left(-1.96\leq\underset{\sim N\left(0,1\right)}{\underbrace{\frac{\sqrt{n}\left(\overline{X}-\mu\right)}{\sigma}}}\leq1.96\right)\simeq0.95.\end{aligned}

Notice in this case that the coverage probability is equal to $0.95$ at all values of $\mu$, such that the confidence coefficient does not depend on $\mu.$

A common way to obtain confidence intervals is to 'invert' tests.

For example, consider the two-sided $Z$-test of $H_{0}:\mu=\mu_{0}$ vs. $H_{1}:\mu\neq\mu_{0}$, that rejects $H_{0}$ iff $\overline{X}-1.96\frac{\sigma}{\sqrt{n}}\gt \mu_{0}\text{ or }\overline{X}+1.96\frac{\sigma}{\sqrt{n}}\lt \mu_{0}.$

Notice that the test accepts $H_{0}$ iff $\overline{X}-1.96\frac{\sigma}{\sqrt{n}}\leq\mu_{0}\leq\overline{X}+1.96\frac{\sigma}{\sqrt{n}}.$

The confidence interval $\left[\overline{X}-1.96\frac{\sigma}{\sqrt{n}},\overline{X}+1.96\frac{\sigma}{\sqrt{n}}\right]$ consists of those values of $\mu_{0}$ for which the two-sided $z$-test does not reject $H_{0}:\mu=\mu_{0}$. In other words, there is a duality between 5% tests and 95% confidence intervals.

In general, we create a 95% confidence set for $\theta\in\Theta$ by including those values of $\theta_{0}$ for which a 5% test of $H_{0}:\theta=\theta_{0}$ does not reject.

## Optimality

A confidence set is optimal iff it is obtained by inverting an optimal test. Because an optimal test minimizes the probability of type 2 errors (i.e., accepting the null hypothesis when the alternative hypothesis was correct), the corresponding optimal interval is optimal in the sense that it minimizes the likelihood of including values of $\mu\neq\mu_{0}$ in the confidence interval.