Hypothesis Testing

A casual walkthrough of hypothesis testing basics — null vs. alternative hypotheses, Z-statistics, and how to decide when to reject what the data's telling you.

Just want to cover some very basic testing stuff and then move on.

So first — what even is hypothesis testing?

You’re comparing observed data with a null model using a rule chosen in advance. The significance level limits one specific mistake: rejecting a true null hypothesis. It doesn’t bound the chance that every conclusion you draw is wrong. That’s the distinction we’ll work through!

OK let me just throw out an example.

EX. Suppose a certain company’s lightbulbs have a lifespan that follows a normal distribution, and they run quality control so the mean is 1500 hours and the standard deviation is 100 hours.

That is — if you write the lifespan as a random variable X, then X ~ N(1500, 100²).

Now the R&D team at this company comes out and claims they’ve developed a new product — same cost, same standard deviation as the existing one, but the mean lifespan is longer.

To check this, take 25 independent bulb lifetimes from the new normal population, still assuming the population standard deviation is known to be 100 hours. Their measured mean is:

Sample mean X̄ = 1550

From this result — can we really be sure the new bulb’s mean lifespan is longer than the existing one’s?

When you’re staring down a question like this,

you do hypothesis testing.

And first — since the R&D folks are claiming the mean lifespan is strictly greater than 1500 hours, let’s set up the hypotheses like this:

H₀: θ = 1500; H₁: θ > 1500

θ represents the ‘mean lifespan’. Let me explain a bit about hypothesis testing by walking through what H_0 and H_1 are.

These guys’ claim was: “the new bulb’s mean lifespan is longer than the existing one’s mean of 1500.” That claim gets written over there as

H₁: θ > 1500

This —

H₁

— is called the alternative hypothesis.

And this —

Θ = 1500

written as

H₀

— is called the null hypothesis.

The null hypothesis is the reference model against which the test is calibrated; it does not always mean “no effect.”

That is, "

H₀

is the reference case, while the directional alternative is

H₁

."

So we set up the hypotheses and decide whether the data give enough evidence to reject the null. If not, we fail to reject it; that doesn’t establish that it is true. That’s hypothesis testing.

But of course, you’d need to be armed with some basis and logic that shuts everyone up before you can claim “this one’s adopted, that one’s rejected.” There are various criteria for testing, but here we’ll do the example with the Z-statistic.

Because there’s still more basic terminology we need to nail down.

Let’s think about the Z-statistic.

The standard deviation of

Sample mean X̄

is

Σ divided by the square root of n

, so it’s 20.

And under H_0:

Z = (X̄ − μ)/(σ/√n) = (X̄ − 1500)/20

and when

Sample mean X̄

is large enough (i.e. when the mean of what we sampled in the trial comes out absurdly large),

that is, when

Z = (X̄ − 1500)/20 ≥ Z₀.₀₅ = 1.645

we reject

H₀

and adopt the alternative hypothesis

H₁

.

Why does

Z₀.₀₅ = 1.645

this become the cutoff — well, that’s kind of up to whoever’s doing the test….

But in stats, apparently

Z₀.₀₅

or

Z₀.₁₀

get used a lot. (More on this later.)

Anyway —

(X̄ − 1500)/20 ≥ 1.645; X̄ ≥ 1.645 × 20 + 1500

if the mean of our measured sample exceeds that value, we get to reject H_0 and adopt H_1 — that!

What this actually means, deep down, we’ll come back to in a sec!!!

Before that, let’s organize the terminology here.

A statistic that serves as the standard for testing — like the Z-statistic when you’re testing by this kind of criterion — is called the test statistic.

And a region like Z ≥ 1.645, the “region where the null gets rejected,” is called the critical region.

The rest is often called the acceptance region in older terminology. Read that as the non-rejection region, not a proof that the null is true.

(cf. The boundary between them is called the critical point.)

(Whether we phrase it as ‘rejecting’ the null hypothesis or ‘adopting’ the alternative — that’s the standard.)

If we draw the critical region and acceptance region:

Equation from the original notes

Now let’s dig a little more into what Z ≥ 1.645 actually means.

First — in testing, there are two kinds of ’errors’:

  1. When the null hypothesis H_0 is true, but you adopt H_1 anyway: Type 1 error

  2. When the alternative hypothesis H_1 is true, but you fail to reject H_0: Type 2 error

So,

Equation from the original notes

we observe sample X̄, look at the Z-statistic from it, and let’s say it lands in the critical region — and I rejected the null.

But —

Equation from the original notes

what this graph is telling us is “the probability of being drawn when X̄ is drawn,” right?

That is, “the probability of drawing an X̄ that lands in the critical region when X̄ is drawn” — that green chunk over there in the diagram!!!

The event $Z\ge1.645$ is the rejection rule. Under the null model, the probability of that event is about 5%: the Type I error rate. The inequality itself is not a probability, nor the probability that the null is true after observing the data.

That is — “the probability of committing a Type 1 error” lives right here:

Equation from the original notes

We say that number means “the permissible limit of the probability of committing the error of rejecting H_0 when H_0 is actually true and adopting H_1 instead.”

It’s called the significance level, and apparently it’s commonly written as α.

So $\alpha=5\%$ means a 5% probability of rejection when the null model is true, for this test. Across repeated independent applications under that null, the long-run rejection fraction approaches 5%. It does not guarantee at most five rejections in a particular batch of 100; that count is itself random.

The matching interval procedure has confidence coefficient $1-\alpha=95\%$. That isn’t a 95% probability that one of these hypotheses is true. We’ll return to what it actually means below.

By the way, the significance levels people commonly use are 1%, 5%, and 10%.

OK so — since the R&D team’s sample mean for n = 25 was 1550,

Z = 2.5,

and since Z = 2.5 > 1.645 (it’s in the critical region),

“at significance level 5%” we get to draw the conclusion: reject the null, adopt the alternative.

At this point, let’s look at the p-value.

The mean the team got from their sample was 1550, and the Z-statistic for that was Z = 2.5, right? Then if Z = 2.5,

Normal-tail sketch: Z = 2.5, probability 0.006 = 0.6%

Under $H_0$, the probability of $Z\ge2.5$ is about $0.0062097=0.621\%$. That’s the p-value for this one-sided test. The original sketch rounds it to 0.006; keep the unrounded value when comparing it with a cutoff. For example, $p\lt0.05$ but $p\gt0.006$, so we reject at 5% and do not reject at exactly 0.6%.

We choose the test’s significance level before seeing the data; the p-value reports how far into the null distribution’s tail the observed result lies.

The meaning of the p-value is: ’the minimum significance level at which the null hypothesis H_0 can still be rejected for the given test statistic.’

For this one-sided test, a larger sample mean gives a smaller p-value: the result is less compatible with the null model in the tested direction. But $p$ is not the probability that $H_0$ is true, nor is $1-p$ the probability that $H_1$ is true. It also doesn’t measure the size or practical importance of the improvement.

OK, now those terms that felt totally foreign earlier are starting to feel a little more familiar.

Let me lightly cover the few terms we haven’t hit yet —

H: θ = θ₀

A hypothesis like this, where the parameter value is pinned to a single point, is called a simple hypothesis.

H: θ > θ₀ or θ ≠ θ₀

A hypothesis like this, where the parameter value is given as a range, is called a composite hypothesis… ;;; just terminology ;;;

Our examples use a point null. Null hypotheses can also be composite—for instance, ‘the new mean is no greater than 1500.’ In that one-sided normal-mean problem, calibrating the cutoff at the boundary, 1500, controls the rejection probability over the null range.

Power function

  1. In any given test method, the function that expresses “the probability of rejecting H_0” (i.e. the probability of landing in the critical region) as a function of the parameter θ is called the power function,

and mathematically it’s written as

Equation from the original notes

!!

  1. The value of the power function at a specific θ belonging to the alternative hypothesis H_1 is called the power, apparently.

Let’s say

X follows N(θ, 2²)

. And when we use a sample of n = 25,

let’s say

H₀: θ = 0; H₁: θ > 0

Z = (X̄ − μ)/(σ/√n) = (X̄ − 0)/(2/5) = X̄/0.4

has the standard normal distribution at $\theta=0$. At a general true mean $\theta$, its mean is $\theta/0.4$. This new example uses the cutoff 1.96, so it is a one-sided test of size about 2.5%, not the earlier 5% test. Its power function is $\pi(\theta)=1-\Phi(1.96-\theta/0.4)$:

Equation from the original notes

(Here uppercase Φ is the ‘cumulative probability’, riiight?)

And then if we keep cranking out π(θ) for θ = 0, θ = 0.4, θ = 1, etc. etc. etc., we get a bunch of values.

These values get produced…

and what you get when you plot them on a graph — that is the power function.

Power curve: π(θ) versus θ, n = 25, value 0.025 at θ = 0

Let me focus on just that one marked point.

It’s been set so that the function value at θ = 0 in π(θ) is 0.025.

This means: the probability of rejecting the null when θ = 0.

And the probability of rejection is

Equation from the original notes

since this means the probability right here —

we’ve seen this somewhere before, haven’t we?!?!?!?

It was the diagram about the significance level, wasn’t it???

Only the value at the null, $\pi(0)\approx0.025$, is the Type I error probability here. At $\theta\gt0$, $\pi(\theta)$ is the probability of correctly rejecting that null—the power—and it generally exceeds $\alpha$. For example, at $\theta=0.4$ it is about 0.169, not 0.025.

Now let’s look at this with the t-statistic.

(And while we’re at it — earlier we only did one-tailed examples, so let’s look at what two-tailed means at the same time.)

As we saw, when X follows

X follows N(μₓ, σₓ²)

,

then the sample mean follows $\bar X\sim N(\mu_X,\sigma_X^2/n)$ for independent normal observations. The next original picture is missing the bar over $X$:

Source writes X follows N(μₓ, (σₓ/√n)²); the missing bar is discussed in the editorial note

,

so

Z = (X̄ − μₓ)/(σₓ/√n)

follows the standard normal distribution, which is nice —

but usually

Σₓ

is unknown. That’s the trap.

So let’s say we replaced that

Σₓ

with

Sₓ

.

Sₓ² = sum from i = 1 to n of (Xᵢ − X̄)², divided by n − 1

That is —

(X̄ − μₓ)/(Sₓ/√n)

we’ve replaced it with this.

Now this guy no longer follows a normal distribution — as we saw earlier, you have to treat it as a t-distribution with n − 1 degrees of freedom.

So this time, let’s look at the 95% confidence interval and the critical t-value at that point using the T-statistic!

With a “two-tailed test”!!! (Degrees of freedom: 27. So sample size is 28.)

Looking up the t-distribution table,

P(−2.052 ≤ t ≤ 2.052) = 0.95

we can confirm:

Equation from the original notes

!

That is — when df = 27, the probability that the observed t-value falls in (−2.052, 2.052) is 95%, and here −2.052 and 2.052 are called the critical t-values.

t = −2.052 is the lower critical t-value, and the other one is the upper critical t-value.

And now, if we change

P(−2.052 ≤ t ≤ 2.052) = 0.95

into

Probability event transformed into X̄ − 2.052 Sₓ/√n ≤ μₓ ≤ X̄ + 2.052 Sₓ/√n

The population mean $\mu_X$ is fixed; the interval endpoints vary from sample to sample. 95% coverage means that, over repeated samples under these assumptions, about 95% of the intervals constructed this way contain that fixed mean. Once we’ve computed one interval, it either contains the mean or it doesn’t; frequentist coverage doesn’t assign a 95% probability to the fixed mean being inside that particular interval. See NIST’s confidence-interval explanation .

This time, let me throw out a quick example of testing via the chi-squared distribution before I head out.

One classical use of the chi-squared distribution is testing a normal population’s variance from its observed sample variance $S^2$. Other chi-squared tests have different purposes. Here we use independent normal observations and the usual sample variance with denominator $n-1$.

Say S² for 31 observations from a normal-distribution population is 12.

And let’s set up

Source hypothesis block labels both rows H₀: σ² = 9 and σ² ≠ 9

.

The second hypothesis in the preceding original picture should be $H_1:\sigma^2\ne9$, not another $H_0$. Under the null $\sigma^2=9$, the statistic below follows $\chi^2_{30}$:

(n − 1) S²/σ²

statistic follows the

Χ² with n − 1 degrees of freedom

distribution.

For this two-sided variance test at $\alpha=5\%$, the non-rejection region for the test statistic is approximately $16.7908\le\chi^2\le46.9792$ with 30 degrees of freedom. The original sketch below gives 18.4926 as the lower boundary; that is the 5th percentile, not the required 2.5th percentile. Its upper number is slightly mistyped too. Use the corrected boundaries here:

Chi-square rejection-tail sketch, each tail labeled 2.5%, with source bounds 18.4926 and 46.9752

But if σ² is 9,

since

Χ² = 30 × 12/9 = 40

, it lands in the acceptance region in the graph above.

So the conclusion is: “we do not reject the null hypothesis.”

OK, that was the surface-level rundown on testing.

After this, in a ‘statistics’ post rather than a ‘statistics basics’ post, I’ll deal with more and more detailed problems.

Questions or corrections?

Did a step lose you, or does a number look off? Email me or use the contact page. Include the note title and the step or figure you mean.

Feedback goes to me privately by email; it is not posted as a public comment.