Hypothesis Testing
Hypothesis Testing
UNIT – 2
HYPOTHESIS TESTING
Hypothesis Testing
Introduction Hypothesis
• Hypothesis testing typically begins with some theory, claim, or
assertion about a particular parameter of a population
• These hypothetical statements are tested for their validity by the
information provided by random samples drawn from their
corresponding populations
Hypothesis
• The hypothesis provides a summary of what direction, if any, is
taken to investigate a theory.
• 𝐻0 : The performance of new drug is same as that of old drug i.e., the performance of new drug is not better
than old one etc.,
• Usually, a null hypothesis is expressed with “=” sign and sometimes ‘>=‘ or ‘<=‘.
• The null hypothesis is that the filling process is working properly, and therefore the mean fill is the 368-gram
specification
𝐻0 : 𝜇 = 368
Alternative Hypothesis
• It is a rivalry or complimentary or opposite hypothesis to null
hypothesis and is denoted by 𝐻1 𝑜𝑟 𝐻𝑎 .
• 𝐻1 :The difference in quality of tube- lights among three brands is
significant,
P = 8, N = 4
TP = 6, TN = 3, FP = 1, FN = 2
PP = TP + FP = 7
PN = TN + FN = 5
Estimating Error
Bias is the difference between the average prediction of the
hypothesis and the correct value of prediction.
The hypothesis with high bias tries to oversimplify the training (not
working on a complex model). It tends to have high training errors
and high test errors.
They try to over-complex the model and do not generalize the data very
well.
Confidence Level & Interval
• When an estimate is made for a variable, there is always uncertainty
around that estimate because the number is based on a sample of
the population you are studying.
• The confidence interval is the range of values that the estimate is
expected to fall between, a certain percentage of the time if the
experiment is run again or re-sampled the population in same way.
• The confidence level is the percentage of times that an estimate is
expected to be reproduced between the upper and lower bounds of
the confidence interval, and is set by the alpha value.
The Critical Value of the Test Statistic
• In the Oxford Cereal Company scenario, the null hypothesis is that the mean
amount of cereal per box in the entire filling process is 368 grams
• You select a sample of boxes from the filling process, weigh each box, and
compute the sample mean
• This statistic is an estimate of the corresponding parameter
ത is likely to
• Even if the null hypothesis is true, the statistic (the sample mean, 𝑋)
differ from the value of the parameter
• For example, if the sample mean is 367.9, you conclude that the population mean
has not changed
• if the sample mean is 320, you conclude that the population mean is not 368
• Determining what is very close and what is very different is arbitrary without
clear definitions
Regions of Rejection and Non-rejection
• The sampling distribution of the test statistic is divided into two regions, a
region of rejection (sometimes called the critical region) and a region of
nonrejection
• if a value of the test statistic falls into this rejection region, you reject the
null hypothesis
• If the test statistic falls into the region of non-rejection, you do not reject
the null hypothesis.
Risks in Decision Making Using Hypothesis-
Testing Methodology
• A Type I error occurs if you reject the null hypothesis, 𝐻0 , when it is
true and should not be rejected. The probability of a Type I error
occurring is 𝛼.
• A Type II error occurs if you do not reject the null hypothesis, 𝐻0 ,
when it is false and should be rejected. The probability of a Type II
error occurring is 𝛽.
Confusion Matrix
• P = TP + FN
• N = FP + TN
• PP = TP + FP
• PN = FN + TN
• Error cases: FP, FN
• Type I error: FP
• Type II error: FN
Errors in Hypothesis Testing
•P(Type I error)
• 𝜶 = 𝐏 Rejecting 𝐻0 𝐻0 is true)
•P(Type II error)
• 𝛃 = 𝐏 Accepting 𝐻0 𝐻0 is false)
•Note:
• 𝜶 and 𝛃 are not independent of each other. as one increases, the other
decreases
• When the sample size increases, both to decrease since sampling error is
reduced.
• In general, we focus on Type I error, but Type II error is also important,
particularly when sample size is small.
Type-1 & Type-2 Error
Level of Significance
• level of significance(𝜶)
• control the Type I error by deciding the risk level, 𝛼, that you are willing to
have in rejecting the null hypothesis when it is true
• select levels of 0.01, 0.05, or 0.10
The Confidence Coefficient
• The complement of the probability of a Type I error, (1 - 𝛼),is called
the confidence coefficient
• The confidence coefficient, (1 - 𝛼), is the probability that you will not
reject the null hypothesis, 𝐻0 , when it is true and should not be
rejected. The confidence level of a hypothesis test is (1 - 𝛼) *100%.
The 𝛽 𝑅𝑖𝑠𝑘
• The probability of committing a Type II error is denoted by 𝛽
• the probability of making a Type II error depends on the difference
between the hypothesized and actual values of the population
parameter
• if the difference between the hypothesized and actual values of the
population parameter is large, 𝛽 is small
• if the difference between the hypothesized and actual values of the
parameter is small, 𝛽 is large
The Power of a Test
• The complement of the probability of a Type II error, (1 - 𝛽), is called
the power of a statistical test.
• The power of a statistical test, (1 - 𝛽), is the probability that you will
reject the null hypothesis when it is false and should be rejected.
Risk in Decision Making
• The Table illustrates
Confidence Interval
• Generally, the true error is complex and difficult to calculate. It can be
estimated with the help of a confidence interval. The confidence interval can
be estimated as the function of the sampling error.
• Below are the steps for the confidence interval:
• Randomly drawn n samples S (independently of each other), where n should be >30 from
the population P.
• Calculate the Sample Error of sample S.
• Here we assume that the sampling error is the unbiased estimator of True
Error. Following is the formula for calculating true error:
Example n = 40
Hypothesis h commits r = 12 errors
12
Sample error 𝑒𝑟𝑟𝑜𝑟𝑆 ℎ = = 0.3
40
95% confidence
0.3 ±1.96 ∗ 0.7 = 0.3 ± 0.14
Confidence Intervals
• With 95% probability, 𝑒𝑟𝑟𝑜𝑟𝐷 ℎ lies in the interval
𝑒𝑟𝑟𝑜𝑟𝑆 (ℎ) ± 𝑧𝑁 𝑒𝑟𝑟𝑜𝑟𝑆 (ℎ)(1 − 𝑒𝑟𝑟𝑜𝑟𝑆 ℎ )/𝑛
Confidence t t t Z
Level (10 d.f.) (20 d.f.) (30 d.f.) (∞ d.f.)
Note: t Z as n increases
Example of t distribution confidence
interval
46.698 ≤ μ ≤ 53.302
Example
• A manufacturing company produces electric insulators. If the insulators break when in use, a
short circuit is likely. To test the strength of the insulators, you carry out destructive testing to
determine how much force is required to break the insulators. You measure force by observing
how many pounds are applied to the insulator before it breaks. Table lists 30 values from this
experiment. Construct a 95% confidence interval estimate for the population mean force required
to break the insulator.
• 1,870 1,728 1,656 1,610 1,634 1,784 1,522 1,696 1,592 1,662
• 1,866 1,764 1,734 1,662 1,734 1,774 1,550 1,756 1,762 1,866
• 1,820 1,744 1,788 1,688 1,810 1,752 1,680 1,810 1,652 1,736
Answer: 𝑋ത = 1723.4, S = 89.55, 𝑛 = 30, 𝑡29 =2.0452
𝑋ത ± 𝑡𝑛−1 𝑆/√𝑛
1723.4 ± 2.0452 ∗ 89.55/√30
1723.4 ± 33.44
1689.96 ≤ 𝜇 ≤ 1756.84
CONFIDENCE INTERVAL ESTIMATION FOR THE
PROPORTION
• The concept of the confidence interval to categorical data
• The unknown population proportion is represented by the Greek
letter 𝜋
• point estimate for 𝜋 is the sample proportion, p = X/n, where n is the
sample size and X is the number of items in the sample having the
characteristic of interest
CONFIDENCE INTERVAL ESTIMATE FOR THE
PROPORTION
𝑝(1 − 𝑝)
𝑝 ± 𝑍√
𝑛
• Z = critical value from the standardized normal distribution
• Example: estimate the proportion of sales invoices that contain errors. Suppose that in a
sample of 100 sales invoices, 10 contain errors
Answer: 95% confidence, Z = 1.96
10
𝑝= = 0.1
100
0.1 ∗ 09
0.1 ± 1.96 ∗ √
100
0.1 ± 1.96 ∗ 0.03
0.1 ± 0.0588
0.0412 ≤ 𝜋 ≤ 0.1588
Try
• A large newspaper wants to estimate the proportion of newspapers
printed that have a nonconforming attribute, such as excessive ruboff,
improper page setup, missing pages, or duplicate pages. A random
sample of 200 newspapers is selected from all the newspapers
printed during a single day. For this sample of 200, 35 contain some
type of nonconformance. Construct and interpret a 90% confidence
interval for the proportion of newspapers printed during the day that
have a nonconforming attribute.
Sample Size Determination for the Mean
• Confidence interval estimation
𝜎
𝑋ത ± 𝑍
√𝑛
• The sampling error e is defined by
𝜎
𝑒=𝑍
√𝑛
• The sample size, n, is equal to the product of the Z value squared and
the variance 𝜎, squared, divided by the square of the sampling error,
e
𝑛 = 𝑍 2 𝜎 2 /𝑒 2
Example
• suppose you want to estimate the population mean force required to break the
insulator to within 25 pounds with 95% confidence. On the basis of a study taken
the previous year, you believe that the standard deviation is 100 pounds. Find the
sample size needed.
Answer: e = 25, Z = 1.96 (95% confidence), 𝜎 = 100
𝑛 = 𝑍 2 𝜎 2 /𝑒 2
𝑛 = (1.96)2 (100)2 /(25)2
𝑛 = 61.47