Overview

Part 3 - Confidence Interval and Hypothesis Testing

Inferences for mean/proportion

Let’s recap what a confidence interval is,

Definition 1 (Confidence interval)

A confidence interval of level 100(1−α)%100(1 - \alpha)\% means that we are 100(1−α)%100(1 - \alpha)\% confident that the true value of the parameter is included into the interval.

When dealing with confidence intervals, we will often encounter different “types” of situations. Let’s review these.

Confidence Interval on the mean of a Normal Distribution, variance known

Suppose we have a normal distribution with unknown mean μ\mu and known variance σ2\sigma^2.

We have thus a random sample X1,X2,…,XnX_1, X_2, \ldots, X_n, such that, for all ii,

Xi∼N(μ,σ2)X_i \sim N(\mu, \sigma^2)

with μ\mu unknown and σ\sigma a known constant.

We would like a confidence interval for μ\mu.

We know that,

Xˉ=1n∑i=1nXi∼N(μ,σ2n)\bar{X} = \frac{1}{n} \sum_{i = 1}^n X_i \sim N\left(\mu, \frac{\sigma^2}{n}\right)

we can standardize this to,

Z=Xˉ−μσ/n=nXˉ−μσ∼N(0,1)Z = \frac{\bar{X} - \mu}{\sigma/\sqrt{n}} = \sqrt{n} \frac{\bar{X} - \mu}{\sigma} \sim N(0, 1)

So, because Z∼N(0,1)Z \sim N(0, 1),

P(−z1−α/2≤Z≤z1−α/2)=1−αP(-z_{1 - \alpha/2} \leq Z \leq z_{1 - \alpha/2}) = 1 - \alpha

Thus,

P(−z1−α/2≤nXˉ−μσ≤z1−α/2)=1−αP\left(-z_{1 - \alpha/2} \leq \sqrt{n} \frac{\bar{X} - \mu}{\sigma} \leq z_{1 - \alpha/2}\right) = 1 - \alpha

Re-arranging this, we get,

P(Xˉ−z1−α/2σn≤μ≤Xˉ+z1−α/2σn)=1−αP\left(\bar{X} - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}} \leq \mu \leq \bar{X} + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right) = 1 - \alpha

Let’s call them LL and UU for lower and upper, finally, the interval is,

[L,U]=[xˉ−z1−α/2σn,xˉ+z1−α/2σn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right]

Confidence Interval on the mean of an arbitrary distribution, variance known

Let us recap the central limit theorem.

The Central Limit Theorem (CLT) implies if nn is large enough,

Z=nXˉ−μσ∼N(0,1)Z = \sqrt{n} \frac{\bar{X} - \mu}{\sigma} \sim N(0, 1)

Thus,

P(−z1−α/2≤nXˉ−μσ≤z1−α/2)≃1−αP\left(-z_{1 - \alpha/2} \leq \sqrt{n} \frac{\bar{X} - \mu}{\sigma} \leq z_{1 - \alpha/2}\right) \simeq 1 - \alpha

Which yields the (same) interval,

[L,U]=[xˉ−z1−α/2σn,xˉ+z1−α/2σn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right]

Confidence interval on the mean of a normal distribution, variance unknown

In the case we do not have the variance, we need to sample it!

Recall the sample variance,

S2=1n−1∑i=1n(Xi−Xˉ)2S^2 = \frac{1}{n - 1} \sum_{i = 1}^n (X_i - \bar{X})^2

A natural procedure is thus to,

T=nXˉ−μST = \sqrt{n} \frac{\bar{X} - \mu}{S}

In a normal population, the exact distribution of TT is T∼tn−1T \sim t_{n - 1}.

We can write,

P(−tn−1;1−α/2≤nXˉ−μS≤tn−1;1−α/2)=1−αP(-t_{n - 1;1 - \alpha/2} \leq \sqrt{n} \frac{\bar{X} - \mu}{S} \leq t_{n - 1;1 - \alpha/2}) = 1 - \alpha

or,

P(Xˉ−tn−1;1−α/2Sn≤μ≤Xˉ+tn−1;1−α/2Sn)=1−αP\left(\bar{X} - t_{n - 1;1 - \alpha/2} \frac{S}{\sqrt{n}} \leq \mu \leq \bar{X} + t_{n - 1;1 - \alpha/2} \frac{S}{\sqrt{n}}\right) = 1 - \alpha

Which yields us the interval,

[L,U]=[xˉ−tn−1;1−α/2sn,xˉ+tn−1;1−α/2sn][L, U] = \left[\bar{x} - t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}, \bar{x} + t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}\right]

In large samples,

T≃N(0,1)T \simeq N(0, 1)

Consequently, an approximate confidence interval of level 100(1−α)%100(1 - \alpha)\% for μ\mu is,

[L,U]=[xˉ−z1−α/2sn,xˉ+z1−α/2sn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{s}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{s}{\sqrt{n}}\right]

Confidence Interval on the mean: Summary

Is the population normal?

  • If yes, is σ\sigma known?
    • If yes, use an exact zz-confidence interval:
      • [L,U]=[xˉ−z1−α/2σn,xˉ+z1−α/2σn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right]
    • If no, use an exact tt-confidence interval:
      • [L,U]=[xˉ−tn−1;1−α/2sn,xˉ+tn−1;1−α/2sn][L, U] = \left[\bar{x} - t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}, \bar{x} + t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}\right]
  • If no, use an approximate large sample confidence interval:
    • [L,U]=[xˉ−z1−α/2σn,xˉ+z1−α/2σn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right]
    • or
    • [L,U]=[xˉ−z1−α/2sn,xˉ+z1−α/2sn][L, U] = \left[\bar{x} - z_{1 - \alpha/2} \frac{s}{\sqrt{n}}, \bar{x} + z_{1 - \alpha/2} \frac{s}{\sqrt{n}}\right]

Confidence Interval on the proportion

The random variable to study is,

X={1If the individual has the characteristic of interest0If notX = \begin{cases} 1 & \text{If the individual has the characteristic of interest} \newline 0 & \text{If not} \end{cases}

X1,X2,…,XnX_1, X_2, \ldots, X_n is a set of nn independent Bern(pp) random variables.

Thus,

Y=∑i=1nXi∼B(n,p)Y = \sum_{i = 1}^n X_i \sim B(n, p)

and the sample proportion is,

P^=Yn\hat{P} = \frac{Y}{n}

We also know that,

nP^−pp(1−p)∼N(0,1)\sqrt{n} \frac{\hat{P} - p}{\sqrt{p(1 - p)}} \sim N(0, 1)

if nn is large.

Approximate two-sided confidence interval of level 100(1−α)%100(1 - \alpha)\% for pp is given by,

[p^−z1−α/2p^(1−p^)n,p^+z1−α/2p^(1−p^)n]\left[\hat{p} - z_{1 - \alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}, \hat{p} + z_{1 - \alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}\right]

Hypotheses testing for the mean

Let’s recall hypothesis testing. The null hypothesis is usually of the form,

H0:μ=μ0H_0 : \mu = \mu_0

The alternative hypothesis can be a two-sided alternative,

Ha:μ≠μ0H_a : \mu \neq \mu_0

or one-sided alternatives,

Ha:μ>μ0orHa:μ<μ0H_a : \mu > \mu_0 \quad \text{or} \quad H_a : \mu < \mu_0

Remember, we have two important cases

  1. Rejecting H0H_0 when it is true: type I error.
  2. Failing to reject H0H_0 when it is false: type II error.
P(Type I error)=P(reject H0∣H0 is true)=α,P(Type II error)=P(fail to reject H0∣H0 is false)=β.\begin{align*} P(\text{Type I error}) & = P(\text{reject } H_0 \mid H_0 \text{ is true}) = \alpha, \newline P(\text{Type II error}) & = P(\text{fail to reject } H_0 \mid H_0 \text{ is false}) = \beta. \end{align*}

Note that β\beta depends on the (unknown) value of μ\mu under the alternative.

Assume for the moment that the population is normal with known σ\sigma.

Xˉ∼N(μ,σ2n).\bar{X} \sim N\left(\mu, \frac{\sigma^2}{n}\right).

At significance level α\alpha, we are after two constants ℓ\ell and uu such that,

α=P(Xˉ∉[ℓ,u] when μ=μ0)=P(Z∉[nℓ−μ0σ,nu−μ0σ])\alpha = P(\bar{X} \notin [\ell, u] \text{ when } \mu = \mu_0) = P\left(Z \notin \left[\sqrt{n} \frac{\ell - \mu_0}{\sigma}, \sqrt{n} \frac{u - \mu_0}{\sigma}\right]\right)

Thus,

nℓ−μ0σ=zα/2=−z1−α/2\sqrt{n} \frac{\ell - \mu_0}{\sigma} = z_{\alpha/2} = -z_{1 - \alpha/2}

and,

nu−μ0σ=z1−α/2\sqrt{n} \frac{u - \mu_0}{\sigma} = z_{1 - \alpha/2}

This yields,

ℓ=μ0−z1−α/2σn,u=μ0+z1−α/2σn.\ell = \mu_0 - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \quad u = \mu_0 + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}.

The decision rule is then,

Reject H0 if xˉ∉[μ0−z1−α/2σn,μ0+z1−α/2σn].\text{Reject } H_0 \text{ if } \bar{x} \notin \left[\mu_0 - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \mu_0 + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right].

Hypotheses testing for the mean: pp-value

The pp-value is the probability that the test statistic will take on a value that is at least as extreme as the observed value when H0H_0 is true. (extreme is to be understood in the direction of the alternative).

When testing H0:μ=μ0H_0 : \mu = \mu_0 against Ha:μ≠μ0H_a : \mu \neq \mu_0, the pp-value will be the probability of finding the random variable Xˉ\bar{X} more different to μ0\mu_0 than the observed xˉ\bar{x}, that is,

p=P(Xˉ∉[μ0±∣xˉ−μ0∣] when μ=μ0)=1−P(Xˉ∈[μ0±∣xˉ−μ0∣] when μ=μ0)\begin{align*} p & = P(\bar{X} \notin [\mu_0 \pm |\bar{x} - \mu_0|] \text{ when } \mu = \mu_0) \newline & = 1 - P(\bar{X} \in [\mu_0 \pm |\bar{x} - \mu_0|] \text{ when } \mu = \mu_0) \end{align*}

Let us define,

z0=nxˉ−μ0σz_0 = \sqrt{n} \frac{\bar{x} - \mu_0}{\sigma}

as the “observed value of the test statistic”.

As we know that Z=nXˉ−μ0σ∼N(0,1)Z = \sqrt{n} \frac{\bar{X} - \mu_0}{\sigma} \sim N(0, 1), we can write,

p=1−P(nXˉ−μ0σ∈[nμ0±∣xˉ−μ0∣−μ0σ])=1−P(Z∈[−∣z0∣,∣z0∣])=2(1−Φ(∣z0∣))\begin{align*} p & = 1 - P\left(\sqrt{n} \frac{\bar{X} - \mu_0}{\sigma} \in \left[\sqrt{n} \frac{\mu_0 \pm |\bar{x} - \mu_0| - \mu_0}{\sigma}\right]\right) \newline & = 1 - P(Z \in [-|z_0|, |z_0|]) = 2(1 - \Phi(|z_0|)) \end{align*}

Operationally, since a pp-value is computed, we typically compare it to a predefined significance level α\alpha to make a decision:

{if p<α, reject H0if p≥α, do not reject H0\begin{cases} \text{if } p < \alpha, \text{ reject } H_0 \newline \text{if } p \geq \alpha, \text{ do not reject } H_0 \end{cases}

Hypotheses testing for the mean: one-sided

With Ha:μ>μ0H_a : \mu > \mu_0 we are after a constant uu such that,

P(Xˉ>u when μ=μ0)=αP(\bar{X} > u \text{ when } \mu = \mu_0) = \alpha

As we know that Z=nXˉ−μ0σ∼N(0,1)Z = \sqrt{n} \frac{\bar{X} - \mu_0}{\sigma} \sim N(0, 1), the decision rule is reject H0H_0 if xˉ>μ0+z1−ασn\bar{x} > \mu_0 + z_{1 - \alpha} \frac{\sigma}{\sqrt{n}}.

Again with z0=nxˉ−μ0σz_0 = \sqrt{n} \frac{\bar{x} - \mu_0}{\sigma}, the pp-value is,

p=P(Xˉ>xˉ when μ=μ0)=P(Z>nxˉ−μ0σ)=1−Φ(z0)p = P(\bar{X} > \bar{x} \text{ when } \mu = \mu_0) = P(Z > \sqrt{n} \frac{\bar{x} - \mu_0}{\sigma}) = 1 - \Phi(z_0)

With Ha:μ<μ0H_a : \mu < \mu_0, we are after a constant ℓ\ell such that,

P(Xˉ<ℓ when μ=μ0)=αP(\bar{X} < \ell \text{ when } \mu = \mu_0) = \alpha

The decision rule is reject H0H_0 if xˉ<μ0−z1−ασn\bar{x} < \mu_0 - z_{1 - \alpha} \frac{\sigma}{\sqrt{n}}.

The pp-value is,

p=P(Xˉ<xˉ when μ=μ0)=P(Z<nxˉ−μ0σ)=Φ(z0)p = P(\bar{X} < \bar{x} \text{ when } \mu = \mu_0) = P(Z < \sqrt{n} \frac{\bar{x} - \mu_0}{\sigma}) = \Phi(z_0)

Hypotheses testing for the mean: other cases

Say we have a normal population with unknown standard deviation.

Specifically, for the two-sided test H0:μ=μ0H_0 : \mu = \mu_0 against Ha:μ≠μ0H_a : \mu \neq \mu_0, the decision rule is,

reject H0 if xˉ∉[μ0−tn−1;1−α/2sn,μ0+tn−1;1−α/2sn]\text{reject } H_0 \text{ if } \bar{x} \notin \left[\mu_0 - t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}, \mu_0 + t_{n - 1;1 - \alpha/2} \frac{s}{\sqrt{n}}\right]

and from the observed value of the test statistic,

t0=nxˉ−μ0st_0 = \sqrt{n} \frac{\bar{x} - \mu_0}{s}

we can compute the pp-value,

p=1−P(T∈[−∣t0∣,∣t0∣])=2P(T>∣t0∣),where T∼tn−1.p = 1 - P(T \in [-|t_0|, |t_0|]) = 2P(T > |t_0|), \quad \text{where } T \sim t_{n - 1}.

If we have non-normal populations with known or unknown standard deviation,

reject H0 if xˉ∉[μ0−z1−α/2σn,μ0+z1−α/2σn]\text{reject } H_0 \text{ if } \bar{x} \notin \left[\mu_0 - z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}, \mu_0 + z_{1 - \alpha/2} \frac{\sigma}{\sqrt{n}}\right]

or,

reject H0 if xˉ∉[μ0−z1−α/2sn,μ0+z1−α/2sn]\text{reject } H_0 \text{ if } \bar{x} \notin \left[\mu_0 - z_{1 - \alpha/2} \frac{s}{\sqrt{n}}, \mu_0 + z_{1 - \alpha/2} \frac{s}{\sqrt{n}}\right]

The associated approximate pp-value will be given by,

p=2(1−Φ(∣z0∣)),p = 2(1 - \Phi(|z_0|)),

with z0=nxˉ−μ0σz_0 = \sqrt{n} \frac{\bar{x} - \mu_0}{\sigma} or z0=nxˉ−μ0sz_0 = \sqrt{n} \frac{\bar{x} - \mu_0}{s}.

Hypotheses testing for the proportion

Large-sample confidence interval for pp,

[p^−z1−α/2p^(1−p^)n,p^+z1−α/2p^(1−p^)n]\left[\hat{p} - z_{1 - \alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}, \hat{p} + z_{1 - \alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}\right]

The decision rule at (approximate) level α\alpha is,

reject H0 if p^∉[p0−z1−α/2p0(1−p0)n,p0+z1−α/2p0(1−p0)n]\text{reject } H_0 \text{ if } \hat{p} \notin \left[p_0 - z_{1 - \alpha/2} \sqrt{\frac{p_0(1 - p_0)}{n}}, p_0 + z_{1 - \alpha/2} \sqrt{\frac{p_0(1 - p_0)}{n}}\right]

The (approximate) pp-value for this test is,

p=2(1−Φ(∣z0∣))p = 2(1 - \Phi(|z_0|))

where z0=np^−p0p0(1−p0)z_0 = \sqrt{n} \frac{\hat{p} - p_0}{\sqrt{p_0(1 - p_0)}}.

R code for finding z1−α/2z_{1 - \alpha/2}

alpha<-0.05
zstar<-qnorm(1-alpha/2)

Example

Suppose 53 people among 100 surveyed is for the proposition, find the 95% confidence interval for the proportion of people in favor of the proposition.

n<-100
phat<-53/n
SE<-sqrt(phat*(1-phat)/n)
alpha<-0.05
zstar<-qnorm(1 - alpha/2)
> c(phat-zstar*SE, phat+zstar*SE)
[1] 0.432178 0.6278216

Built-in functions in R for finding the CI of proportion estimate

prop.test(x=53, n=100, conf.level=0.95)
> 1-sample proportions test with continuity correction
>
> data: 53 out of 100, null probability 0.5
> X-squared = 0.25, df = 1, p-value = 0.6171
> alternative hypothesis: true p is not equal to 0.5
> 95 percent confidence interval:
> 0.4280225 0.6296465
> sample estimates:
> p
> 0.53

Built-in functions in R for finding the CI of mean estimate

x<-c(175, 185, 170, 184, 175)
t.test(x, conf.level=0.90)
> One Sample t-test
>
> data: x
> t = 61.567, df = 4, p-value = 4.169e-07
> alternative hypothesis: true mean is not equal to 0
> 90 percent confidence interval:
> 171.6434 183.9566
> sample estimates:
> mean of x
> 177.8
t.test(x, conf.level=0.90, alt="less")
> One Sample t-test
>
> data: x
> t = 61.567, df = 4, p-value = 1
> alternative hypothesis: true mean is less than 0
> 90 percent confidence interval:
> -Inf 182.2278
> sample estimates:
> mean of x
> 177.8

Inferences for difference of means

In many situations it is quite common to be interested in *comparing two ‘populations’ in regard to a parameter of interest.

The two ‘populations’ may be:

  • Produced items using an existing and a new technique.
  • Success rates in two groups of individuals.
  • Health test results for patients who received a drug and for patients who received a placebo.

Two-sample test

X11,X12,…,X1n1X_{11}, X_{12}, \ldots, X_{1n_1} is a sample from population 1. X21,X22,…,X2n2X_{21}, X_{22}, \ldots, X_{2n_2} is a sample from population 2.

The samples are independent (i.e., observations in sample 1 are by no means linked to the observations in sample 2, they concern different individuals).

What we would like to know is whether μ1=μ2\mu_1 = \mu_2 or not.

So,

H0:μ1=μ2H_0 : \mu_1 = \mu_2

We compute the sample means xˉ1\bar{x}_1 and xˉ2\bar{x}_2.

  • If xˉ1≃xˉ2\bar{x}_1 \simeq \bar{x}_2, then H0H_0 is probably acceptable.
  • If xˉ1\bar{x}_1 is considerably different to xˉ2\bar{x}_2, that is evidence that H0H_0 is not true and we are tempted to reject it.

Note that the alternative hypothesis can be,

H1:μ1≠μ2(two-sided alternative),H_1 : \mu_1 \neq \mu_2 \quad \text{(two-sided alternative)},

or,

H1:μ1>μ2orH1:μ1<μ2(one-sided alternative).H_1 : \mu_1 > \mu_2 \quad \text{or} \quad H_1 : \mu_1 < \mu_2 \quad \text{(one-sided alternative)}.

We know that,

Xˉ1=1n1∑i=1n1X1i∼N(μ1,σ12n1)\bar{X}_1 = \frac{1}{n_1} \sum_{i = 1}^{n_1} X_{1i} \sim N\left(\mu_1, \frac{\sigma_1^2}{n_1}\right)

and,

Xˉ2=1n2∑i=1n2X2i∼N(μ2,σ22n2)\bar{X}_2 = \frac{1}{n_2} \sum_{i = 1}^{n_2} X_{2i} \sim N\left(\mu_2, \frac{\sigma_2^2}{n_2}\right)

we deduce the sampling distribution of Xˉ1−Xˉ2\bar{X}_1 - \bar{X}_2,

Xˉ1−Xˉ2∼N(μ1−μ2,σ12n1+σ22n2)\bar{X}_1 - \bar{X}_2 \sim N\left(\mu_1 - \mu_2, \frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}\right)

Now, testing for H0:μ1=μ2H_0 : \mu_1 = \mu_2 exactly amounts to for H0:μ1−μ2=0H_0 : \mu_1 - \mu_2 = 0, with Xˉ1−Xˉ2\bar{X}_1 - \bar{X}_2 as an estimator for μ1−μ2\mu_1 - \mu_2.

Two-sample test: known variances

Suppose that σ1\sigma_1 and σ2\sigma_2 are known.

For the two-sided test (with Ha:μ1−μ2≠0H_a : \mu_1 - \mu_2 \neq 0), at significance level α\alpha, the decision rule is,

Reject H0 if xˉ1−xˉ2∉[−z1−α/2σ12n1+σ22n2,z1−α/2σ12n1+σ22n2]\text{Reject } H_0 \text{ if } \bar{x}_1 - \bar{x}_2 \notin \left[-z_{1 - \alpha/2} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}, z_{1 - \alpha/2} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}\right]

pp-value is,

p=2(1−Φ(∣z0∣)),p = 2(1 - \Phi(|z_0|)),

where z0=xˉ1−xˉ2σ12n1+σ22n2z_0 = \frac{\bar{x}_1 - \bar{x}_2}{\sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}}.

Similarly, for the one-sided test Ha:μ1>μ2H_a : \mu_1 > \mu_2, the decision rule is,

reject H0 if xˉ1−xˉ2>z1−ασ12n1+σ22n2\text{reject } H_0 \text{ if } \bar{x}_1 - \bar{x}_2 > z_{1 - \alpha} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}

and the pp-value is,

p=1−Φ(z0)p = 1 - \Phi(z_0)

while for the one-sided test Ha:μ1<μ2H_a : \mu_1 < \mu_2, the decision rule is,

reject H0 if xˉ1−xˉ2<−z1−ασ12n1+σ22n2\text{reject } H_0 \text{ if } \bar{x}_1 - \bar{x}_2 < -z_{1 - \alpha} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}

and the pp-value is,

p=Φ(z0)p = \Phi(z_0)

100(1−α)%100(1 - \alpha)\% two-sided confidence interval for μ1−μ2\mu_1 - \mu_2 is,

[(xˉ1−xˉ2)−z1−α/2σ12n1+σ22n2,(xˉ1−xˉ2)+z1−α/2σ12n1+σ22n2]\left[(\bar{x}_1 - \bar{x}_2) - z_{1 - \alpha/2} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}, (\bar{x}_1 - \bar{x}_2) + z_{1 - \alpha/2} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}\right]

100(1−α)%100(1 - \alpha)\% one-sided confidence intervals for μ1−μ2\mu_1 - \mu_2 are,

(−∞,(xˉ1−xˉ2)+z1−ασ12n1+σ22n2]\left(-\infty, (\bar{x}_1 - \bar{x}_2) + z_{1 - \alpha} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}\right]

and,

[(xˉ1−xˉ2)−z1−ασ12n1+σ22n2,+∞)\left[(\bar{x}_1 - \bar{x}_2) - z_{1 - \alpha} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}, +\infty\right)

Two-sample test: unknown equal variances

Assume now σ1=σ2=σ\sigma_1 = \sigma_2 = \sigma, but σ\sigma is unknown.

We can estimate σ2\sigma^2 by the pooled variance estimator,

Sp2=∑i=1n1(X1i−Xˉ1)2+∑i=1n2(X2i−Xˉ2)2n1+n2−2S_{p}^2 = \frac{\sum_{i = 1}^{n_1} \left(X_{1i} - \bar{X}_1\right)^2 + \sum_{i = 1}^{n_2} \left(X_{2i} - \bar{X}_2\right)^2}{n_1 + n_2 - 2}

Where S12S_1^2 and S22S_2^2 are the sample variances of the two samples,

S12=1n1−1∑i=1n1(X1i−Xˉ1)2S_1^2 = \frac{1}{n_1 - 1} \sum_{i = 1}^{n_1} (X_{1i} - \bar{X}_1)^2

and,

S22=1n2−1∑i=1n2(X2i−Xˉ2)2S_2^2 = \frac{1}{n_2 - 1} \sum_{i = 1}^{n_2} (X_{2i} - \bar{X}_2)^2

For the two-sided test (with Ha:μ1−μ2≠0H_a : \mu_1 - \mu_2 \neq 0), at significance level α\alpha, the decision rule is,

reject H0 if xˉ1−xˉ2∉[−tn1+n2−2;1−α/2sp1n1+1n2,tn1+n2−2;1−α/2sp1n1+1n2]\text{reject } H_0 \text{ if } \bar{x}_1 - \bar{x}_2 \notin \left[-t_{n_1 + n_2 - 2;1 - \alpha/2} s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}, t_{n_1 + n_2 - 2;1 - \alpha/2} s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}\right]

The pp-value is given by,

p=2P(T>∣t0∣)p = 2P(T > |t_0|)

with T∼tn1+n2−2T \sim t_{n_1 + n_2 - 2}, and where t0t_0 is the observed value of the test statistic,

t0=xˉ1−xˉ2sp1n1+1n2t_0 = \frac{\bar{x}_1 - \bar{x}_2}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}

This test is known as the two-sample tt-test.

A 100(1−α)%100(1 - \alpha)\% two-sided confidence interval for μ1−μ2\mu_1 - \mu_2 is,

[(xˉ1−xˉ2)−tn1+n2−2;1−α/2sp1n1+1n2,(xˉ1−xˉ2)+tn1+n2−2;1−α/2sp1n1+1n2]\left[(\bar{x}_1 - \bar{x}_2) - t_{n_1 + n_2 - 2;1 - \alpha/2} s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}, (\bar{x}_1 - \bar{x}_2) + t_{n_1 + n_2 - 2;1 - \alpha/2} s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}\right]

Two-sample test: unknown unequal variances

There is no exact result available. An approximate result can be applied,

(Xˉ1−Xˉ2)−(μ1−μ2)S12n1+S22n2∼tν\frac{(\bar{X}_1 - \bar{X}_2) - (\mu_1 - \mu_2)}{\sqrt{\frac{S_1^2}{n_1} + \frac{S_2^2}{n_2}}} \sim t_{\nu}

where the number of degrees of freedom is,

ν=(S12n1+S22n2)2(S12n1)2n1−1+(S22n2)2n2−1\nu = \frac{\left(\frac{S_1^2}{n_1} + \frac{S_2^2}{n_2}\right)^2}{\frac{\left(\frac{S_1^2}{n_1}\right)^2}{n_1 - 1} + \frac{\left(\frac{S_2^2}{n_2}\right)^2}{n_2 - 1}}

(rounded down to the nearest integer).

This is called Welch’s two sample tt-test.

Example

6 subjects were given a drug (treatment group, μ2\mu_2) and an additional 6 subjects a placebo (control group, μ1\mu_1). Their reaction time to a stimulus was measured (in ms). Perform a two sample tt-test for comparing the means of the treatment and control groups

Let’s use a one-sided test.

H0:μ1=μ2vsH1:μ1<μ2H_0 : \mu_1 = \mu_2 \quad \text{vs} \quad H_1 : \mu_1 < \mu_2
control<-c(91, 87, 99, 77, 88, 91)
treat<-c(101, 110, 103, 93, 99, 104)
t.test(control, treat, alternative="less", var.equal=TRUE)
> Two Sample t-test
>
> data: control and treat
> t = -3.4456, df = 10, p-value = 0.003136
> alternative hypothesis: true difference in means is less than 0
> 95 percent confidence interval:
> -Inf -6.082744
> sample estimates:
> mean of x mean of y
> 88.83333 101.66667

We can also do a Welch test,

t.test(control, treat, alternative="less")
> Welch Two Sample t-test
>
> data: control and treat
> t = -3.4456, df = 9.4797, p-value = 0.003391
> alternative hypothesis: true difference in means is less than 0
> 95 percent confidence interval:
> -Inf -6.044949
> sample estimates:
> mean of x mean of y
> 88.83333 101.66667

Paired data for difference of means

Two sample tt-test cannot be used when we deal with “before and after” data, and numerous situations where the data are naturally paired (and thus, not independent).

Let (X11,X21),(X12,X22),…,(X1n,X2n)(X_{11}, X_{21}), (X_{12}, X_{22}), \ldots, (X_{1n}, X_{2n}) be a random sample of nn pairs of observations drawn from two subpopulations X1X_1 and X2X_2, with respective means μ1\mu_1 and μ2\mu_2.

An easy way is just to consider the differences.

Di=X1i−X2i.D_i = X_{1i} - X_{2i}.

We have just a sample D1,D2,…,DnD_1, D_2, \ldots, D_n from a distribution with mean,

μD=μ1−μ2\mu_D = \mu_1 - \mu_2

Testing for H0:μ1=μ2H_0 : \mu_1 = \mu_2 is just H0:μD=0H_0 : \mu_D = 0. This can be accomplished by performing the usual one sample test for mean.

So, in R we can,

t.test(x,y, paired=TRUE)
# or
t.test(x-y)

Inferences for variance

We know that,

S2=1n−1∑i=1n(Xi−Xˉ)2S^2 = \frac{1}{n - 1} \sum_{i = 1}^n (X_i - \bar{X})^2

and is a natural estimator for the population variance σ2\sigma^2.

In general, little can be said about the distribution of S2S^2. However, when the population is normal, that is X∼N(μ,σ2)X \sim N(\mu, \sigma^2), then,

(n−1)S2σ2∼χn−12\frac{(n - 1)S^2}{\sigma^2} \sim \chi^2_{n - 1}

Let χν;α2\chi^2_{\nu; \alpha} be the value such that,

P(X>χν;α2)=αP(X > \chi^2_{\nu; \alpha}) = \alpha

for X∼χν2X \sim \chi^2_{\nu}.

As we know that,

(n−1)S2σ2∼χn−12\frac{(n - 1)S^2}{\sigma^2} \sim \chi^2_{n - 1}

we can write,

P(χn−1;1−α/22≤(n−1)S2σ2≤χn−1;α/22)=1−αP(\chi^2_{n - 1;1 - \alpha/2} \leq \frac{(n - 1)S^2}{\sigma^2} \leq \chi^2_{n - 1;\alpha/2}) = 1 - \alpha

which can be re-arranged to,

P((n−1)S2χn−1;α/22≤σ2≤(n−1)S2χn−1;1−α/22)=1−αP\left(\frac{(n - 1)S^2}{\chi^2_{n - 1;\alpha/2}} \leq \sigma^2 \leq \frac{(n - 1)S^2}{\chi^2_{n - 1;1 - \alpha/2}}\right) = 1 - \alpha

Which gives us the interval,

[(n−1)S2χn−1;α/22,(n−1)S2χn−1;1−α/22]\left[\frac{(n - 1)S^2}{\chi^2_{n - 1;\alpha/2}}, \frac{(n - 1)S^2}{\chi^2_{n - 1;1 - \alpha/2}}\right]

Now, H0:σ2=σ02H_0 : \sigma^2 = \sigma_0^2 against Ha:σ2≠σ02H_a : \sigma^2 \neq \sigma_0^2. It is natural to reject H0H_0 whenever s2s^2 is too distant from σ02\sigma_0^2.

We are after two constants ℓ\ell and uu such that,

α=P(S2∉[ℓ,u] when σ2=σ02)=P((n−1)S2σ02∉[(n−1)ℓσ02,(n−1)uσ02])\alpha = P(S^2 \notin [\ell, u] \text{ when } \sigma^2 = \sigma_0^2) = P\left(\frac{(n - 1)S^2}{\sigma_0^2} \notin \left[\frac{(n - 1)\ell}{\sigma_0^2}, \frac{(n - 1)u}{\sigma_0^2}\right]\right)

This yields,

ℓ=χn−1;1−α/22σ02n−1,u=χn−1;α/22σ02n−1.\ell = \frac{\chi^2_{n - 1;1 - \alpha/2} \sigma_0^2}{n - 1}, \quad u = \frac{\chi^2_{n - 1;\alpha/2} \sigma_0^2}{n - 1}.

The decision rule is then,

Reject H0 if s2∉[χn−1;1−α/22σ02n−1,χn−1;α/22σ02n−1].\text{Reject } H_0 \text{ if } s^2 \notin \left[\frac{\chi^2_{n - 1;1 - \alpha/2} \sigma_0^2}{n - 1}, \frac{\chi^2_{n - 1;\alpha/2} \sigma_0^2}{n - 1}\right].

One-sided CI,

[0,(n−1)S2χn−1;1−α2],[(n−1)S2χn−1;α2,+∞).\left[0, \frac{(n - 1)S^2}{\chi^2_{n - 1;1 - \alpha}}\right], \quad \left[\frac{(n - 1)S^2}{\chi^2_{n - 1;\alpha}}, +\infty\right).

One-sided test,

For Ha:σ2>σ02, reject H0 if s2>χn−1;α2σ02n−1,For Ha:σ2<σ02, reject H0 if s2<χn−1;1−α2σ02n−1.\begin{align*} & \text{For } H_a : \sigma^2 > \sigma_0^2, \text{ reject } H_0 \text{ if } s^2 > \frac{\chi^2_{n - 1;\alpha} \sigma_0^2}{n - 1}, \newline & \text{For } H_a : \sigma^2 < \sigma_0^2, \text{ reject } H_0 \text{ if } s^2 < \frac{\chi^2_{n - 1;1 - \alpha} \sigma_0^2}{n - 1}. \end{align*}

The pp-value is,

P(S2>s2)=1−P((n−1)S2σ02≤(n−1)s2σ02)=1−P(χn−12≤(n−1)s2σ02),P(S2<s2)=P((n−1)S2σ02≤(n−1)s2σ02)=P(χn−12≤(n−1)s2σ02).\begin{align*} P(S^2 > s^2) & = 1 - P\left(\frac{(n - 1) S^2}{\sigma^2_0} \leq \frac{(n - 1) s^2}{\sigma^2_0}\right) = 1 - P\left(\chi^2_{n - 1} \leq \frac{(n - 1) s^2}{\sigma^2_0}\right), \newline P(S^2 < s^2) & = P\left(\frac{(n - 1) S^2}{\sigma^2_0} \leq \frac{(n - 1) s^2}{\sigma^2_0}\right) = P\left(\chi^2_{n - 1} \leq \frac{(n - 1) s^2}{\sigma^2_0}\right). \end{align*}

Inferences for ratio of variances/test of equality of variances

Let X11,X12,…,X1n1X_{11}, X_{12}, \ldots, X_{1n_1} be a sample from population 1. Let X21,X22,…,X2n2X_{21}, X_{22}, \ldots, X_{2n_2} be a sample from population 2.

The samples are independent, and we would like to know whether σ12=σ22\sigma_1^2 = \sigma_2^2 or not.

Define the sample variances,

S12=1n1−1∑i=1n1(X1i−Xˉ1)2,S22=1n2−1∑i=1n2(X2i−Xˉ2)2S_1^2 = \frac{1}{n_1 - 1} \sum_{i = 1}^{n_1} (X_{1i} - \bar{X}_1)^2, \quad S_2^2 = \frac{1}{n_2 - 1} \sum_{i = 1}^{n_2} (X_{2i} - \bar{X}_2)^2

We can use the test statistic,

F=S12S22F = \frac{S_1^2}{S_2^2}

In general, there is no known exact distribution for FF. Fortunately, if X1i∼N(μ1,σ12)X_{1i} \sim N(\mu_1, \sigma_1^2) and X2i∼N(μ2,σ22)X_{2i} \sim N(\mu_2, \sigma_2^2), FF has an F(n1−1,n2−1)F(n_1 - 1, n_2 - 1) distribution if the null (σ12=σ22\sigma_1^2 = \sigma_2^2) is true.

H0:σ12=σ22H_0 : \sigma_1^2 = \sigma_2^2 against Ha:σ12≠σ22H_a : \sigma_1^2 \neq \sigma_2^2.

It is natural to reject H0H_0 whenever FF is too big or too small,

The decision rule is,

Reject H0 if F∉[Fn1−1,n2−1;1−α/2,Fn1−1,n2−1;α/2].\text{Reject } H_0 \text{ if } F \notin \left[F_{n_1 - 1, n_2 - 1;1 - \alpha/2}, F_{n_1 - 1, n_2 - 1;\alpha/2}\right].

Two-sided CI for σ12σ22\frac{\sigma_1^2}{\sigma_2^2},

P(Fn1−1,n2−1;1−α/2≤S12/σ12S22/σ22≤Fn1−1,n2−1;α/2)=1−α.P\left(F_{n_1 - 1, n_2 - 1;1 - \alpha/2} \leq \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \leq F_{n_1 - 1, n_2 - 1;\alpha/2}\right) = 1 - \alpha.

Which yields us the interval,

[S12S22Fn1−1,n2−1;α/2,S12S22Fn1−1,n2−1;1−α/2]\left[\frac{S_1^2}{S_2^2 F_{n_1 - 1, n_2 - 1;\alpha/2}}, \frac{S_1^2}{S_2^2 F_{n_1 - 1, n_2 - 1;1 - \alpha/2}}\right]

One-sided CI,

[0,S12S22Fn1−1,n2−1;1−α],[S12S22Fn1−1,n2−1;α,+∞).\left[0, \frac{S_1^2}{S_2^2 F_{n_1 - 1, n_2 - 1;1 - \alpha}}\right], \quad \left[\frac{S_1^2}{S_2^2 F_{n_1 - 1, n_2 - 1;\alpha}}, +\infty\right).

One-sided test,

For Ha:σ12>σ22, reject H0 if F>Fn1−1,n2−1;α,For Ha:σ12<σ22, reject H0 if F<Fn1−1,n2−1;1−α.\begin{align*} & \text{For } H_a : \sigma_1^2 > \sigma_2^2, \text{ reject } H_0 \text{ if } F > F_{n_1 - 1, n_2 - 1;\alpha}, \newline & \text{For } H_a : \sigma_1^2 < \sigma_2^2, \text{ reject } H_0 \text{ if } F < F_{n_1 - 1, n_2 - 1;1 - \alpha}. \end{align*}

The pp-value is,

P(F>f)=1−P(F(n1−1,n2−1)≤f),P(F<f)=P(F(n1−1,n2−1)≤f).P(F > f) = 1 - P(F(n_1 - 1, n_2 - 1) \leq f), \quad P(F < f) = P(F(n_1 - 1, n_2 - 1) \leq f).

Search

Essays, lecture notes, and research

Type to search the site.