Professional Documents
Culture Documents
Batch38 CSE7315c ConfInt HypTest TDist
Batch38 CSE7315c ConfInt HypTest TDist
Stat Skills
Confidence Intervals, t-
Distribution, Hypothesis Testing,
t-Tests
Dr. Anand Jayaraman
Jan 6, 2018
Thanks to Dr.Sridhar Pappu for the material
The best place for students to learn Applied Engineering http://www.insofe.edu.in
Review
• Probability Distributions
– Bernoulli, Geometric, Binomial, Poisson,
Exponential
• Gaussian Distribution
– Areas under the curve
– Reading the normal distribution table
– Approximating B(n,p) with Normal
distribution
– Continuity correction
• Central Limit Theorem
𝜎
What are we trying to find out?
𝜇 𝜇𝑋ത = 𝜇
We need to know if population mean, 𝜇, is within ±12g of the sample
ത
mean, 𝑋.
ത is
This is the same as saying that we need to know if sample mean, 𝑋,
within ±12g of the population mean, 𝜇. Since 𝜇 = 𝜇𝑋ത , we can now use the
sampling distribution of the means.
Source: https://www.khanacademy.org/math/probability/statistics-inferential/confidence-intervals/v/confidence-interval-1
Last accessed: May 9, 2014
The best place for students to learn Applied Engineering 4 http://www.insofe.edu.in
Sampling Distribution
𝑃𝑜𝑝𝑢𝑙𝑎𝑡𝑖𝑜𝑛 𝑑𝑖𝑠𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑆𝑎𝑚𝑝𝑙𝑖𝑛𝑔 𝑑𝑖𝑠𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑜𝑓 𝑠𝑎𝑚𝑝𝑙𝑒 𝑚𝑒𝑎𝑛 𝑤ℎ𝑒𝑛 𝑛 = 36
𝜇 𝜇𝑋ത = 𝜇
We need to find out how many standard deviations away from 𝜇𝑋ത is 12g. But, we don’t know 𝜎𝑋ത
because we don’t know 𝜎. We use the sample standard deviation, s (40g), as the best estimate of
𝜎 40
population standard deviation. 𝜎 ≈ 𝑠 = ±40𝑔. ∴ 𝜎𝑋ത = 6 = 6 = 6.67. So 12g is 12/6.67 = 1.8
standard deviations.
The z-table gives the probability as 0.9641 but that is the entire region below +1.8 z.
Find the region between -1.8 and +1.8 z.
0.9282. How would you get this answer if you did not have the negative z table?
Source: https://www.khanacademy.org/math/probability/statistics-inferential/confidence-intervals/v/confidence-interval-1
Last accessed: May 9, 2014
The best place for students to learn Applied Engineering 5 http://www.insofe.edu.in
Normal Distribution
(0.9641-0.5000)*2
= 0.4641*2
= 0.9282
Source: http://en.wikipedia.org/wiki/Indian_general_election,_2014
Last accessed: March 27, 2015
𝜎
𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐸𝑟𝑟𝑜𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑀𝑒𝑎𝑛 =
𝑛
𝜎
𝜇 𝜇𝑋ത = 𝜇
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.
𝜎
𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐸𝑟𝑟𝑜𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑀𝑒𝑎𝑛 =
𝑛
𝜇𝑋ത = 𝜇
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).
ҧ
𝑥−𝜇 𝜎
𝑧= 𝜎 or Margin of error = 𝑧 ∗
𝑛
𝑛
0.90
0.05 0.05
za 0 zb
Check qnorm(0.05, 0, 1)
and qnorm(0.95, 0, 1) in
R.
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 16 http://www.insofe.edu.in
SE, Margin of Error, Confidence Interval and Sample
Size
Just like Mean, Proportion is another common parameter of
interest in many problems.
Source: https://en.wikipedia.org/wiki/Margin_of_error
Last accessed: June 18, 2015
The best place for students to learn Applied Engineering 18 http://www.insofe.edu.in
SE, Margin of Error, Confidence Interval and Sample
Size
In a poll by FOX News conducted
between Oct 22 – 24, 2017, a
survey of 1005 randomly
sampled voters showed that the
approval rating for president
Trump down to 38%.
0.38 ∗ 0.62
0.01 = 1.96 ∗
𝑛
2
1.96
∴𝑛= ∗ 0.38 ∗ 0.62 = 9050
0.01
You know σ2 𝜎 𝜎
µ Normal n is large or small (𝑋ത − 𝑧 , 𝑋ത +𝑧 )
𝑛 𝑛
𝑋ത is the sample mean
You know σ2 𝜎 𝜎
µ Non-normal n is large (> 30) (𝑋ത − 𝑧 , 𝑋ത +𝑧 )
𝑛 𝑛
𝑋ത is the sample mean
You don’t know σ2 𝑠 𝑠
Normal or n is large (> 30) (𝑋ത − 𝑧 , 𝑋ത +𝑧 )
µ 𝑛 𝑛
Non-normal 𝑋ത is the sample mean
s2 is the sample variance
n is large
𝑝𝑠 𝑞𝑠 𝑝𝑠 𝑞𝑠
p Binomial ps is the sample proportion (𝑝𝑠 − 𝑧 , 𝑝𝑠 +𝑧 )
𝑛 𝑛
qs is 1 - ps
The best place for students to learn Applied Engineering 21 http://www.insofe.edu.in
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.67 0.67
95% 𝐶𝐼: 4.062 − 1.96 ∗ , 4.062 + 1.96 ∗
57 57
= (3.89,4.23)
𝜎 𝜎
(𝑋ത − 𝑧 , 𝑋ത +𝑧 )
𝑛 𝑛
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.
Ref: http://image.slidesharecdn.com/2013-ingenious-ireland-theingeniousirishiet-slideshow-130524065705-phpapp01/95/2013-
ingeniousirelandthe-ingenious-irishietslideshow-43-638.jpg?cb=1369825611
Last accessed: October 31, 2015
The best place for students to learn Applied Engineering 30 http://www.insofe.edu.in
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.
Source: https://en.wikipedia.org/wiki/Student%27s_t-distribution
Last accessed: Apr 8, 2017
The best place for students to learn Applied Engineering 32 http://www.insofe.edu.in
t-Distribution
(𝑥ҧ − 𝜇)
𝑡 𝑠𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 𝑜𝑟 𝑡 𝑠𝑐𝑜𝑟𝑒 , 𝑡 = 𝑠
𝑛
Degrees of freedom, ν: # of independent observations for a
source of variation minus the number of independent parameters
estimated in computing the variation.*
* Roger E. Kirk, Experimental Design: Procedures for the Behavioral Sciences. Belmont, California: Brooks/Cole, 1968.
– 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).
𝑡9,0.025 = 2.262
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 40 http://www.insofe.edu.in
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
Mean
CD4 25 321.4 14.8 73.8 208.0 261.5 325.0 394.0 449.0
(cells/𝜇l)
𝑠
Margin of Error ME = 𝑡𝑛−1,𝛼 𝑛
2
𝐶𝐼 0.05 : 𝑥ҧ − 𝑀𝐸 ≤ 𝜇 ≤ 𝑥ҧ + 𝑀𝐸
321.4 − 𝑀𝐸 ≤ 𝜇 ≤ 321.4 + 𝑀𝐸
73.8
ME = 𝑡25−1,0.05
2 25
The best place for students to learn Applied Engineering 42 http://www.insofe.edu.in
t-table
73.8
ME = 𝑡25−1,0.05 = 30.46
2 25
321.4 − 𝑀𝐸 ≤ 𝜇 ≤ 321.4 + 𝑀𝐸
∴ 𝐶𝐼(0.05): [290.85,351.95]
This far?
This far?
This far?
Claim or Expectation, say, mean score=7/10
Sample size = 40
Normal distribution is a good approximation
𝑠 1.0
Std Err = = = 0.158
𝑛 40
X ~ N(0.7, 0.1582 ) = N(0.7, 0.025)
ҧ
𝑥−𝜇 0.55−0.7
𝑧= 𝜎 = = -0.94
0.158
𝑛
This far?
This far?
This far?
Claim or Expectation, say, 7/10 mean score
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 0.7 is the mean score 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.
Critical Region
17.1%
There isn’t sufficient evidence to reject the null hypothesis and so,
the claims of the principal are accepted.
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.
c
α 100%-α
100%-α α
c1 c2
α/2 100%-α α/2
What can you now say about the coin being biased or
not? c=15
100%-α? α?
α State of Nature
Null true Null false
Fail to reject Correct decision Type II error (β)
null (negative) True Negative False Negative
P(Type I error) = α Specificity
Action Reject null Type I error (α) Correct decision (Power)
(positive) False Positive True Positive
Sensitivity/Recall
Action
1. Check that you have a specific value for H1. Reject null Type I error (α) Correct decision (Power)
(positive) False Positive True Positive
ҧ
𝑥−𝜇
𝑧= 𝜎 < -1.34 µ=50, σ = 21 & 𝑛 = 36
𝑛
𝑥ҧ < 45.31
Img src: https://www.youtube.com/watch?v=BJZpx7Mdde4
The best place for students to learn Applied Engineering 76 http://www.insofe.edu.in
Null hypothesis is rejected when the sample average 𝑥ҧ < 45.31
ҧ
𝑥−𝜇 45.31−43
𝑧= 𝜎 = 21 = 0.66
𝑛 36
Type-2 Error:
β = P(Not reject H0 | µ=43 ) = P(Z > 0.66) = 0.255
Img src: https://www.youtube.com/watch?v=BJZpx7Mdde4
The best place for students to learn Applied Engineering 81 http://www.insofe.edu.in
Power of Hypothesis Test
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 null Type I error (α) Correct decision (Power)
(positive) False Positive True Positive
P(Reject H0 | H0 True) Sensitivity/Recall
P(Reject H0 | H0 False)
To study if their means are the same – we can create a new data
set from the difference of the individual data points.
Xnew = X1 – X2
We can then look at how far away from zero is the mean E(Xnew )
𝑋𝑛𝑒𝑤 − 0
𝑡=
𝑆𝐸(𝑋𝑛𝑒𝑤)
Significance level
𝛼 =0.05
Test statistic?
𝑡𝑛−1,𝛼 (for two − tailed we would use 𝑡𝑛−1,𝛼 )
2
𝑡11,0.05 = 1.795885
𝜎1 2 𝜎2 2
and 𝜎𝑥1 −𝑥2 = + [Recall Var(X-Y)=Var(X)+Var(Y)]
𝑛1 𝑛2
The control group were asked to follow their usual routine while
the other group was exposed to 1-hour of his lecture on t-
distribution shortly after dinner. The time taken to sleep was
measured for each group.
The best place for students to learn Applied Engineering 100 http://www.insofe.edu.in
Two sample t-test
Time taken to sleep (hr)
Treated Subjects Control 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 101 http://www.insofe.edu.in
Hypothesis Testing
What is the null hypothesis?
𝐻0 : 𝜇1 − 𝜇2 = 0 (The lecture has no impact)
The best place for students to learn Applied Engineering 102 http://www.insofe.edu.in
Two sample t-test
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
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 103 http://www.insofe.edu.in
Hypothesis Testing
Will you reject the null hypothesis or fail to do so?
Reject. That means lecture does affect the time-to-sleep.
The best place for students to learn Applied Engineering 104 http://www.insofe.edu.in
Confidence Intervals
1 1
Margin of Error ME= 𝑡𝑛−1,𝛼 ∗S.E = 𝑡𝑛−1,𝛼 ∗ 𝑠𝑝 +
2 2 𝑛1 𝑛2
=2.048*0.0763 = 0.156
𝑥1 − 𝑥2 − 𝑀𝐸 ≤ 𝜇1 − 𝜇2 ≤ 𝑥1 − 𝑥2 + 𝑀𝐸
0.298 − 0.156 ≤ 𝜇1 − 𝜇2 ≤ 0.298 + 0.156
The best place for students to learn Applied Engineering 106 http://www.insofe.edu.in
Summary
• Confidence Intervals
• t-Distribution
• Hypothesis testing
• Two-sample t-Tests
The best place for students to learn Applied Engineering 107 http://www.insofe.edu.in
Resources
• Standard deviation – why use (n-1) instead of n?
– https://www.khanacademy.org/video/review-and-intuition-why-we-divide-by-n-1-for-
the-unbiased-sample-variance
– http://nebula.deanza.edu/~bloom/math10/m10divideby_nminus1.pdf
The best place for students to learn Applied Engineering 108 http://www.insofe.edu.in
HYDERABAD BENGALURU
2nd Floor, Jyothi Imperial, Vamsiram Builders, Old L77, 15th Cross Road, 3rd Main Road, Sector 6,
Mumbai Highway, Gachibowli, Hyderabad - 500 032 HSR Layout, Bengaluru – 560 102
+91-9701685511 (Individuals) +91-9502334561 (Individuals)
+91-9618483483 (Corporates) +91-9502799088 (Corporates)
Social Media
Web: http://www.insofe.edu.in
Facebook: https://www.facebook.com/insofe
Twitter: https://twitter.com/Insofeedu
YouTube: http://www.youtube.com/InsofeVideos
SlideShare: http://www.slideshare.net/INSOFE
LinkedIn: http://www.linkedin.com/company/international-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 109 http://www.insofe.edu.in