13.10. Statistical Power Practice Problems#

# load libraries
import scipy.stats as stats
import numpy as np
import math
import matplotlib.pyplot as plt

13.10.1. Learning Objectives#

After studying this notebook, completing the activities, participating in class, and reviewing your notes, should be able to:

  • Formulate null and alternative hypotheses from a problem description

  • Draw conclusions by interpreting a calculated P-value

  • Explain Type I and Type II errors in the context of an application

  • Predict Type I and Type II error rates (including statistical power calculations)

  • Calculate minimum sample size based on Type I and Type II error rate specifications

13.10.2. Practice Problems#

Note

Class Breakout 1: In a breakout room, brainstorm how to start Practice Problem A on paper. Make a list of questions to ask when we regroup as a class.

13.10.3. Practice Problem A: Probability of Errors in Hypothesis Testing#

Reference: Problem 2 in §6.13 of Navidi (2015).

A test has power 0.80 assume the alternative mean \(\mu = 3.5\). True or false:

  1. The probability of rejecting \(H_0\) when \(\mu=3.5\) is 0.80.

  2. The probability of making a Type I error when \(\mu=3.5\) is 0.80.

  3. The probability of making a Type I error when \(\mu=3.5\) is 0.20.

  4. The probability of making a Type II error when \(\mu=3.5\) is 0.80.

  5. The probability of making a Type II error when \(\mu=3.5\) is 0.20.

  6. The probability that \(H_0\) is false when \(\mu=3.5\) is 0.80.

Note

Class Breakout 2: In a breakout room, brainstorm how to start Practice Problem B on paper. Make a list of questions to ask when we regroup as a class.

13.10.4. Practice Problem B: Conceptual Understanding#

Reference: Problem 2 in §6.12 of Navidi (2015).

A process for a certain type of ore is designed to reduce the concentration of impurities to less than 2%. It is known that the standard deviation of imputities for processed ore is 0.6%. Let \(\mu\) represent the mean impurity level, in percent, for ore specimens treated by this process. The impurity of 80 ore specimens is measured, and a test of the hypothesis \(H_0: ~\mu \geq\) 2 versus \(H_a:~ \mu\) < 2 will be performed.

  1. If the test is made at the 5% level, what is the rejection region?

  2. If the sample mean impurity concentration is 1.85, will \(H_0\) be rejected at the 10% level?

  3. If the same mean impurity concentration is 1.85, will \(H_0\) be rejected at the 1% level?

  4. If the value 1.9 is a critical point (i.e., the value of the test statistic that produces a P-value equal to \(\alpha\)), what is the level of the test?

Note: During class, you should write down all of the paper and pencil work we do together. In the cells below, we are just using Python as a calculator.

# given data
# Add your solution here
# Part 1
alpha = 0.05

# Step 1: calculate the normalized critical point (z)
# hint: ppf is the inverse cdf
# Add your solution here

# Step 2: translate the normalize critical point to the sample mean (X)
# Add your solution here
zcrit =  -1.6448536269514729
xcrit =  1.8896598643129827
# Part 2

# Strategy: repeat the previous calculation with a new alpha
alpha = 0.1

# Step 1: calculate the normalized critical point (z)
# hint: ppf is the inverse cdf
# Add your solution here

# Step 2: translate the normalize critical point to the sample mean (X)
# Add your solution here
zcrit =  -1.2815515655446004
xcrit =  1.9140309074831299
# Part 3

# Strategy: repeat the previous calculation with a new alpha
alpha = 0.01

# Step 1: calculate the normalized critical point (z)
# hint: ppf is the inverse cdf
# Add your solution here

# Step 2: translate the normalize critical point to the sample mean (X)
# Add your solution here
zcrit =  -2.3263478740408408
xcrit =  1.8439438404299768
# Part 4

# Given: critical point for sample mean
xcrit = 1.9

# Step 1: calculate normalized critical point
# Add your solution here

# Step 2: look up probability
# Add your solution here
zcrit = -1.4907119849998614
level = 0.06801856405707159

Note

Class Breakout 3: In a breakout room, brainstorm how to start Practice Problem C on paper. Make a list of questions to ask when we regroup as a class.

13.10.5. Practice Problem C: Statistical Power Calculations#

Reference: Problem 6 in §6.13 of Navidi (2015).

Note: During class, you should write down all of the paper and pencil work we do together. In the cells below, we are just using Python as a calculator.

13.10.5.1. Given Data#

A copper smelting process is supposed to reduce the arsenic concent of the copper to less than 1000 ppm. Let \(\mu\) denote the mean arsenic content for copper treated by this process, and assume that the standard deviation of arsenic content is \(\sigma\) = 100 ppm. The sample mean arsenic content \(\bar{X}\) of 75 copper specimens will computed, and the null hypothesis \(H_{0}:~ \mu \geq\) 1000 ppm will be tested against the alternative \(H_a:~ \mu\) < 1000 ppm.

# Add your solution here

13.10.5.2. Part 1#

A decision is made to reject \(H_0\) is \(\bar{X} \leq 980\). Find the level (\(\alpha\)) of this test.

# Given: critical point for sample mean
xcrit = 980

# Step 1: calculate normalized critical point
# Add your solution here

# Step 2: look up probability (level)
# Add your solution here
zcrit = -1.7320508075688774
level = 0.0416322583317752

13.10.5.3. Part 2#

Find the power of the test in part (1) if the true mean content is 965 ppm.

# Assumption: true mean
mua = 965 # ppm

# Step 1: draw a picture!!!

# Step 2: calculate za, i.e., the location of the critical point on the alternate distribution
# Add your solution here

# Step 3: calculate probability
# Add your solution here
za = 1.299038105676658
power = 0.9030345738587946

13.10.5.4. Part 3#

For what values of \(\bar{X}\) should \(H_0\) be rejected so that the power of the test will be 0.95 when the true mean content is 965 ppm?

# Step 1: calculate za corresponding with 95% power
# Add your solution here

# Step 2: translate za to the critical point
# Add your solution here
za = 1.6448536269514722
xcrit = 983.9931336859593

13.10.5.5. Part 4#

For what values of \(\bar{X}\) should \(H_0\) be rejected so that the level of the test (\(\alpha\)) will be 5%?

level = 0.05

# Step 1: Calculate z0 (zcrit) from the level
# Add your solution here

# Step 2: Convert z0 to xcrit (x0)
# Add your solution here
zcrit = z0 = -1.6448536269514729
xcrit = x0 = 981.0068663140407

13.10.5.6. Part 5#

What is the power of a 5% level test if the true mean content is 965 ppm?

# Step 1: Convert x0 (critical point) to za on alternate distribution
# Add your solution here

# Step 2: Convert za to power
# Add your solution here
za = 1.3862352862940657
power = 0.9171624649939363

13.10.5.7. Part 6#

How large a sample is needed so that a 5% level test has power 0.95 when the true mean content is 965 ppm?

# Given: level, power
level = 0.05
power = 0.95

# Step 1: compute z0 from level
# Add your solution here

# Step 2: compute za from power
# Add your solution here

# Step 3: solve for n
# Add your solution here
z0 = -1.6448536269514729
za = 1.6448536269514722
n = 88.34427605209513