IE2152 Statistics For Industrial Engineers Problem Solving Sessions
IE2152 Statistics For Industrial Engineers Problem Solving Sessions
3
Decisions in Hypothesis
Testing
and
• Therefore,
5
• which implies 5.74% of all random samples would lead to
rejection of the hypothesis H0: μ = 50.
Computing the Probability of
Type II Error
• The z-values corresponding to 48.5 and 51.5 when 52 are
and
• Hence,
• which means that the probability that we will fail to reject the 6
false null hypothesis is 0.2643.
The Power of a Statistical Test
• The power of a statistical test is the probability of rejecting the
null hypothesis H0 when the alternative hypothesis is true.
• The power is computed as 1 - β, and power can be interpreted
as the probability of correctly rejecting a false null hypothesis.
• For example, consider the propellant burning rate problem
when we are testing H0 : μ = 50 centimeters per second
against H1 : μ not equal 50 centimeters per second.
• Suppose that the true value of the mean is μ = 52.
• When n = 10, we found that β = 0.2643, so the power of this
test is
7
1 – β = 1 - 0.2643 = 0.7357
One-Sided and Two-Sided
Hypotheses
• Two-Sided Test:
H0: 0
H1: ≠ 0
• One-Sided Tests:
H0: 0 H0: 0
H1: > 0 or H1: < 0
H0: 0
H1: 0
9
General Procedure for
Hypothesis Tests
1. Identify the parameter of interest.
2. Formulate the null hypothesis, H0.
3. Specify an appropriate alternative hypothesis, H1.
4. Choose a significance level, .
5. Determine an appropriate test statistic.
6. State the rejection criteria for the statistic.
7. Compute necessary sample quantities for calculating the
test statistic.
8. Draw appropriate conclusions.
10
Tests on the Mean of a Normal
Distribution, Variance Known
• One-Sample z-Test
• Consider the two-sided hypothesis test
H0: 0
H1: ≠ 0
1. Parameter of interest:
12
2. Null hypothesis:
3. Alternative hypothesis:
Ex. 9-2 Propellant Burning Rate
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion:
13
Interpretation:
Ex. 9-2 Propellant Burning Rate
• RStudio output:
> #We can use the zsum.test() function from the BSDA package
> #to test the null hypothesis H0=50 against the two-sided alternative.
> require(BSDA)
> zsum.test(mean.x=xbar,
sigma.x=sigma,
n.x=n,
alt='two.sided’,
mu=mu0,
conf.level=0.95)
One-sample z-Test
data: Summarized x
z = 3.25, p-value = 0.001154
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
50.51601 52.08399
sample estimates:
mean of x
51.3
15
P-Values in Hypothesis Tests
• The P-value is the smallest level of significance that would lead to
rejection of the null hypothesis H0 with the given data. P-value is the
observed significance level.
• Consider the two-sided hypothesis test H0: 50 against H1: 50
with n =16 and 2.5. Suppose that the observed sample mean is
centimeters per second.
• The P-value of the test is the associated with the critical region.
Any smaller value for expands the critical region and the test fails
to reject the null hypothesis when .
16
Ex. 9-2 Propellant Burning
Rate
• Using the p-value approach for Ex. 9-2:
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion: 17
Interpretation:
Ex. 9-2 Propellant Burning Rate
• RStudio output:
> #Manually calculate the p-value
> pval<-2*(1-pnorm(z0)); pval
[1] 0.00115405
>
> #Compare the p-value with the significance level, and make a decision.
> test.pval(pval,mu0,alpha,theta="mu")
[1] "H0: mu = 50 is rejected at 0.05 significance level"
>
> #Also, zsum.test() function calculates the p-value for the hypothesis test.
> zsum.test(mean.x=xbar,
sigma.x=sigma,
n.x=n,
alt='two.sided', mu=mu0,conf.level=0.95)$p.val
[1] 0.00115405
18
Ex. 9-2 Propellant Burning Rate
• RStudio output:
> #We can use our plotmean.hypothesis function with the required parameters:
> plotmean.hypothesis(z0,zc,type='z',alt='two.sided')
19
-4 -2 0 2 4
z0=3.25<-->zc =1.96
Finding the Probability of
Type II Error
• Consider the two-sided hypothesis test H0: 0 and H1: 0.
• Suppose the null hypothesis is false and the true value of the mean
is 0 , where 0.
• The test statistic Z0 is:
20
Finding the Probability of
Type II Error
• For a two-sided alternative
where 21
Type II Error and Choice of
Sample Size
• For a two-sided alternative hypothesis:
22
Ex. 9-3 Propellant Burning Rate
• Consider the rocket propellant problem of Example 9-2. The
true burning rate is 49 centimeters per second. Find for the
two-sided test with 0.05, 2, and n = 25.
• Interpretation:
23
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> mu0<-50
> n<-25
> sigma<-2
> sem<-sigma/sqrt(n); sem
[1] 0.4
> mu <- 49
> delta <- mu-mu0; delta
[1] -1
> alpha <- .05
>
> #Calculate zalpha/2 and compute the type II error and power of the test by hand:
> z_halfalpha <- qnorm(c(alpha/2,1-alpha/2)); z_halfalpha
[1] -1.959964 1.959964
> beta <- diff(pnorm(z_halfalpha-delta/sem)); beta
[1] 0.294582
> power<-1-beta; power
[1] 0.705418
24
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> #Using the pwr.norm.test function we can find the power of the test:
> require('pwr')
> pwrNorm <- pwr.norm.test(delta/sigma,n,alpha,power=NULL,alt='two.sided'); pwrNorm
d = 0.5
n = 25
sig.level = 0.05
power = 0.705418
alternative = two.sided
25
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> #Another approach is to compute the lower and upper bounds of sample means
> #for which the null hypothesis mu = 50 would not be rejected.
> I <- c(alpha/2, 1-alpha/2)
> q <- qnorm(I, mean=mu0, sd=sem); q
[1] 49.21601 50.78399
>
> #Therefore, so long as the sample mean is between the bounds
> #in a hypothesis test, the null hypothesis will not be rejected.
> #Since we assume that the actual population mean is 49, we can
> #compute the lower tail probabilities of both end points.
> mu <- 49
> p <- pnorm(q, mean=mu, sd=sem); p
[1] 0.7054139 0.9999959
>
> #Finally, the probability of type II error is
> #the probability between the two end points.
> beta<-diff(p); beta # p93[2]-p93[1]
[1] 0.294582
>
> #The power of the hypothesis test is as follows: 26
> power<-1-diff(p); power
[1] 0.705418
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> plotmean.beta(sigma,z_halfalpha[2],delta,n,type='z',alt='two.sided’)
> plot(pwr.norm.test(delta/sigma,n,0.05,power=NULL,alt='two.sided'))
75%
test power = 1 -
density
0.2
50%
0.1
25%
n = 25
0% 27
-4 -2 0 2 4 10 20 30 40 50
sample size
z
Ex. 9-3 Propellant Burning
Rate
• Suppose that the analyst wishes to design the test so that if
the true mean burning rate differs from 50 centimeters per
second by as much as 1 centimeter per second, the test will
detect this (i.e., reject H0: 50) with a high probability, say,
0.90.
• What is the required sample size?
28
Ex. 9-3 Propellant Burning
Rate
• Interpretation:
29
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> #In the second part, we need to determine the required sample size
> #The parameters beta, mu, and delta zalpha∕2 and zbeta are determined.
> beta<-0.10
> mu<-51
> delta<-mu-mu0; delta
[1] 1
> #We can apply pwr.norm.test function in order to find the required sample size:
> pwrNorm <- pwr.norm.test(delta/sigma,
n=NULL,alpha,power=1-beta,alt='two.sided'); pwrNorm
d = 0.5
n = 42.02968
sig.level = 0.05
power = 0.9
alternative = two.sided
> ceiling(pwrNorm$n)
[1] 43
30
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> #For manual calculation, the parameters zalpha/2 and zbeta are determined.
> z_halfalpha<-qnorm(1-alpha/2); z_halfalpha
[1] 1.959964
> z_beta<-qnorm(1-beta); z_beta
[1] 1.281552
>
> #The required sample size is calculated.
> nreq<-((z_halfalpha+z_beta)*sigma/(mu-mu0))^2; nreq
[1] 42.02969
>
> #We can also use uniroot function to find the required sample size.
> fnc<-function(alpha,beta,delta,n,sd){
+ beta-diff(pnorm(c(qnorm(alpha/2),qnorm(1-alpha/2))-delta*sqrt(n)/sd))
+ }
> nreq<-uniroot(fnc,c(2, 1000),alpha=alpha,beta=beta,delta=delta,sd=sigma)$root; nreq
[1] 42.02968
> ceiling(nreq)
[1] 43
>
> #The upper tail and lower tail probabilities are calculated below:
> pnorm(z_halfalpha-(mu-mu0)*sqrt(nreq)/sigma) 31
[1] 0.1000001
> pnorm(-z_halfalpha-(mu-mu0)*sqrt(nreq)/sigma)
[1] 9.885442e-08
Ex. 9-3 Propellant Burning Rate
• RStudio output:
> plot(pwrNorm)
75%
test power = 1 -
50%
25%
20 40 60
sample size
Review Example 1
• A quality control engineer finds that a sample of 100 light
bulbs had an average life-time of 470 hours.
• Assuming a population standard deviation of σ = 25
hours, test whether the population mean is 480 hours vs.
the alternative hypothesis µ < 480 at a significance level
of α = 0.05.
• The eight-step hypothesis testing procedure is
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
33
Review Example 1
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion:
34
Interpretation:
Review Example 1
• RStudio output:
> #We can use the zsum.test() function to test the null hypothesis.
> zsum.test(mean.x=xbar, sigma.x=sigma, n.x=n, alt='less', mu=mu0,conf.level=0.95)
One-sample z-Test
data: Summarized x
z = -4, p-value = 3.167e-05
alternative hypothesis: true mean is less than 480
95 percent confidence interval:
NA 474.1121
sample estimates:
mean of x
470
37
-4 -2 0 2 4
z0=-4<-->zc=-1.64
Review Example 2
• The manager of a department store is interested in the cost
effectiveness of establishing a new billing system for the
store’s credit customers. After a careful analysis, she
determines that the new system is justified only if the mean
monthly account size is more than $170 . The manager wishes
to find out if there is sufficient statistical support for this.
• The manager takes a random sample of 400 monthly accounts.
The sample mean turns out to be $178. Historical data
indicate that the standard deviation of monthly accounts is
about $65.
• Test the null hypothesis against the one-sided alternative at
a=0.05 significance level.
38
Review Example 2
• Using the critical value approach:
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion: 39
Interpretation:
Review Example 2
• Using the p-value approach:
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion: 40
Interpretation:
Review Example 2
• RStudio output:
41
Review Example 2
• RStudio output:
> #We can use the zsum.test() function to test the null hypothesis.
> zsum.test(mean.x=xbar, sigma.x=sigma, n.x=n, alt='greater', mu=mu0,conf.level=0.95)
One-sample z-Test
data: Summarized x
z = 2.4615, p-value = 0.006917
alternative hypothesis: true mean is greater than 170
95 percent confidence interval:
172.6542 NA
sample estimates:
mean of x
178
43
-4 -2 0 2 4
z0=2.46<-->zc =1.64
Review Example 2
• What is the type II error and the power of the test when true
mean monthly account size is $172?
44
Review Example 2
• RStudio output:
d = 0.03076923
n = 400
sig.level = 0.05
power = 0.1516297
alternative = greater
Distributions underH0andH1
0.4
Ty pe I error
Ty pe II error
0.3
density
0.2
0.1
0.0
47
-4 -2 0 2 4
z
Review Example 2
• Suppose that the sample size n is increased to 5000. What is
the power of the test?
48
Review Example 2
• RStudio output:
> n<-5000
> pwrNorm <- pwr.norm.test(delta/sigma,n,alpha,power=NULL,alt='greater'); pwrNorm
d = 0.03076923
n = 5000
sig.level = 0.05
power = 0.7022419
alternative = greater
>
> #Manual calculation of type II error and power:
> sem<-sigma/sqrt(n); sem
[1] 0.9192388
> beta <- pnorm(zc-delta/sem); beta
[1] 0.2977581
> power <-1-beta; power
[1] 0.7022419
>
> #Using the alternative approach:
> q <- qnorm(1-alpha, mean=mu0, sd=sem); q
[1] 171.512 49
> beta <- pnorm(q, mean=mu, sd=sem); beta
[1] 0.2977581
> power<-1-beta; power
[1] 0.7022419
Review Example 2
• RStudio output:
> plot(pwrNorm)
> plotmean.beta(sigma,zc,delta,n,type='z',alt='greater')
0.4
effect size d = 0.0307692307692308 Ty pe I error
Ty pe II error
alpha = 0.05
75%
0.3
test power = 1 -
density
50% 0.2
0.1
25%
n = 5000 50
0%
-4 -2 0 2 4
0 2000 4000 6000
sample size z
Review Example 3
• Assume that someone wants to check/verify the height of the U.S.
male population. Currently, the population mean is about 70 inches
with a standard deviation of 3 inches. A total of 30 representative
samples are taken and the height is measured.
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion: 52
Interpretation:
Review Example 3
• Using the p-value approach:
1. Parameter of interest:
2. Null hypothesis:
3. Alternative hypothesis:
4. Significance level:
5. Test statistic:
6. Reject H0 if:
7. Computations:
8. Conclusion: 53
Interpretation:
Review Example 3
• RStudio output:
> #Enter problem data
> height<-c(67, 70, 65, 73, 71, 72, 69, 73, 71, 72, 73, 71, 71, 67, 67,
+ 69, 66, 68, 65, 66, 73, 68, 67, 73, 71, 70, 75, 68, 73, 66)
>
> #Define problem parameters
> n<-length(height); n
[1] 30
> mu0<-70
> sigma<-3
> xbar<-mean(height); xbar
[1] 69.66667
> alpha<-0.05
>
> #Calculate the critical values at 0.05 significance level
> zc<-qnorm(1-alpha/2)
> c(-zc,zc)
[1] -1.959964 1.959964
>
> #Calculate the test statistic Z0:
> z0<-(xbar-mu0)/(sigma/sqrt(n)); z0
[1] -0.6085806 54
>
> #Compare the test statistic with the critical values, and make a decision.
> testmean.cv(zc,z0,mu0,alpha,alt="t",theta="mu")
[1] "H0: mu = 70 is not rejected at 0.05 significance level"
Review Example 3
• RStudio output:
> #We can use the z.test() function from the BSDA package
> #to test the null hypothesis H0=70 against the two-sided alternative.
> z.test(height,alt="t",mu=mu0,sigma.x = sigma,conf.level=0.95)
One-sample z-Test
data: height
z = -0.60858, p-value = 0.5428
alternative hypothesis: true mean is not equal to 70
95 percent confidence interval:
68.59315 70.74018
sample estimates:
mean of x
69.66667
>
> #Manually calculate the p-value
> pval<-2*(pnorm(z0)); pval
[1] 0.5428025
>
> #Compare the p-value with the significance level, and make a decision.
55
> test.pval(pval,mu0,alpha,theta="mu")
[1] "H0: mu = 70 is not rejected at 0.05 significance level"
Review Example 3
• RStudio output:
> plotmean.hypothesis(z0,zc,type='z',alt='two.sided')
56
-4 -2 0 2 4
z0=-0.61<-->zc=1.96
References
• Montgomery, D. C., & Runger, G. C. (2006). Applied statistics
and probability for engineers. 4th Edition. Hoboken, NJ: Wiley.
• http://www.sci.utah.edu/~arpaiva/classes/UT_ece3530/hypot
hesis_testing.pdf
• https://personal.utdallas.edu/~scniu/OPRE-6301/documents/
Hypothesis_Testing.pdf
• https://www.theopeneducator.com/doe/hypothesis-Testing-In
ferential-Statistics-Analysis-of-Variance-ANOVA/Single-Sample-
Z-Test
57