33. Hypothesis Testing

(and how Confidence Intervals relate)

Confidence Intervals

A Confidence Interval provides a range of values that are plausible for the parameter, based on the sample statistic.

  • Confidence Level - the proportion of the time the interval is expected to contain the parameter (usually 95%)

  • When the CLT applies, you can compute a 95% CI as:

\[\overline X \pm \underset{\text{margin of error}}{\underbrace{1.96 \cdot \text{SE}[\overline X]}}\]

using \(\text{SE}[\overline X] = \sqrt{\frac{\overline X (1-\overline X)}{N}}\) if \(X\) is discrete and \(\text{SE}[\overline X] = \frac{\text{SD}[X]}{\sqrt{N}}\) if \(X\) is continuous.


(This is what the margin of error in a poll is actually used for)

Comparing to the Population

Often, we want to know if our sample is different from the population.

That is, could our sample value have arisen by chance, if the population value is \(p\)?

For instance -

  • Does the lightbulb we manufacture last longer than competitors?

  • Does the medication we created work better than existing drugs?

A standard normal density is shown in blue with an orange vertical line near 2.25. The legend says the blue line is the population distribution and the orange line shows the sample mean. The title reads "Did this happen by chance?".

We can establish the rarity of the observed sample mean under \(H_0\)

Comparing to the Population

Often, we want to know if our sample is different from what we believe about the population.

That is, could our sample value have arisen by chance, if the population value is \(p\)?

For instance -

  • Does the lightbulb we manufacture last longer than competitors?

  • Does the medication we created work better than existing drugs?

A standard normal density is shown in blue with an orange vertical line near 2.25. The legend says the blue line is the population distribution and the orange line shows the sample mean. The area to the right of the orange line is shaded, and text says P(X > Observed) = 0.012, It's not likely. The title reads "Did this happen by chance?".

This is called Hypothesis Testing

Example: Testing to Failure

Foldable smartphones are tested to survive around 200,000 folds.

Quality Assurance for SamSing phones takes a sample of 30 Andromeda phones from the production line and tests the foldable screen to failure.

The average number of times the phones could be opened and closed before they failed was 179,423.3, and the standard deviation of the number of times a phone could be opened and closed was 11,427.

What is the:

  • statistic? \(\overline X = 179423.3\)
  • parameter? \(\mu = 200000\)

What type of variable is \(X\)? continuous

Does the CLT hold for this example? yes. \(N = 30\) and the variable is continuous.

Example: Testing to Failure

Foldable smartphones are tested to survive around 200,000 folds.

Quality Assurance for SamSing phones takes a sample of 30 Andromeda phones from the production line and tests the foldable screen to failure.

The average number of times the phones could be opened and closed before they failed was 179,423.3, and the standard deviation of the number of times a phone could be opened and closed was 11,427.

Confidence Interval

\[\begin{align}\phantom{=}&\overline X \pm \text{Multiplier}\cdot \text{SE}[\overline X]\\=&179423.3 \pm 1.96 \cdot 11427/\sqrt{30} \\=&179423.3 \pm 1.96 \cdot 2086.275 \\=& 179423.3 \pm 4089.099 \\=& (175334.2, 183512.4)\end{align}\]

200,000 is not in the 95% confidence interval

\(\Rightarrow\) 200,000 is not a plausible value, according to our data

\(\Rightarrow\) It’s not plausible that our data originate from a population with \(\mu=200,000\)

Example: Testing to Failure

Foldable smartphones are tested to survive around 200,000 folds.

Quality Assurance for SamSing phones takes a sample of 30 Andromeda phones from the production line and tests the foldable screen to failure.

The average number of times the phones could be opened and closed before they failed was 179,423.3, and the standard deviation of the number of times a phone could be opened and closed was 11,427.

Confidence Interval Interpretation

Statistics terminology and contextual information are both important here!

We are 95% confident that SamSing Andromeda phones can be opened between 175334 and 183512 times, on average, before failure.

As the industry standard of 200,000 open/close operations is outside of the 95% confidence interval, we can conclude that Andromeda phones are significantly less durable than the industry standard.

Example: Testing to Failure

Foldable smartphones are tested to survive around 200,000 folds.

Quality Assurance for SamSing phones takes a sample of 30 Andromeda phones from the production line and tests the foldable screen to failure.

The average number of times the phones could be opened and closed before they failed was 179,423.3, and the standard deviation of the number of times a phone could be opened and closed was 11,427.

Hypothesis Test

\(H_0:\) \(\mu = 200,000\) and \(H_A:\) \(\mu \neq 200,000\)

\(Z^\ast = \frac{179423.3 - 200000}{11427/\sqrt{30}} = -9.8628886\)

\(Z^\ast\) is negative, so we want the lower tail, and then we multiply by 2 to add the upper tail in.

pnorm((179423.3 - 200000)/(11427/sqrt(30)))
pnorm((179423.3 - 200000)/(11427/sqrt(30))) * 2
1
\(P(\overline X \leq Z^\ast)\)
2
\(P(\overline X \leq Z^\ast) + P(\overline X \geq -Z^\ast)\)
[1] 3.014476e-23
[1] 6.028952e-23

Example: Testing to Failure

Foldable smartphones are tested to survive around 200,000 folds.

Quality Assurance for SamSing phones takes a sample of 30 Andromeda phones from the production line and tests the foldable screen to failure.

The average number of times the phones could be opened and closed before they failed was 179,423.3, and the standard deviation of the number of times a phone could be opened and closed was 11,427.

Hypothesis Test Interpretation

Statistics terminology and contextual information are both important here!

We reject \(H_0:\) \(\mu=200,000\) (\(p<0.0001\)) and conclude that it is more likely that \(\mu \neq 200,000\) than it is that we would observe a result as or more extreme than an average of 179,423.3 open/close cycles before screen failure when \(\mu=200,000\) SamSing Andromeda phones can be opened

As the industry standard of 200,000 open/close operations is not plausible based on the data we observed, we can conclude that Andromeda phones are significantly less durable than the industry standard.

Example: Smoking Cessation

Only about 20% of people who try to quit smoking succeed.

A motivational audiobook claims that listening to the book can help people quit. After surveying people who have attempted quitting using the audiobook, 62 out of 250 people were successful at quitting.

What is the:

  • statistic? \(\overline X = 62/250 = 0.248\)

  • parameter? \(p = 0.20\)

  • standard error? \(\sqrt{\frac{0.248 (1-0.248)}{250}} = 0.0273127\)

What type of variable is \(X\)? discrete

Does the CLT hold for this example? yes. \(N*\overline X = 62 > 5\), \(N*(1-\overline X) = 188 > 5\) and the variable is discrete.

Example: Smoking Cessation

Only about 20% of people who try to quit smoking succeed.

A motivational audiobook claims that listening to the book can help people quit. After surveying people who have attempted quitting using the audiobook, 62 out of 250 people were successful at quitting.

Hypothesis Test

\(H_0:\) \(\pi = 0.20\) and \(H_A:\) \(\pi > 0.20\)

\(Z^\ast =\) \(\displaystyle \frac{.248 - .2}{\sqrt{\frac{.2\cdot .8}{250}}} = 1.8973666\)

A quick sketch of the normal distribution with $Z^\ast$

\(Z^\ast\) is positive, so we want the upper tail, and then we multiply by 2 to add the upper tail in.

pnorm((.248-.2)/sqrt((.2*.8/250)), lower.tail = F)
pnorm((.248-.2)/sqrt((.2*.8/250)), lower.tail = F) * 2
1
\(P(\overline X \geq Z^\ast)\)
2
\(P(\overline X \geq Z^\ast) + P(\overline X \leq -Z^\ast)\)
[1] 0.02888979
[1] 0.05777957

Example: Smoking Cessation

Only about 20% of people who try to quit smoking succeed.

A motivational audiobook claims that listening to the book can help people quit. After surveying people who have attempted quitting using the audiobook, 62 out of 250 people were successful at quitting.

Hypothesis Test Interpretation

Statistics terminology and contextual information are both important here!

We fail to reject \(H_0:\) \(\pi=0.2\) (\(p=0.0578\)). It is plausible that we could observe the sample statistic under \(H_0\). There is no evidence that there is a significant difference between the success rate of people who try the motivational audiobook and people who try to quit smoking more generally.