Inspire…Educate…Transform.
Stat Skills
Confidence Intervals, t-
Distribution, Hypothesis Testing,
t-Tests
Dr. Sridhar Pappu
Executive VP – Academics, INSOFE
June 18, 2016
The best place for students to learn Applied Engineering [Link]
The best place for students to learn Applied Engineering 2 [Link]
Activity – R
According to the US Bureau of the Census, about 75% of the
commuters in the United States drive to work alone. Suppose
150 US commuters are randomly sampled.
• What is the probability that fewer than 105 commuters drive
to work alone?
• What is the probability that between 110 and 120 (inclusive)
commuters drive to work alone?
• What is the probability that more than 95 commuters drive to
work alone?
Answers: 0.0657, 0.6485, 0.9993
The best place for students to learn Applied Engineering 3 [Link]
Activity – R
According to National Center for Health Statistics of the US, the
distribution of serum cholesterol levels for 20-74 year old males
has a mean of 211mg/dl with a standard deviation of 46mg/dl.
• What is the probability that the serum cholesterol level of a
male is >230mg/dl?
• What is the probability that the average serum cholesterol
level of a random sample of 25 males will be >230mg/dl?
Answer: 34.0%, 1.9%
The best place for students to learn Applied Engineering 4 [Link]
Present Day
The best place for students to learn Applied Engineering 5 [Link]
CONFIDENCE LEVELS AND
CONFIDENCE INTERVALS
The best place for students to learn Applied Engineering 6 [Link]
±7 ±10
±6 ±10
The best place for students to learn Applied Engineering 7 [Link]
BJP+ JD(U)+ BJP+ JD(U)+
India Today - Cicero Times Now – C Voter
The best place for students to learn Applied Engineering 8 [Link]
When we use samples to provide population estimates, we cannot
be CERTAIN that they will be accurate. There is an amount of
uncertainty, which needs to be calculated.
Source: [Link]
Last accessed: March 27, 2015
The best place for students to learn Applied Engineering 9 [Link]
Incorrect way to present data as it gives the feeling that the
population parameter will lie within these ranges.
𝑃𝑜𝑝𝑢𝑙𝑎𝑡𝑖𝑜𝑛 𝑑𝑖𝑠𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑆𝑎𝑚𝑝𝑙𝑖𝑛𝑔 𝑑𝑖𝑠𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑜𝑓 𝑠𝑎𝑚𝑝𝑙𝑒 𝑚𝑒𝑎𝑛𝑠
𝜎
𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐸𝑟𝑟𝑜𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑀𝑒𝑎𝑛 =
𝑛
𝜎
𝜇 𝜇𝑋 = 𝜇
Standard Error (SE) is the same as Standard Deviation of the sampling distribution and a
sample with 1 SE may or may not include the population parameter.
The best place for students to learn Applied Engineering 10 [Link]
𝑆𝑎𝑚𝑝𝑙𝑖𝑛𝑔 𝑑𝑖𝑠𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑜𝑓 𝑠𝑎𝑚𝑝𝑙𝑒 𝑚𝑒𝑎𝑛𝑠
𝜎
𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐸𝑟𝑟𝑜𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑀𝑒𝑎𝑛 =
𝑛
𝜇𝑋 = 𝜇
We have seen that ~ 95% of the samples will have a mean value
within the interval +/- 2 SE of the population mean (recall the
Empirical Rule for Normal Distribution).
Alternatively, 95% of such intervals include the population mean.
Here, 95% is the Confidence Level and the interval is called the
Confidence Interval.
The best place for students to learn Applied Engineering 11 [Link]
Confidence Level and Interval - Excel
94 of the 100 intervals contain the population mean.
The best place for students to learn Applied Engineering 12 [Link]
SE or Margin of Error?
What CONFIDENCE!!!
The best place for students to learn Applied Engineering 13 [Link]
The best place for students to learn Applied Engineering 14 [Link]
The best place for students to learn Applied Engineering 15 [Link]
What is the maximum rupees you can expect to lose
over the next month…with a 95% confidence level?
A VaR question posed above has 3 components:
• A time period
• Loss estimate (in absolute or percentage terms)
• High level of confidence
The best place for students to learn Applied Engineering 16 [Link]
SE, Margin of Error, Confidence Interval and
Sample Size
𝜎
𝑆𝐸 = Margin of error at
𝑛 1 SE
95% confidence level
𝑀𝑎𝑟𝑔𝑖𝑛 𝑜𝑓 𝐸𝑟𝑟𝑜𝑟 = 𝑧 ∗ 𝑆𝐸
Margin of error is the maximum
expected difference between the
true population parameter and a Mean or
sample estimate of that parameter. Expectation
Margin of error is meaningful only when stated in conjunction
with a probability (confidence level).
The best place for students to learn Applied Engineering 17 [Link]
SE, Margin of Error, Confidence Interval and
Sample Size
Margin of error is the radius or
half-width of a confidence
interval.
Source: [Link]
Last accessed: June 18, 2015
The best place for students to learn Applied Engineering 18 [Link]
SE, Margin of Error, Confidence Interval and
Sample Size
Just like Mean, Proportion is another common parameter of
interest in many problems.
Expectation of a sample proportion = p
𝑝𝑞
SE of a sample proportion =
𝑛
The best place for students to learn Applied Engineering 19 [Link]
SE, Margin of Error, Confidence Interval and
Sample Size
In a poll by CNN/ORC
conducted between November
27 – December 1, 2015, a survey
of 930 randomly sampled
registered voters predicted that
49% would vote for Hillary
Clinton.
What is the margin of error at
95% confidence level (z = 1.96)?
Check qnorm(0.975, 0, 1). Why
0.975? 0.49 ∗ 0.51
Margin of error = 1.96 ∗ ≈ 3.2%
930
The best place for students to learn Applied Engineering 20 [Link]
SE, Margin of Error, Confidence Interval and
Sample Size
If the desired margin of error at 95% confidence level is 1%, what
should be the sample size?
0.49 ∗ 0.51
0.01 = 1.96 ∗
𝑛
2
1.96
∴𝑛= ∗ 0.49 ∗ 0.51 = 9600
0.01
The best place for students to learn Applied Engineering 21 [Link]
Other ways of estimating the data size
• The rule of thumb
–Count the total number of levels
(assuming 10 levels for numeric)
–Multiply with number classes
–Multiply with 75-150
The best place for students to learn Applied Engineering 22 [Link]
Example
• Will a patient adhere or not?
–Age (young, middle, old), income (low,
medium, high), gender (male, female),
education (high school; college; university)
The best place for students to learn Applied Engineering 23 [Link]
Data need
Attributes Levels Classes Rule of Thumb (x75)
2 2 2 600
5 5 3 5625
10 5 4 15000
20 5 2 15000
50 5 3 56250
100 5 4 150000
The best place for students to learn Applied Engineering 24 [Link]
Confidence Intervals
A survey was taken of US companies that do business with firms in
India. One of the survey questions was: Approximately how many
years has your company been trading with firms in India? A
random sample of 44 responses to this question yielded a mean of
10.455 years. Suppose the population standard deviation for this
question is 7.7 years. Using this information, construct a 90%
confidence interval for the mean number of years that a company
has been trading in India for the population of US companies
trading with firms in India.
The best place for students to learn Applied Engineering 25 [Link]
Confidence Intervals
• 𝑛 = 44
• 𝑥 = 10.455
• 𝜎 = 7.7
𝑥−𝜇 𝜎
𝑧= 𝜎 or Margin of error = 𝑧 ∗
𝑛
𝑛
∴ Confidence Interval for the Population Mean is
Sample Mean ± Margin of Error
The best place for students to learn Applied Engineering 26 [Link]
Confidence Intervals
Find za and zb where P(za < Z < zb) = 0.90
0.90
0.05 0.05
za 0 zb
P(Z < za) = 0.05 and P(Z > zb) = 0.05
The best place for students to learn Applied Engineering 27 [Link]
Confidence Intervals
From probability
tables using
interpolation, we
get za = -1.645 and
zb = 1.645.
Check qnorm(0.05, 0, 1)
and qnorm(0.95, 0, 1) in
R.
The best place for students to learn Applied Engineering 28 [Link]
Confidence Intervals
7.7
𝑀𝑎𝑟𝑔𝑖𝑛 𝑜𝑓 𝑒𝑟𝑟𝑜𝑟 𝑎𝑡 90% 𝐶𝑜𝑛𝑓𝑖𝑑𝑒𝑛𝑐𝑒 𝐿𝑒𝑣𝑒𝑙 = 1.645 ∗ = 1.91
44
Recall Confidence Interval for the Population Mean is Sample Mean ± Margin of Error
𝑋 − 1.91 < 𝜇 < 𝑋 + 1.91
Since the sample mean is 10.455 years, we get the confidence interval for 90% as
8.545 < 𝜇 < 12.365.
The analyst is 90% confident that if a census of all US companies trading with
firms in India were taken at the time of the survey, the actual population mean
number of trading years of such firms would be between 8.545 and 12.365 years.
The best place for students to learn Applied Engineering 29 [Link]
Shortcuts for Calculating Confidence Intervals
Population Population Conditions Confidence Interval
n Distribution
Parameter n
r
You know σ2 𝜎 𝜎
µ Normal n is large or small (𝑋 − 𝑧 ,𝑋 +𝑧 )
𝑛 𝑛
𝑋 is the sample mean
You know σ2 𝜎 𝜎
Non-normal
µ n is large (> 30) (𝑋 − 𝑧 ,𝑋 +𝑧 )
normal 𝑛 𝑛
𝑋 is the sample mean
You don’t know σ2 𝑠 𝑠
Normal or (𝑋 − 𝑧 ,𝑋 +𝑧 )
n is large (> 30) 𝑛 𝑛
µ Non-normal
𝑋 is the sample mean
normal
s2 is the sample variance
n is large
ps is the sample proportion 𝑝𝑠 𝑞𝑠 𝑝𝑠 𝑞𝑠
p Binomial
proportion
(𝑝𝑠 − 𝑧 , 𝑝𝑠 + 𝑧 )
𝑛 𝑛
q is 1 - p
The best place for students to learn Applied Engineering 30 [Link]
Shortcuts for Calculating Confidence Intervals
Level of Confidence Value of z
90% 1.64
95% 1.96
99% 2.58
You took a sample of 50 Gems and found that in the sample, the
proportion of red Gems is 0.25. Construct a 99% confidence
interval for the proportion of red Gems in the population.
0.25 ∗ 0.75 0.25 ∗ 0.75
0.25 − 2.58 ∗ < 𝑝 < 0.25 + 2.58 ∗
50 50
0.09 < 𝑝 < 0.41
The best place for students to learn Applied Engineering 31 [Link]
Shortcuts for Calculating Confidence Intervals
Level of confidence Value of z
90% 1.64
95% 1.96
99% 2.58
The lung function in 57 people is
tested using FEV1 (Forced Expiratory
Volume in 1 Second) measurements.
The mean FEV1 value for this sample
is 4.062 litres and standard deviation,
s is 0.67 litres. Construct the 95%
Confidence Interval.
The best place for students to learn Applied Engineering 32 [Link]
FEV1 values of 57 male medical students
Level of Value of z 2.85 2.85 2.98 3.04 3.10 3.10 3.19 3.20 3.30 3.39
confidence z 3.42 3.48 3.50 3.54 3.54 3.57 3.60 3.60 3.69 3.70
90% 1.64 3.70 3.75 3.78 3.83 3.90 3.96 4.05 4.08 4.10 4.14
95% 1.96
4.14 4.16 4.20 4.20 4.30 4.30 4.32 4.44 4.47 4.47
99% 2.58
4.47 4.50 4.50 4.56 4.68 4.70 4.71 4.78 4.80 4.80
4.90 5.00 5.10 5.10 5.20 5.30 5.43
0.67 0.67
95% 𝐶𝐼: 4.062 − 1.96 ∗ , 4.062 + 1.96 ∗
57 57
= (3.89,4.23)
The best place for students to learn Applied Engineering 33 [Link]
Confidence Intervals for a Sample Median
Confidence limits are given by actual values in the sample using
the following formulae:
𝑛 𝑛
Lower 95% Confidence Limit: − 1.96 ∗ ranked value.
2 2
𝑛 𝑛
Upper 95% Confidence Limit: 1 + + 1.96 ∗ ranked value.
2 2
The best place for students to learn Applied Engineering 34 [Link]
Confidence Intervals for a Sample Median
2.85 2.85 2.98 3.04 3.10 3.10 3.19 3.20 3.30 3.39
3.42 3.48 3.50 3.54 3.54 3.57 3.60 3.60 3.69 3.70
3.70 3.75 3.78 3.83 3.90 3.96 4.05 4.08 4.10 4.14
4.14 4.16 4.20 4.20 4.30 4.30 4.32 4.44 4.47 4.47
4.47 4.50 4.50 4.56 4.68 4.70 4.71 4.78 4.80 4.80
Lower 95% CL Median
4.90 5.00 5.10 5.10 5.20 5.30 5.43
Upper 95% CL
57 57
Lower 95% Confidence Limit: − 1.96 ∗ = 21.10 ranked
2 2
value. 21st ranked value is 3.70.
57 57
Upper 95% Confidence Limit: 1 + + 1.96 ∗ = 36.90 ranked
2 2
value. 37th ranked value is 4.32.
95% CI: (3.70,4.32) Recall 95% CI using Mean: (3.89,4.23)
The best place for students to learn Applied Engineering 35 [Link]
Confidence Intervals for a Sample Median
• Lack of distributional assumptions makes it difficult to obtain an
exact CI for the median.
• CI are not necessarily symmetric around the sample estimate.
The best place for students to learn Applied Engineering 36 [Link]
Value at Risk (VAR)
VAR is the maximum loss over a target horizon within a confidence
interval (or, under normal market conditions).
In other words, if none of the “extreme events” (i.e., low-
probability events) occurs, what is my maximum loss over a given
time period?
The best place for students to learn Applied Engineering 37 [Link]
VAR: Example
Consider a $100 million portfolio of medium-term bonds.
Suppose the confidence interval is 95% (i.e., 95% of possible
market events is defined as “normal”) Then, what is the maximum
monthly loss under normal markets over any month?
To answer this question, let’s look at the monthly medium-term
bond returns from 1953 to 1995:
Lowest: -6.5% vs. Highest: 12%
The best place for students to learn Applied Engineering 38 [Link]
History of Medium Bond Returns
The best place for students to learn Applied Engineering 39 [Link]
Distribution of Medium Bond Returns
The best place for students to learn Applied Engineering 40 [Link]
Calculating VAR at 95% Confidence
• At the 95% confidence interval, the lowest monthly return is -
1.7%. (i.e., there is a 5% chance that the monthly medium bond
return is lower than -1.7%)
– That is, there are 26 months out of the 516 for which the monthly
returns were lower than -1.7%.
• VAR = 100 million X 1.7% = $1.7 million
– (95% of the time, the portfolio’s loss will be no more than $1.7
million!)
The best place for students to learn Applied Engineering 41 [Link]
Attention Check
What happens to confidence interval as confidence level changes?
As confidence level increases, the confidence interval becomes
wider and vice-versa.
What happens to the confidence interval as sample size changes?
As sample size increases, the confidence interval becomes narrower.
𝜎 𝜎
Remember (𝑋 − 𝑧 , 𝑋 + 𝑧 ).
𝑛 𝑛
The best place for students to learn Applied Engineering 42 [Link]
The Connection
Confidence Interval = Sample statistic ± Margin of Error
𝜎 𝜎 𝑀𝑎𝑥(𝑥 − 𝜇)
(𝑋 − 𝑧 ,𝑋 +𝑧 )
𝑛 𝑛
Margin of error = z * Standard Error (Recall the standardization formula)
𝜎
Depends on the confidence level 𝑛
Probability density.
Area under the curve between the limits.
Probability that a certain % of samples will contain the population mean within this interval.
Standard deviation of the population: A sort of “average” deviation from the mean.
The best place for students to learn Applied Engineering 43 [Link]
t-Distribution
Ref: [Link]
[Link]?cb=1369825611
Last accessed: October 31, 2015
The best place for students to learn Applied Engineering 44 [Link]
t-Distribution
If the sample size is small (<30), the variance of the population is
not adequately captured by the variance of the sample. Instead of
z-distribution, t-distribution is used. It is also the appropriate
distribution to be used when population variance is not known,
irrespective of sample size.
Ref: "Comparing Normal and Student's t-Distributions" from the Wolfram Demonstrations Project
[Link]
Contributed by: Gary McClelland; Last accessed: June 14, 2016
The best place for students to learn Applied Engineering 45 [Link]
t-Distribution
(𝑥 − 𝜇)
𝑡 𝑠𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 𝑜𝑟 𝑡 𝑠𝑐𝑜𝑟𝑒 , 𝑡 = 𝑠
𝑛
Degrees of freedom, ν: # of independent observations for a source
of variation minus the number of independent parameters estimated
in computing the variation.*
When estimating mean or proportion from a single sample, the # of
independent observations is equal to n-1.
* Roger E. Kirk, Experimental Design: Procedures for the Behavioral Sciences. Belmont, California: Brooks/Cole, 1968.
The best place for students to learn Applied Engineering 46 [Link]
Properties of t-Distribution
• Mean of the distribution = 0
𝜈
• Variance = , where 𝜈 > 2
𝜈−2
• Variance is always greater than 1, although it is close to 1 when
there are many degrees of freedom (sample size is large)
• With infinite degrees of freedom, t distribution is the same as the
standard normal distribution
The best place for students to learn Applied Engineering 47 [Link]
Confidence Interval to Estimate 𝝁
• Population standard deviation UNKNOWN and the population
normally distributed.
𝑠 𝑠
• 𝑥− 𝑡𝑛−1,𝛼 ≤𝜇≤𝑥+ 𝑡𝑛−1,𝛼
2 𝑛 2 𝑛
– Sample mean, standard deviation and size can be calculated from the
data; t value can be read from the table or obtained from software.
– α is the area in the tail of the distribution. For 90% Confidence Level,
α=0.10. In a Confidence Interval, this area is symmetrically distributed
between the 2 tails (α/2 in each tail).
The best place for students to learn Applied Engineering 48 [Link]
t-table
The best place for students to learn Applied Engineering 49 [Link]
t-Distribution - Example
The labeled potency of a tablet dosage form is 100 mg. As per the
quality control specifications, 10 tablets are randomly assayed.
A researcher wants to estimate the interval for the true mean of the
batch of tablets with 95% confidence. Assume the potency is
normally distributed.
Data are as follows (in mg):
98.6 102.1 100.7 102.0 97.0
103.4 98.9 101.6 102.9 105.2
The best place for students to learn Applied Engineering 50 [Link]
t-Distribution - Example
Mean, 𝑥 = 101.24 mg
Standard deviation, s = 2.48
n = 10
𝜈 = 10 − 1 = 9
𝛼
At 95% level, 𝛼 = 0.05, and ∴, = 0.025
2
The best place for students to learn Applied Engineering 51 [Link]
t-table
𝑡9,0.025 = 2.262
The best place for students to learn Applied Engineering 52 [Link]
t-Distribution - Example
Mean, 𝑥 = 101.24 mg, Standard deviation, s = 2.48
n = 10, 𝜈 = 10 − 1 = 9
𝑠 𝑠
𝑥 − 𝑡𝑛−1,𝛼 ≤ 𝜇 ≤ 𝑥 + 𝑡𝑛−1,𝛼
2 𝑛 2 𝑛
2.48 2.48
101.24 − 2.262 ∗ ≤ 𝜇 ≤ 101.24 + 2.262 ∗
10 10
99.47 ≤ 𝜇 ≤ 103.01
The batch mean is 101.24 mg with an error of +/-1.77 mg. The
researcher is 95% confident that the average potency of the batch of
tablets is between 99.47 mg and 103.01 mg.
The best place for students to learn Applied Engineering 53 [Link]
t-Distribution – Example – R Output
The best place for students to learn Applied Engineering 54 [Link]
t-Distribution - Example
A researcher wants to examine CD4 counts
for HIV+ patients at her clinic. She
randomly selects a sample of 25 HIV+
patients and measures their CD4 levels.
Calculate a 95% CI for population mean
given the following sample results:
Variable n 𝒙 SE of s Min Q1 Median Q3 Max
e Mean
CD4 25 321.4 14.8 73.8 208.0 261.5 325.0 394.0 449.0
(cells/𝜇l)
The best place for students to learn Applied Engineering 55 [Link]
t-Distribution - Example
Variable n 𝒙 SE of s Min Q1 Median Q3 Max
Mean
CD4 25 321.4 14.8 73.8 208.0 261.5 325.0 394.0 449.0
(cells/𝜇l)
𝑠 𝑠
𝐶𝐼 0.05 : 𝑥 − 𝑡𝑛−1,𝛼 ≤ 𝜇 ≤ 𝑥 + 𝑡𝑛−1,𝛼
2 𝑛 2 𝑛
73.8 73.8
321.4 − 𝑡 0.05 ≤ 𝜇 ≤ 321.4 + 𝑡 0.05
25−1, 25 25−1, 25
2 2
𝑡24,0.025 = 2.064
∴ 𝐶𝐼(0.05): [290.85,351.95]
The best place for students to learn Applied Engineering 56 [Link]
t-Distribution - Example
What does 𝐶𝐼(0.05): [290.85,351.95] mean in the business
context given that US Government classifies AIDS under three
official categories of CD4 counts:
• Asymptomatic: ≥ 500 cells/𝜇l
• AIDS related complex (ARC): 200-499 cells/𝜇l
• AIDS (Stage 3 infection): < 200 cells/𝜇l
The best place for students to learn Applied Engineering 57 [Link]
Interview Question
If you toss a coin 20 times and get 15 heads, would you
say the coin is biased?
Let us apply our learning thus far…
The best place for students to learn Applied Engineering 58 [Link]
Q. What distribution is it?
A. Binomial; X~B(20,0.5) assuming the coin is fair.
Q. What is the expectation?
A. 𝑛𝑝 = 10
Q. What is the standard deviation?
A. 𝑛𝑝𝑞 = 5 = 2.236
Q. How many standard deviations away from the mean
is 15?
15−10
A. = 2.236
2.236
The best place for students to learn Applied Engineering 59 [Link]
Q. What is the probability of getting 15 or more heads?
A. 𝑃 𝑋 ≥ 15 = 𝑃 𝑋 = 15 + 𝑃 𝑋 = 16 +
𝑃 𝑋 = 17 + 𝑃 𝑋 = 18 + 𝑃 𝑋 = 19 +
𝑃 𝑋 = 20 = 0.021
Q. Can it be approximated to a normal distribution?
A. 𝑛𝑝 = 10 𝑎𝑛𝑑 𝑛𝑞 = 10. Since both are greater than
5, it can be approximated to X~N(10,5)
Q. What is the probability of getting 15 or more heads?
A. P X > 14.5 = 1 − 𝑃 𝑋 < 14.5
Q. What is the z-score?
14.5−10
A. = 2.01. ∴ 𝑃 = 1 − 0.9778 = 0.0222
5
The best place for students to learn Applied Engineering 60 [Link]
HYPOTHESIS TESTS
The best place for students to learn Applied Engineering 61 [Link]
Hypothesis tests give a way of using samples to test whether or not
statistical claims are likely to be true or not.
The best place for students to learn Applied Engineering 62 [Link]
Dr. Unsnora prescribes SnoreCull to 15 of her patients and records
whether it cured them or not after 2 weeks. She found that 11 were
cured and 4 were not.
If the drug maker claimed that 90% get cured, 13.5 or 14 patients
should have been cured. Is the company making false claims or is
the doctor’s sampling biased?
The best place for students to learn Applied Engineering 63 [Link]
Hypothesis Testing Process
Considering variations in samples, how far away from 90%
is acceptable to you as expected variation and when do you
say “enough is enough; this is too far”?
This far?
This far?
This far?
Claim or Expectation, say, 90% get cured
The best place for students to learn Applied Engineering 64 [Link]
Step 1: Decide on the hypothesis
SnoreCull cures 90% of the patients within 2 weeks.
This is called Null Hypothesis and is represented by H0.
In this case, H0: p = 0.9
If Null Hypothesis is rejected based on evidence, an Alternate
Hypothesis, H1, needs to be accepted. We always start with the
assumption that Null Hypothesis is true.
In this case, H1: p < 0.9
The best place for students to learn Applied Engineering 65 [Link]
Examples of Hypotheses
• Two hypotheses in competition:
– H0: The NULL hypothesis, usually the most conservative.
– H1 or HA: The ALTERNATIVE hypothesis, the one we are actually
interested in.
• Examples of NULL Hypothesis:
– The coin is fair
– The new drug is no better (or worse) than the placebo
• Examples of ALTERNATIVE hypothesis:
– The coin is biased (either towards heads or tails)
– The coin is biased towards heads
– The coin has a probability 0.6 of landing on tails
– The drug is better than the placebo
The best place for students to learn Applied Engineering 66 [Link]
Step 2: Choose your statistic
X ~ B(15, 0.9)
The best place for students to learn Applied Engineering 67 [Link]
Step 3: Specify the Significance Level
First, we must decide on the Significance Level, α. It is a measure
of how unlikely you want the results of the sample to be before you
reject the null hypothesis, H0.
This far?
This far?
This far?
Claim or Expectation, say, 90% get cured
The best place for students to learn Applied Engineering 68 [Link]
Step 4: Determine the critical region
If X represents the number of snorers cured, the critical region is
defined as P(X < c) < α where α = 5%.
Critical Region
Recall that in a 95% CI, there is a 5% chance that the sample will
not contain the population mean. Hence if the sample falls in the
critical region, the null hypothesis that 90% snorers are cured, is
rejected.
That is the reason 5% or 0.05 is called the Significance Level. In a
99% CI, 0.01 is the Significance Level.
The best place for students to learn Applied Engineering 69 [Link]
Step 5: Find the p-value
p-value is the probability of getting a value
up to and including the one in the sample in
the direction of the critical region.
It is a way of taking the sample and working
out whether the result falls within the
critical region of the hypothesis test.
p-value
Probability density
Essentially, this is the value used to Area under the curve
determine whether or not to reject the null
hypothesis.
The best place for students to learn Applied Engineering 70 [Link]
Step 5: Find the p-value
In the SnoreCull test done by Dr. Unsnora, 11 people were cured.
This means our p-value is P(X ≤ 11), where X is the distribution of
the number of people cured in the sample.
If P(X ≤ 11) < 0.05 (Significance Level), it indicates that 11 is
inside the critical region, and hence H0 can be rejected.
Given that X ~ B(15, 0.9), P(X ≤ 11) = 1 – P (X ≥ 12) = 0.0555
The best place for students to learn Applied Engineering 71 [Link]
Step 6: Is the sample result in the critical region?
Critical Region
5.55%
The best place for students to learn Applied Engineering 72 [Link]
Step 7: Make your decision
There isn’t sufficient evidence to reject the null hypothesis and so,
the claims of the company are accepted.
Dr. Unsnora is not convinced and did another test with 100 people
where 80 got cured and 20 didn’t. What is your decision going to
be now?
The best place for students to learn Applied Engineering 73 [Link]
What are the null and alternate hypotheses?
H0: p = 0.9
H1: p < 0.9
What is the test statistic?
X ~ B(100, 0.9) Oh! Dear
The best place for students to learn Applied Engineering 74 [Link]
What probability distribution can be used to approximate the
Binomial distribution?
Since np>5 and nq>5, Central Limit Theorem can be applied to
sampling proportions.
What is the probability of 80% or fewer getting cured?
CONTINUITY
0.5 CORRECTION FACTOR
𝑝+ − 𝑝0 0.805 − 0.9 0.805 − 0.9
𝑧= 𝑛 = = = −3.17
𝑝0 (1 − 𝑝0 ) 0.9 ∗ 0.1 0.0009
𝑛 100
p-value = P(Z < -3.17) = 0.0008
The best place for students to learn Applied Engineering 75 [Link]
What is your decision?
Since the p-value (0.0008) is less than the Significance Level of
0.05, the null hypothesis can be rejected.
The best place for students to learn Applied Engineering 76 [Link]
Attention Check
In hypothesis testing, do you assume the null hypothesis to be true or false?
True.
If there is sufficient evidence against the null hypothesis, do you
accept it or reject it?
Reject it.
The best place for students to learn Applied Engineering 77 [Link]
Attention Check
If the p-value is less than 0.05 for the above significance level, will you
accept or reject the null hypothesis?
Reject it.
Do you need weaker evidence or stronger to reject the null hypothesis if you
were testing at the 1% significance level instead of the 5% significance level?
Stronger.
The best place for students to learn Applied Engineering 78 [Link]
Critical Region Up Close
One-tailed tests
The position of the tail is dependent on H1.
If H1 includes a < sign, then the lower tail is used.
If H1 includes a > sign, then the upper tail is used.
c
α 100%-α
100%-α α
The best place for students to learn Applied Engineering 79 [Link]
Critical Region Up Close
Two-tailed tests
Critical region is split over both ends. Both ends contain α/2, making a total
of α.
If H1 includes a ≠ sign, then the two-tailed test is used as we then look for a
change in parameter, rather than an increase or a decrease.
c1 c2
α/2 100%-α α/2
The best place for students to learn Applied Engineering 80 [Link]
Critical Region Up Close
For each of the scenarios below, identify what type of test you would require.
• SnoreCull hypothesis test as discussed till now.
One-tailed/Lower-tailed
• If we were checking whether significantly more or significantly fewer than
90% patients had been cured, i.e., H1: p≠0.9.
Two-tailed test
• The coin is biased.
Two-tailed test
• The coin is biased towards heads with probability 0.8.
One-tailed/Upper-tailed
The best place for students to learn Applied Engineering 81 [Link]
The Missing Link in the Interview
Q. What is the probability of getting 15 or more heads?
A. 𝑃 𝑋 ≥ 15 = 𝑃 𝑋 = 15 + 𝑃 𝑋 = 16 +
𝑃 𝑋 = 17 + 𝑃 𝑋 = 18 + 𝑃 𝑋 = 19 +
𝑃 𝑋 = 20 = 0.021
What can you now say about the coin being biased or not?
c=15
100%-α? α?
The best place for students to learn Applied Engineering 82 [Link]
The hypothesis test doesn’t answer the question whether
the coin is biased or not; it only states whether the
evidence is enough to reject the null hypothesis or not
at the chosen significance level.
The best place for students to learn Applied Engineering 83 [Link]
Errors
• Type I: We reject the NULL hypothesis incorrectly
• Type II: We “accept” it incorrectly
State of Nature
Null true Null false
Fail to Correct decision Type II error (β)
reject null True Negative False Negative
(negative) Specificity P(Accept H0 | H0 False)
Action ) P(Accept H0 | H0 True)
Reject Type I error (α) Correct decision (Power)
null False Positive (Power)
(positive) P(Reject H0 | H0 True) True Positive
Sensitivity/Recall
P(Reject H0 | H0 False)
The best place for students to learn Applied Engineering 84 [Link]
Probability of Getting Type I Error
State of Nature
Null true Null false
Fail to reject Correct decision Type II error (β)
null (negative) decision False Negative
True Negative
Action Specificity
Reject null Type I error (α) Correct decision (Power)
(positive) False Positive (Power)
True Positive
Sensitivity/Recall
α
P(Type I error) = α
The best place for students to learn Applied Engineering 85 [Link]
Probability of Getting Type II Error
State of Nature
P(Type II error) = β Null true Null false
Fail to reject Correct decision Type II error (β)
To find β, null (negative) decision
True Negative
False Negative
Action Specificity
1. Check that you have a specific value for H1. Reject null Type I error (α) Correct decision (Power)
(positive) False Positive (Power)
True Positive
2. Find the range of values outside the critical Sensitivity/Recall
region of the test. If the test statistic has been
standardized, it needs to be de-standardized for
the purpose.
3. Find the probability of getting this range of
values, assuming H1 is true. In other words, find
the probability of getting the range of values α
outside the critical region, but this time using the
test statistic described by H1 and not H0.
The best place for students to learn Applied Engineering 86 [Link]
Probabilities of Type I and Type II Errors
Type I (α)
Type II (β)
The best place for students to learn Applied Engineering 87 [Link]
Probabilities of Errors in Our Example
P(Type I error) = 0.05
To calculate P(Type II error)
H0: p = 0.9
H1: p = 0.8
P(Z < z) = 0.05 for 5% Significance Value. From probability tables, z = -1.64.
To de-standardize and find values outside the critical region,
𝑝−0.9
≥ −1.64; 𝑝 ≥ 0.8508, i.e., we would accept null hypothesis if 85.08 or
0.0009
more people out of 100 had been cured.
The best place for students to learn Applied Engineering 88 [Link]
Probabilities of Errors in Our Example
Finally, we need to calculate P(𝑝 ≥ 0.8508), assuming
H1 is true.
𝑝 1−𝑝
𝑝~𝑁(𝑝0 , 0 0
) where n=100 and 𝑝0 =0.8. This
𝑛
gives 𝑝~𝑁(0.8,0.0016).
To calculate P(𝑝 ≥ 0.8508) where 𝑝~𝑁(0.8,0.0016),
we find
0.8508 − 0.80
𝑧= = 1.27
0.0016
P(Z ≥ 1.27) = 1 – P(Z < 1.27) = 1-0.8980 = 0.102
P(Type II error) = 0.102
The probability of accepting the null hypothesis that
90% are cured when actually 80% are is 10.2%.
The best place for students to learn Applied Engineering 89 [Link]
Power of a Hypothesis Test
We reject null hypothesis correctly
when it is false.
It is actually the opposite of Type II
error, and therefore,
Power = 1 – β = 1-0.102 = 0.898, i.e.,
the probability that we will make the
correct decision in rejecting the null
hypothesis is 89.8%.
The best place for students to learn Applied Engineering 90 [Link]
Hypothesis Testing
A prisoner is on trial and you are on the jury. The jury’s task is to assume that
the accused is innocent, but if there is enough evidence, the jury needs to
convict him.
In the trial, what is the null hypothesis?
The prisoner is innocent (or not guilty).
What is the alternate hypothesis?
The prisoner is guilty.
The best place for students to learn Applied Engineering 91 [Link]
Hypothesis Testing
What are the possible ways of the jury coming to an incorrect verdict?
If the prisoner is innocent, and the jury gives a ‘guilty’ verdict.
If the prisoner is guilty, and the jury gives an ‘innocent’ verdict.
Which one is Type I and which one Type II?
First one is Type I because null hypothesis actually was correct but rejected
incorrectly.
Second one is Type II because null hypothesis was false but was accepted
incorrectly.
What is the Power of the test?
Since it is opposite of Type II, it will be finding the prisoner guilty when the
prisoner is actually guilty, i.e., rejecting the null hypothesis correctly.
The best place for students to learn Applied Engineering 92 [Link]
Hypothesis Testing
The best place for students to learn Applied Engineering 93 [Link]
Common Test Statistics for Inferential Techniques
Inferential techniques (Confidence Intervals and Hypothesis
Testing) most commonly use 4 test statistics:
• z
Closely related to Sampling Distribution of Means
• t
• 𝜒 2 (Chi-squared) • Closely related to Sampling Distribution of Variances
• Derived from Normal Distribution
• F
The best place for students to learn Applied Engineering 94 [Link]
TWO-SAMPLE t-TEST FOR
MEANS
The best place for students to learn Applied Engineering 95 [Link]
• Do two samples come from the same population?
• If they come from different populations, what is the difference
in the means of the two populations?
– Does the average cost of a two-bedroom flat differ between Bengaluru
and Hyderabad? What is the difference?
– What is the difference in the strength of steel produced under two
different temperatures?
– Does the effectiveness of Head & Shoulders anti-dandruff shampoo
differ from Pantene anti-dandruff shampoo?
– What is the difference in the productivity of men and women on an
assembly line under certain conditions?
– Does an antibiotic affect the efficacy of another drug being taken by a
patient?
The best place for students to learn Applied Engineering 96 [Link]
The Central Limit Theorem states that the difference in two sample
means, 𝑥1 − 𝑥2 , is normally distributed for large sample sizes
(both 𝑛1 and 𝑛2 ≥ 30) whatever the population distribution.
Also, 𝜇𝑥1 −𝑥2 = 𝜇1 − 𝜇2 [Recall E(X-Y)=E(X)-E(Y)]
𝜎1 2 𝜎2 2
and 𝜎𝑥1 −𝑥2 = + [Recall Var(X-Y)=Var(X)+Var(Y)]
𝑛1 𝑛2
𝑜𝑏𝑠𝑒𝑟𝑣𝑒𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒−𝑒𝑥𝑝𝑒𝑐𝑡𝑒𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑥1 −𝑥2 −(𝜇1 −𝜇2 )
𝑧= =
𝑆𝐸 𝑜𝑓 𝑡ℎ𝑒 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝜎1 2 𝜎2 2
𝑛1
+𝑛
2
This is the test statistic for a 2-sample z-test.
The best place for students to learn Applied Engineering 97 [Link]
Two-Sample t-Test for Unpaired Data
𝐻0 : 𝜇1 = 𝜇2 ; 𝐻1 : 𝜇1 ≠ 𝜇2
𝑥1 −𝑥2
Test statistic, 𝑡 =
𝜎1 2 𝜎2 2
𝑛1
+𝑛
2
Assuming the two samples come from populations with the same
standard deviation (Rule of thumb: The ratio between the higher
s and the lower s is less than 2), pooled variance can be used to
calculate SE.
𝑛 − 1 𝑠 2 + (𝑛 − 1)𝑠 2
2 1 1 2 2
𝑠𝑝 =
𝑛1 − 1 + (𝑛2 − 1)
𝑥1 −𝑥2
𝑡= 1 1
with (𝑛1 + 𝑛2 − 2) degrees of freedom.
𝑠𝑝 𝑛 +𝑛
1 2
The best place for students to learn Applied Engineering 98 [Link]
Two-Sample t-Test for Unpaired Data
Welch’s t-test using Welch-Sattherthwaite equation for df
𝑥1 −𝑥2
𝐻0 : 𝜇1 = 𝜇2 ; 𝐻1 : 𝜇1 ≠ 𝜇2 ; Test statistic, 𝑡 =
𝑠1 2 𝑠2 2
+
𝑛1 𝑛2
for unequal standard deviations for the two populations.
The degrees of freedom in this case are calculated as:
2
𝑠1 2 𝑠2 2
𝑛1 𝑛2
+
𝜈= 2 2 , rounded off to the nearest integer.
𝑠1 2 𝑠2 2
𝑛1 𝑛2
𝑛1 −1
+ 𝑛2 −1
R code: [Link](data1, data2, alternative="[Link]", [Link]=FALSE)
The best place for students to learn Applied Engineering 99 [Link]
Hypothesis Testing
Antibiotic rifampicin increases
the amount of drug
metabolizing enzyme present in
the liver. This causes increase
in the rate of elimination of a lot
of other drugs.
Image Source: Deccan Chronicle, Hyderabad edition, May 04, 2016
An experiment was conducted to study whether rifampicin affects
the metabolic removal of the anti-asthma drug theophylline. A high
elimination rate would mean inadequate treatment of the patient’s
asthma.
The best place for students to learn Applied Engineering 100 [Link]
Hypothesis Testing
Two groups of 15 subjects were pre-treated with oral rifampicin
(600 mg daily for 10 days) and a placebo, respectively. All of them
were then given intravenous injection of theophylline (3 mg/kg of
body weight).
Drug content was then measured from the blood samples and
efficiency of removal of theophylline reported as clearance (in
ml/min/kg).
The best place for students to learn Applied Engineering 101 [Link]
Hypothesis Testing
Clearance of theophylline (ml/min/kg)
Control Subjects Treated Subjects
0.81 0.56 0.46 1.15 1.15 0.92
1.06 0.45 0.43 1.28 0.72 0.67
0.43 0.88 0.37 1.00 0.79 0.76
0.54 0.73 0.73 0.95 0.67 0.82
0.68 0.43 0.93 1.06 1.21 0.82
𝑛2 = 15 𝑛1 = 15
𝑥2 = 0.633 𝑥1 = 0.931
𝑠2 = 0.216 𝑠1 = 0.202
𝑠2 2 = 0.0467 𝑠1 2 = 0.0408
The best place for students to learn Applied Engineering 102 [Link]
Hypothesis Testing
What is the null hypothesis?
𝐻0 : 𝜇1 − 𝜇2 = 0 (Rifampicin does not cause a change in
theophylline clearance)
What is the alternative hypothesis?
𝐻1 : 𝜇1 − 𝜇2 ≠ 0
Is it a one-tailed test or a two-tailed test?
Two-tailed
What could be a possible hypothesis for a one-tailed test?
Rifampicin decreases theophylline clearance.
The best place for students to learn Applied Engineering 103 [Link]
Hypothesis Testing
At α = 0.05, determine if there is a significant difference between
the two groups.
2 𝑛1 −1 𝑠1 2 +(𝑛2 −1)𝑠2 2 𝑥1 −𝑥2
𝑠𝑝 = ; 𝑡= with (𝑛1 + 𝑛2 − 2) df.
𝑛1 −1 +(𝑛2 −1) 1
𝑠𝑝 𝑛 +𝑛
1
1 2
2 15−1 ∗0.0408+ 15−1 ∗0.0467
𝑠𝑝 = = 0.04375; 𝑠𝑝 = 0.209
15−1 +(15−1)
0.931−0.633
𝑡= 1 1
= 3.91
0.209∗ +
15 15
You can find the p-value for this t-score or knowing that the t-score
is way more than the critical value for 28 df (~ 2) at this significance
level, you see that it is in the critical region in the right tail.
The best place for students to learn Applied Engineering 104 [Link]
Hypothesis Testing
Will you reject the null hypothesis or fail to do so?
Reject. That means rifampicin does affect theophylline clearance.
Does it increase or decrease theophylline clearance and by how
much?
As the treated patients showed a higher clearance (0.931 ml/min/kg)
compared to the control group (0.633 ml/min/kg), rifampicin
increases clearance by about 0.298 ml/min/kg).
The best place for students to learn Applied Engineering 105 [Link]
Confidence Intervals
𝑥1 −𝑥2 −(𝜇1 −𝜇2 )
𝑡= 1 1
Rewriting:
𝑠𝑝 𝑛 +𝑛
1 2
1 1 1 1
𝑥1 − 𝑥2 − 𝑡𝑠𝑝 + ≤ 𝜇1 − 𝜇2 ≤ 𝑥1 − 𝑥2 + 𝑡𝑠𝑝 +
𝑛1 𝑛2 𝑛1 𝑛2
0.298 − 2.048 ∗ 0.0763 ≤ 𝜇1 − 𝜇2 ≤ 0.298 + 2.048 ∗ 0.0763
95% CI: (0.142, 0.454)
Note zero difference is unlikely as at 95% Confidence Level, the
difference ranges between 0.142 and 0.454 ml/min/kg, with a point
estimate for the difference in mean clearance being 0.298 ml/min/kg.
The best place for students to learn Applied Engineering 106 [Link]
Two-Sample t-Test for Paired Data
When the effects of two alternative treatments is to be compared,
sometimes it is possible to make comparisons in pairs, where, e.g.,
the pair can be the same person at two different occasions or
matched pairs where they are alike in all respects.
In unpaired t-test, difference in means is studied. In paired t-test,
mean of the differences is studied.
The best place for students to learn Applied Engineering 107 [Link]
Two-Sample t-Test for Paired Data
A random sample of 12 diverticulosis patients with comparable
severity in 20-44 age group is given two treatments. In Treatment
A, bran is given in the same dosage in three meals during the day
and in Treatment B, it is given in one meal.
The alimentary transit times of marker pellets through the
alimentary canal are recorded.
The clinician wants to test at 5% Significance Level (or 95%
Confidence Level) if the transit times are shorter when bran is
given in 3 meals.
The best place for students to learn Applied Engineering 108 [Link]
Two-Sample t-Test for Paired Data
Treatment times (h)
Patient Treatment A Treatment B A-B
1 63 55 -8
2 54 62 -8
3 79 108 -29
4 68 77 -9
5 87 83 4
6 84 78 6
7 92 79 13
8 57 94 -37
9 66 69 -3
10 53 66 -13
11 76 72 4
12 63 77 -14
TOTAL 842 920 -78
MEAN 70.17 76.67 -6.5
The best place for students to learn Applied Engineering 109 [Link]
Two-Sample t-Test for Paired Data
Mean of the differences, 𝑑 = −6.5
Standard Deviation of the differences, 𝑠𝑑 = 15.1
𝑠𝑑
Standard Error of the mean, 𝑆𝐸 𝑑 = = 4.37
𝑛
𝑑 −6.5
𝑡= = = −1.487
𝑆𝐸(𝑑) 4.37
𝑡11,0.025 = 2.20099
Comparing the absolute t-value, we cannot reject
the null hypothesis that the mean transit time
between the two forms of treatment is the same.
The best place for students to learn Applied Engineering 110 [Link]
Two-Sample t-Test for Paired Data
The 95% CI for the mean difference is given by 𝑑 ± 𝑡𝑛−1,𝛼 ∗ 𝑆𝐸(𝑑)
2
−6.5 − 2.201 ∗ 4.37 ≤ 𝐷 ≤ −6.5 + 2.201 ∗ 4.37
95% CI: (-16.1, 3.1).
As zero is included in the CI, we cannot reject the null hypothesis.
Business Decision
Although zero is included in CI, the range is very wide, which
should lead the business to conduct a larger study to be sure.
The best place for students to learn Applied Engineering 111 [Link]
International School of Engineering
Plot 63/A, Floors 1&2, Road # 13, Film Nagar, Jubilee Hills, Hyderabad - 500 033
For Individuals: +91-9502334561/63 or 040-65743991
For Corporates: +91-9618483483
Web: [Link]
Facebook: [Link]
Twitter: [Link]
YouTube: [Link]
SlideShare: [Link]
LinkedIn: [Link]
school-of-engineering
This presentation may contain references to findings of various reports available in the public domain. INSOFE makes no representation as to their accuracy or that the organization
subscribes to those findings.
The best place for students to learn Applied Engineering 112 [Link]