0% found this document useful (0 votes)
65 views57 pages

IE2152 Statistics For Industrial Engineers Problem Solving Sessions

This document discusses hypothesis testing concepts including: - The null and alternative hypotheses for testing whether the mean burning rate of a propellant is equal to the specified rate of 50 cm/s. - How to calculate the test statistic, critical values, probability of Type I and Type II errors, and p-values. - Examples are provided to demonstrate applying the hypothesis testing procedure and interpreting the results, including calculating the power of tests.

Uploaded by

Kutay Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views57 pages

IE2152 Statistics For Industrial Engineers Problem Solving Sessions

This document discusses hypothesis testing concepts including: - The null and alternative hypotheses for testing whether the mean burning rate of a propellant is equal to the specified rate of 50 cm/s. - How to calculate the test statistic, critical values, probability of Type I and Type II errors, and p-values. - Examples are provided to demonstrate applying the hypothesis testing procedure and interpreting the results, including calculating the power of tests.

Uploaded by

Kutay Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

IE2152

Statistics for Industrial Engineers


Problem Solving Sessions
Session 05 – Hypothesis Testing
Hypothesis Testing
• A statistical hypothesis is a statement about the parameters of
one or more populations.
• Let H0 : μ = 50 centimeters per second and H1 : μ ≠ 50
centimeters per second
• The statement H0 : μ = 50 is called the null hypothesis.
• The statement H1 : μ ≠ 50 is called the alternative hypothesis.

• One-sided Alternative Hypotheses

H0 : μ = 50 centimeters per second H0 : μ = 50 centimeters per second


or
H1 : μ < 50 centimeters per second H1 : μ > 50 centimeters per second 2
Test of a Hypothesis
• A procedure leading to a decision about a particular
hypothesis
• Hypothesis-testing procedures rely on using the information in
a random sample from the population of interest.
• If this information is consistent with the hypothesis, then we will
conclude that the hypothesis is true;
• if this information is inconsistent with the hypothesis, we will
conclude that the hypothesis is false.
• H0 : μ = 50 centimeters per second
• H1 : μ ≠ 50 centimeters per second

3
Decisions in Hypothesis
Testing

Probability of Type I and Type II Error

 = P(type I error) = P(reject H0 when H0 is true)


β = P(type II error) = P(fail to reject H0 when H0 is false)

• Sometimes the type I error probability is called the significance 4


level, or the -error, or the size of the test.
Computing the Probability of
Type I Error
• Suppose that s = 2.5 and applying CLT, the distribution of the
sample mean is approximately normal with mean m = 50 and
standard deviation = 0.79.
• The z-values that correspond to the critical values 48.5 and 51.5
are

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

• In formulating one-sided alternative hypotheses, one should


remember that rejecting H0 is always a strong conclusion.
• Consequently, we should put the statement about which it is 8
important to make a strong conclusion in the alternative
hypothesis.
Connection between Hypothesis
Tests and Confidence Intervals
• A close relationship exists between the test of a hypothesis for
, and the confidence interval for .
• If [l, u] is a 100(1  ) confidence interval for the parameter
, the test of size  of the hypothesis

H0:   0
H1:   0

• will lead to rejection of H0 if and only if 0 is not in the 100(1 


) CI [l, u].

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

• The test statistic is:

Alternative hypothesis Rejection criteria


H1:  ≠ 0 z0 > z/2 or z0 < -z/2
H1:  > 0 z0 > z 11
H1:  < 0 z0 < -z
Ex. 9-2 Propellant Burning Rate
• Air crew escape systems are powered by a solid propellant. The
burning rate of this propellant is an important product
characteristic.
• Specifications require that the mean burning rate must be 50
centimeters per second and the standard deviation is   2
centimeters per second.
• The significance level of   0.05 and a random sample of n=
25 has a sample average burning rate of centimeters per second.
Draw conclusions.

• The eight-step hypothesis testing procedure is

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:

> #Define problem data


> n<-25 #sample size
> mu0<-50 #hypothesized value
> sigma<-2 #population standard deviation
> xbar<-51.3 #sample mean
> alpha<-0.05 #significance level
> #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] 3.25
>
> #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 = 50 is rejected at 0.05 significance level"
14
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')

Hypothesis testing (two.sided) for H0

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:

• Hence, the distribution of Z0 when H1 is true is .


• The probability of the type II error is the probability that Z0 falls
between -z/2 and z/2 given that H1 is true.

20
Finding the Probability of
Type II Error 
• For a two-sided alternative

• If the alternative is m < m0

• If the alternative is m > m0

where 21
Type II Error and Choice of
Sample Size
• For a two-sided alternative hypothesis:

• For a one-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

Mean power calculation for normal distribution with known variance

d = 0.5
n = 25
sig.level = 0.05
power = 0.705418
alternative = two.sided

> power <- pwrNorm$power; power


[1] 0.705418
> beta <- 1-power; beta
[1] 0.294582

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'))

Distributions underH0andH1 Mean power calculation for normal distribution


with known variance
0.4

Ty pe I error 100% tails = two.sided


Ty pe II error
effect size d = 0.5
alpha = 0.05
0.3

75%

test power = 1 - 
density

0.2

50%
0.1

25%

optimal sample size


0.0

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

Mean power calculation for normal distribution with known variance

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)

Mean power calculation for normal distribution


with known variance
100%
tails = two.sided
effect size d = 0.5
alpha = 0.05

75%
test power = 1 - 

50%

25%

optimal sample size


n = 43
32
0%

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:

> #Define problem data


> n<-100 #sample size
> mu0<-480 #hypothesized value
> sigma<-25 #population standard deviation
> xbar<-470 #sample mean
> alpha<-0.05 #significance level
>
> #Calculate the critical value at 0.05 significance level
> zc<-qnorm(alpha); zc
[1] -1.644854
>
> #Calculate the test statistic Z0:
> z0<-(xbar-mu0)/(sigma/sqrt(n)); z0
[1] -4
>
> #Use our test.critical function to give the decision
> testmean.cv(zc,z0,mu0,alpha,alt="less",theta="mu")
[1] "H0: mu = 480 is rejected at 0.05 significance level"
35
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

> #For manual calculation, calculate the p-value


> pval<-pnorm(z0); pval
[1] 3.167124e-05
>
> #Use our test.pval function to give the decision 36
> test.pval(pval,mu0,alpha,theta="mu")
[1] "H0: mu = 480 is rejected at 0.05 significance level"
Review Example 1
• RStudio output:
> plotmean.hypothesis(z0,zc,n,type='z',alt='less')

Hypothesis testing (less) for H0

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:

> #Define problem data


> n<-400 #sample size
> mu0<-170 #hypothesized value
> sigma<-65 #population standard deviation
> xbar<-178 #sample mean
> alpha<-0.05 #significance level
>
> #Calculate the critical value at 0.05 significance level
> zc<-qnorm(1-alpha)
>
> #Calculate the test statistic Z0:
> z0<-(xbar-mu0)/(sigma/sqrt(n)); z0
[1] 2.461538
>
> #Use our test.critical function to give the decision
> testmean.cv(zc,z0,mu0,alpha,alt="greater",theta="mu")
[1] "H0: mu = 170 is rejected at 0.05 significance level"

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

> #Or, we can manually calculate the p-value


> pval<-1-pnorm(z0); pval
[1] 0.006917128
>
> #Use our test.pval function to give the decision
> test.pval(pval,mu0,alpha,theta="mu")
[1] "H0: mu = 170 is rejected at 0.05 significance level« 42
> #What happens if significance level is 0.001?
> test.pval(pval,mu0,0.001,theta="mu")
[1] "H0: mu = 170 is not rejected at 0.001 significance level"
Review Example 2
• RStudio output:
> plotmean.hypothesis(z0,zc,n,type='z',alt='greater')

Hypothesis testing (greater) for H0

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:

> #Calculate power of the test with pwr.norm.test function:


> mu <- 172
> delta <- mu-mu0; delta
[1] 2
> pwrNorm <- pwr.norm.test(delta/sigma,n,alpha,power=NULL,alt='greater'); pwrNorm

Mean power calculation for normal distribution with known variance

d = 0.03076923
n = 400
sig.level = 0.05
power = 0.1516297
alternative = greater

> beta <- 1-pwrNorm$power; beta


[1] 0.8483703
> power <- 1-beta; power
[1] 0.1516297
45
Review Example 2
• RStudio output:
> #For manual calculation, find the standard error of the mean, zalpha
> #and compute the type II error and power of the test:
> sem<-sigma/sqrt(n); sem
[1] 3.25
> beta <- pnorm(zc-delta/sem); beta
[1] 0.8483703
> power<-1-beta; power
[1] 0.1516297
>
> #Another approach is to compute the upper bound of sample means
> #for which the null hypothesis mu = 170 would not be rejected.
> q <- qnorm(1-alpha, mean=mu0, sd=sem); q
[1] 175.3458
>
> #Therefore, so long as the sample mean is less than
> #the upper bound in the hypothesis test, the null hypothesis will not be rejected.
> #Since we assume that the actual population mean is 172, we can compute
> #the upper tail probability, which gives the probability of type II error.
> beta <- pnorm(q, mean=mu, sd=sem); beta
[1] 0.8483703
> 46
> #The power of the hypothesis test is as follows:
> power<-1-beta; power
[1] 0.1516297
Review Example 2
• RStudio output:
> plotmean.beta(sigma,zc,delta,n,type='z',alt='greater')

Distributions underH0andH1
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

Mean power calculation for normal distribution with known variance

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')

Mean power calculation for normal distribution


with known variance Distributions underH0andH1
100% tails = 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%

optimal sample size


0.0

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.

• Test the null hypothesis against the two-sided alternative at a=0.05


significance level. 51
Review Example 3
• 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: 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')

Hypothesis testing (two.sided) for H0

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

You might also like