Download Confidence Intervals for the mean

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Degrees of freedom (statistics) wikipedia , lookup

Bootstrapping (statistics) wikipedia , lookup

Taylor's law wikipedia , lookup

Student's t-test wikipedia , lookup

German tank problem wikipedia , lookup

Resampling (statistics) wikipedia , lookup

Misuse of statistics wikipedia , lookup

Transcript
Stats for Engineers Lecture 7
Confidence intervals
During component manufacture, a random sample of 500 are
weighed each day, and each day a 95% confidence interval is
calculated for the mean weight πœ‡ of the components. On the first day
we obtain a confidence interval for the mean weight of 0.998 ±
1.
2.
3.
4.
On 95% of days, the mean weight πœ‡ is in
the range 0.998 ± 0.003 Kg
95% of the daily sample means lie in the
range 0.998 ± 0.003 Kg
On 95% of days the calculated
confidence interval contains πœ‡
95% of the components have weights in
the range 0.998 ± 0.003 Kg
74%
13%
13%
0%
1
2
3
4
Recap: Confidence Intervals for the mean
Random sample 𝑋1 , 𝑋2 , … 𝑋𝑛 from 𝑁 πœ‡, 𝜎 2 , where 𝜎 2 is known [or large data
sample so can estimate it accurately, 𝜎 2 β‰ˆ 𝑠 2 ] but πœ‡ is unknown.
We want a confidence interval for πœ‡.
Reminder: 𝑋 ∼ 𝑁
𝜎2
πœ‡, 𝑛 )
With probability 0.95, a Normal random
variables lies within 1.96 standard deviations
of the mean.
95% of the time expect 𝑋 in πœ‡ ± 1.96
P=0.025
P=0.025
𝜎2
𝑛
𝜎2
𝜎2
𝑋 = πœ‡ ± 1.96
β‡’πœ‡=𝑋±
𝑛
𝑛
A 95% confidence interval for πœ‡ if we measure a sample mean 𝑋 and already know 𝜎 2 is
𝜎2
𝑋 ± 1.96
𝑛
Confidence interval interpretation
During component manufacture, a random sample of
500 are weighed each day, and each day a 95%
confidence interval is calculated for the mean weight πœ‡
of the components. On the first day we obtain a
confidence interval for the mean weight of 0.998 ±
π‘‹βˆΌπ‘
𝜎2
πœ‡, 𝑛
, so 95% of the time the sample mean 𝑋 lies in 𝑋 = πœ‡ ± 1.96
here πœ‡ ± 1.96
𝜎2
𝑛
= πœ‡ ± 0.003
Every day we get a different sample, so different 𝑋.
Confidence interval
e.g.
Day 1:
Day 2:
Day 3:
Day 4:
…
𝑋
𝑋
𝑋
𝑋
= 0.998
= 0.995
= 1.000
= 0.997
95% of the time, 𝑋 is in πœ‡ ± 0.003
𝜎2
𝑛
0.998 ± 0.003
0.995 ± 0.003
1.000 ± 0.003
0.997 ± 0.003
…
β‡’95% of the time, πœ‡ is in X ± 0.003
Other answers?
On 95% of days, the mean weight is in the range 0.998 ± 0.003 Kg
NO - the mean weight πœ‡ is assumed to be a constant.
It is either in the range or it isn’t – if true for one day it will be true for all days
95% of the components have weights in the range 0.998 ± 0.003 Kg
NO – the confidence interval we calculated is for the mean weight, not individual weights
(and 𝑋 β‰  πœ‡ so the mid-point is incorrect)
95% of the daily sample means lie in the range 0.998 ± 0.003 Kg
NO – the correct statement is that 95% of the time 𝑋 lies in πœ‡ ± 0.003 Kg
Statement would only be true if on the first day we got 𝑋 = πœ‡, which has negligible probability
In general can use any confidence level, not just 95%.
95% confidence level has 5% in the tails, i.e. p=0.05 in the tails.
In general to have probability 𝑝 in the tails; for two tail, 𝑝/2 in each tail:
A 100 1 βˆ’ 𝑝 % confidence interval for πœ‡ if we measure a sample mean 𝑋 and
already know 𝜎 2 is 𝑋 ± 𝑧
p/2
𝜎2
𝑛
, where 𝑄 𝑧 = 1 βˆ’ 𝑝/2
p/2
E.g. for a 99% confidence interval, we would want 𝑄 𝑧 = 0.995.
Q
Two tail versus one tail
Does the distribution have two small tails or one? Or are we only interested in upper
or lower limits?
If the distribution is one sided, or we want upper or lower limits, a one tail interval may
be more appropriate.
95% Two tail
95% One tail
P=0.05
P=0.025
P=0.025
Example
You are responsible for calculating average extraurban fuel efficiency figures for new cars. You test
a sample of 100 cars, and find a sample mean of
𝑋 = 55.40mpg. The standard deviation is 𝜎 =
1.2 mpg. What is the 95% confidence interval for
the average fuel efficiency?
Answer:
Sample size if 𝑛 = 100 and 95% confidence interval is 𝑋 ± 1.96
𝜎2
.
𝑛
1.22
β‡’ 55.4 ± 1.96
= 55.4 ± 0.235
100
i.e. mean πœ‡ in 55.165 to 55.63 mpg at 95% confidence
Confidence interval
Given the confidence interval just constructed, it is
correct to say that approximately 95% of new cars
will have efficiencies between 55.165 and 55.63
mpg?
Question from Derek Bruff
1.
2.
3.
4.
YES – high confidence
YES – low confidence
NO – high confidence
NO – low confidence
NO: 𝜎 = 1.2mpg given in the question is the standard
deviation of the individual car efficiencies (i.e. expect
new cars in a range ±1.96𝜎). The confidence interval
we calculated is the range we expect the mean
efficiency to lie in (much smaller range).
0%
1
0%
0%
2
3
0%
4
10
Countdown
Example: Polling
A sample of 1000 random voters were polled, with 350 saying they will vote for the
Conservatives and 650 saying another party. What is the 95% confidence interval for
the Conservative share of the vote?
Answer: this is Binomial data, but large 𝑛 = 1000 so can approximate as Normal
Random variable 𝑋 is the number voting Conservative, 𝑋 ∼ 𝑁 πœ‡, 𝜎 2 )
350
Take variance from the Binomial result with 𝑝 β‰ˆ 1000 = 0.35
𝜎 2 = 𝑛𝑝 1 βˆ’ 𝑝 β‰ˆ 1000 × 0.35 × 1 βˆ’ 0.35 = 227.5
β‡’ 𝜎 = 227.5 β‰ˆ 15.1
95% confidence interval for the total votes is
350 ± 1.96𝜎 = 350 ± 1.96 × 15.1 = 350 ± 29.6
β‡’ 95% confidence interval for the fraction of the votes is
350 ± 29.6
β‰ˆ 0.35 ± 0.03
1000
i.e. ±3% confidence interval
Example – variance unknown
A large number of steel plates will be used to
build a ship. A sample of ten are tested and found
to have sample mean 𝑋 = 2.13kg and sample
variance 𝑠 2 = 0.25 kg 2 . What is the 95%
confidence interval for the mean weight πœ‡?
Reminder:
Sample Variance:
𝑠2 =
2
2
𝑖 𝑋𝑖 βˆ’π‘›π‘‹
π‘›βˆ’1
Normal data, variance unknown
Random sample 𝑋1 , 𝑋2 , … 𝑋𝑛 from 𝑁 πœ‡, 𝜎 2 , where 𝜎 2 and πœ‡ are both unknown.
Want a confidence interval for πœ‡, using observed sample mean and variance.
π‘‹βˆ’πœ‡
𝑛
When we know the variance: use 𝑧 = 𝜎/
which is normally distributed
Remember: 𝑋 ∼ 𝑁 πœ‡,
But don’t know 𝜎 2 , so have to use sample estimate 𝑠 2
π‘‹βˆ’πœ‡
𝑛
When we don’t know the variance: use 𝑑 = 𝑠/
which has a t-distribution
(with 𝑛 βˆ’ 1 d.o.f)
Sometimes more fully as β€œStudent’s t-distribution”
Wikipedia
𝜎2
𝑛
𝜈 =π‘›βˆ’1=1
𝜈 =π‘›βˆ’1=5
𝜈 = 𝑛 βˆ’ 1 = 50
Normal
t-distribution
For large 𝑛 the t-distribution tends to the Normal
- in general broader tails
Confidence Intervals for the mean
2
If 𝜎 is known, confidence interval for πœ‡ is 𝑋 βˆ’ 𝑧
𝜎2
𝑛
to 𝑋 + 𝑧
𝜎2
,
𝑛
where 𝑧
is obtained from Normal tables (z=1.96 for two-tailed 95% confidence limit).
If 𝜎 2 is unknown, we need to make two changes:
(i) Estimate 𝜎 2 by 𝑠 2 , the sample variance;
(ii) replace z by π‘‘π‘›βˆ’1 , the value obtained from t-tables,
The confidence interval for πœ‡ if we measure a sample mean 𝑋 and
sample variance
𝑠2
is: 𝑋 βˆ’ π‘‘π‘›βˆ’1
𝑠2
𝑛
to 𝑋 + π‘‘π‘›βˆ’1
𝑠2
.
𝑛
t-tables
give π‘‘πœˆ for different values Q of the cumulative Student's t-distributions, and
for different values of 𝜈
π‘‘πœˆ
𝑄 π‘‘πœˆ ) =
π‘“πœˆ 𝑑 𝑑𝑑
βˆ’βˆž
The parameter 𝜈 is called the
number of degrees of
freedom.
(when the mean and
variance are unknown, there
are 𝑛 βˆ’ 1 degrees of
freedom to estimate the
variance)
Q
π‘‘πœˆ
Q
π‘‘πœˆ
For a 95% confidence interval, we want the
middle 95% region, so Q = 0.975
(0.05/2=0.025 in both tails).
Similarly, for a 99% confidence interval, we
would want Q = 0.995.
t-distribution example:
A large number of steel plates will be used to
build a ship. A sample of ten are tested and
found to have sample mean 𝑋 = 2.13kg and
sample variance 𝑠 2 = 0.25 kg 2 . What is
the 95% confidence interval for the mean
weight πœ‡?
Answer:
From t-tables, 𝜈 = 𝑛 βˆ’ 1 = 9 for Q = 0.975
𝑑9 = 2.2622.
95% confidence interval for πœ‡ is:
πœ‡ = 𝑋 ± π‘‘π‘›βˆ’1
𝑠2
𝑛
0.252
β‡’ πœ‡ = 2.13 ± 2.2622
= 2.13 ± 0.18 kg
10
i.e. 1.95 to 2.31
Confidence interval width
We constructed a 95% confidence interval for the mean
using a random sample of size n = 10 with sample mean
𝑋 = 2.13kg . Which of the following conditions would
NOT probably lead to a narrower confidence interval?
Question adapted from
Derek Bruff
1.
2.
3.
4.
If you decreased your confidence
level
If you increased your sample size
If the sample mean was smaller
If the population standard
deviation was smaller
48%
33%
14%
5%
1
2
3
4
Confidence interval width
We constructed a 95% confidence interval for the mean
using a random sample of size n = 10 with sample mean
𝑋 = 2.13kg . Which of the following conditions would
NOT probably lead to a narrower confidence interval?
95% confidence interval for πœ‡ is:πœ‡ = 𝑋 ± π‘‘π‘›βˆ’1
𝑠2
;
𝑛
width is 2π‘‘π‘›βˆ’1
𝑠2
𝑛
Decrease your confidence level?
β‡’ larger tail β‡’ smaller π‘‘πœˆ β‡’ smaller confidence interval
Increase your sample size?
𝑠2
β‡’ 𝑛 larger β‡’ smaller confidence interval ( 𝑛 and π‘‘π‘›βˆ’1 both likely to be smaller)
Smaller sample mean?
β‡’ 𝑋 smaller β‡’ just changes mid-point, not width
Smaller population standard deviation?
β‡’ 𝑠 2 likely to be smaller β‡’ smaller confidence interval
Sample size
How many random samples do you need to reach desired level of precision?
For example, for Normal data, confidence interval for πœ‡ is 𝑋 ± π‘‘π‘›βˆ’1
𝑠2
.
𝑛
Suppose we want to estimate πœ‡ to within ±π›Ώ, where 𝛿 (and the degree of
confidence) is given.
Want
𝛿 = π‘‘π‘›βˆ’1
𝑠2
𝑛
2
π‘‘π‘›βˆ’1
𝑠2
⇒𝑛=
𝛿2
Need:
- Estimate of 𝑠 2 (e.g. previous experiments)
- Estimate of π‘‘π‘›βˆ’1 . This depends on n, but not very strongly.
e.g. take π‘‘π‘›βˆ’1 = 2.1 for 95% confidence.
Rule of thumb: for 95% confidence, choose 𝑛 =
2.12 ×Estimate of variance
Ξ΄2
Example
A large number of steel plates will be used to
build a ship. Ten are tested and found to have
sample mean weight 𝑋 = 2.13kg and sample
variance 𝑠 2 = 0.25 kg 2 . How many need to be
tested to determine the mean weight with 95%
confidence to within ±0.1 kg?
Answer:
Want
𝛿 = 0.1kg = π‘‘π‘›βˆ’1
𝑠2
𝑛
Take π‘‘π‘›βˆ’1 = 2.1 for 95% confidence.
2
π‘‘π‘›βˆ’1
𝑠 2 2.12 0.252
⇒𝑛=
=
= 27.6
𝛿2
0.12
i.e. need to test about 28
Number of samples
If you need 28 samples for the confidence interval
to be ±0.1 kg, approximately how many samples
would you need to get a more accurate answer
with confidence interval ±0.01 kg?
1.
2.
3.
4.
88.5
280
2800
28000
39%
28%
17%
𝛿 = π‘‘π‘›βˆ’1
𝛿
β‡’ 10 = π‘‘π‘›βˆ’1
17%
𝑠2
𝑛
𝑠2
100𝑛
so need 100 × more. i.e. 2800
1.
2
3
4
Linear regression
We measure a response variable 𝑦 at various values of a controlled variable π‘₯
e.g. measure fuel efficiency 𝑦 at various values of an experimentally controlled external temperature π‘₯
250
200
y
150
100
0
10
20
30
40
x
Linear regression: fitting a straight line to the mean value of 𝑦 as a function of π‘₯
𝑦 = π‘Žπ‘₯ + 𝑏
𝑦
Distribution of
𝑦 when π‘₯ = π‘₯1
π‘₯1
π‘₯2
π‘₯3
π‘₯
Regression curve:
fits the mean values of the 𝑦 distributions
From a sample of 𝑦 values at various π‘₯, we want to fit the regression curve.
e.g.
250
200
y
150
100
0
10
30
20
x
40
Or is it
250
200
y
150
100
0
10
30
20
40
x
What do we mean by a line being a β€˜good fit’?
𝑦
Straight line plots
Which graph is of the line 𝑦 = 2π‘₯ βˆ’ 4?
1.
π‘₯
2.
56%
3.
33%
4.
11%
0%
1
2
3
4
Equation of straight line is 𝑦 = π‘Ž + 𝑏π‘₯
Simple model for data:
𝑦𝑖 = π‘Ž + 𝑏 π‘₯𝑖 + 𝑒𝑖
Straight line
Random error
Simplest assumption: 𝑒𝑖 ∼ 𝑁 0, 𝜎 2 ) for all 𝑖, and 𝑒𝑖 's are independent
- Linear regression model
Model is 𝑦𝑖 = π‘Ž + 𝑏 π‘₯𝑖 + 𝑒𝑖
Want to estimate parameters a and b, using the data.
e.g. - choose π‘Ž and 𝑏 to minimize the errors
Maximum likelihood estimate = least -squares estimate
Minimize
𝑒𝑖2 =
𝐸=
𝑖
𝑦𝑖 βˆ’ 𝑦𝑖 ) =
𝑖
𝑦𝑖 βˆ’ π‘Ž βˆ’ 𝑏π‘₯𝑖
2
𝑖
Data point
Straight-line prediction
E is defined and can be minimized even when errors not Normal
– least-squares is simple general prescription for fitting a straight line
(but statistical interpretation in general less clear)
The line 𝑦 = 4 + 2π‘₯ has been proposed as a line of best fit for
the following four sets of data. For which data set is this line the
best fit (minimum 𝐸 = 𝑖 𝑒𝑖2 )?
Question from Derek Bruff
1.
2.
57%
3.
4.
24%
19%
0%
1
2
3
4
2
𝑖 𝑒𝑖
How to find π‘Ž and 𝑏 that minimize 𝐸 =
πœ•πΈ
=
𝑦𝑖 βˆ’ π‘Ž βˆ’ 𝑏π‘₯𝑖
𝑖
2
?
πœ•πΈ
For minimum want πœ•π‘Ž = 0 and πœ•π‘ = 0, see notes for derivation
Solution is the least-squares estimates π‘Ž and 𝑏:
𝑆π‘₯𝑦
and π‘Ž = 𝑦 βˆ’ 𝑏 π‘₯
𝑆π‘₯π‘₯
𝑏=
Sample means
Where
π‘₯𝑖2
𝑆π‘₯π‘₯ =
𝑖 π‘₯𝑖
βˆ’
𝑛
𝑖
𝑆π‘₯𝑦 =
π‘₯𝑖 𝑦𝑖 βˆ’
𝑖
2
𝑖 π‘₯𝑖
𝑛
𝑖 𝑦𝑖
=
π‘₯𝑖 βˆ’ π‘₯
2
𝑖
=
π‘₯𝑖 βˆ’ π‘₯) 𝑦𝑖 βˆ’ 𝑦
𝑖
Equation of the fitted line is 𝑦 = π‘Ž + 𝑏π‘₯
Note that since π‘Ž = 𝑦 βˆ’ 𝑏 π‘₯
𝑦 = π‘Ž + 𝑏π‘₯
= 𝑦 βˆ’ 𝑏π‘₯ + 𝑏π‘₯
β‡’ 𝑦 βˆ’ 𝑦 = 𝑏 π‘₯ βˆ’ π‘₯)
i.e. π‘₯, 𝑦) is on the line
250
200
y 𝑦
150
100
0
10
20
π‘₯
x
30
40
Example:
The data y has been observed for various values of x, as
follows:
y
x
240
1.6
181
9.4
193
15.5
155
20.0
172
22.0
110
35.5
113
43.0
75
40.5
94
33.0
Fit the simple linear regression model using least squares.
Answer:
2
𝑖 π‘₯𝑖
𝑖 𝑦𝑖
= 1333.0
2
𝑖 𝑦𝑖
= 7053.7,
𝑆π‘₯π‘₯
= 220549,
220.52
= 7053.7 βˆ’
9
𝑆π‘₯𝑦 = 26864 βˆ’
⇒𝑏=
π‘₯𝑖2
𝑆π‘₯π‘₯ =
𝑖 π‘₯𝑖 𝑦𝑖
= 26864
= 1651.42
220.50 × 1333.0
= βˆ’5794.1
9
𝑆π‘₯𝑦
5794.5
=βˆ’
𝑆π‘₯π‘₯
1651.45
= βˆ’3.5086
βˆ’
𝑖
𝑆π‘₯𝑦 =
π‘₯𝑖 𝑦𝑖 βˆ’
𝑖
Want to fit 𝑦 = π‘Ž + 𝑏π‘₯
n=9
𝑖 π‘₯𝑖 = 220.5 ,
𝑆π‘₯𝑦
𝑏=
and π‘Ž = 𝑦 βˆ’ 𝑏 π‘₯
𝑆π‘₯π‘₯
𝑖 π‘₯𝑖
2
𝑛
𝑖 π‘₯𝑖
𝑛
𝑖 𝑦𝑖
Answer:
𝑆π‘₯𝑦
𝑏=
and π‘Ž = 𝑦 βˆ’ 𝑏 π‘₯
𝑆π‘₯π‘₯
Want to fit 𝑦 = π‘Ž + 𝑏π‘₯
n=9
𝑖 π‘₯𝑖 = 220.5 ,
2
𝑖 π‘₯𝑖
𝑖 𝑦𝑖
𝑆π‘₯π‘₯
= 220549,
220.52
= 7053.7 βˆ’
9
𝑆π‘₯𝑦 = 26864 βˆ’
⇒𝑏=
𝑆π‘₯π‘₯ =
= 1333.0
2
𝑖 𝑦𝑖
= 7053.7,
𝑖 π‘₯𝑖 𝑦𝑖
𝑆π‘₯𝑦 =
= 1651.42
220.50 × 1333.0
= βˆ’5794.1
9
𝑆π‘₯𝑦
5794.5
=βˆ’
𝑆π‘₯π‘₯
1651.45
= βˆ’3.5086
π‘Ž = 𝑦 βˆ’ 𝑏π‘₯
1333.0
220.50
βˆ’ βˆ’3.5086) ×
= 234.1
9
9
So the fit is approximately
𝑦 = 234.1 βˆ’ 3.509π‘₯
βˆ’
𝑖
= 26864
Now just need π‘Ž
=
π‘₯𝑖2
π‘₯𝑖 𝑦𝑖 βˆ’
𝑖
𝑖 π‘₯𝑖
2
𝑛
𝑖 π‘₯𝑖
𝑛
𝑖 𝑦𝑖
Which of the following data are likely to be most appropriately
modelled using a linear regression model?
1.
2.
55%
3.
25%
20%
1
2
3
Quantifying the goodness of the fit
Estimating 𝝈𝟐 : variance of y about the fitted line
Estimated error is: 𝑒𝑖 = 𝑦𝑖 βˆ’ 𝑦𝑖
1
πœ‡π‘’ = 0, so the ordinary sample variance of the 𝑒𝑖 's is ∼ π‘›βˆ’1
2
𝑖 𝑒𝑖
In fact, this is biased since two parameters, a and b have been estimated. The
unbiased estimate is:
𝜎2 =
1
π‘›βˆ’2
𝑒𝑖2 =
=
1
π‘›βˆ’2
𝑦𝑖 βˆ’ 𝑦𝑖
𝑆𝑦𝑦 βˆ’ 𝑏𝑆π‘₯𝑦
π‘›βˆ’2
2
[derivation in notes]
Residual sum of squares
Which of the following plots would have the greatest residual sum
of squares [variance of 𝑦 about the fitted line]?
Question from Derek Bruff
1.
2.
3.
72%
11%
1
17%
2
3
Confidence interval for the slope, b
E.g. if you want to see if 𝑏 is significantly non-zero
Reminder: Normal data with unknown variance, confidence interval for πœ‡ is:
X ο€­ t n ο€­1
s2
n
to
X  t n ο€­1
s2
n
𝑠 2 /𝑛 is the estimate of 𝜎 2 /𝑛, the variance of 𝑋
It can be shown that var 𝑏 =
𝜎2
,
𝑆π‘₯π‘₯
estimated by
𝜎2
𝑆π‘₯π‘₯
Confidence interval for b is
 2
ο€€
b ο€­ t n ο€­2
S xx
to
 2
ο€€
b  t n ο€­2
S xx
(𝑛 βˆ’ 2 degrees of freedom).
Predictions
For given π‘₯ of interest, what is mean 𝑦?
250
200
y
Predicted mean value: 𝑦 = π‘Ž + 𝑏π‘₯.
150
100
0
What is the error bar?
It can be shown that
var 𝑦 π‘₯ = var π‘Ž + 𝑏π‘₯
1
π‘₯βˆ’π‘₯ 2
2
=𝜎
+
𝑛
𝑆π‘₯π‘₯
Confidence interval for mean y at given x
𝑦 ± π‘‘π‘›βˆ’2
1
𝜎2 𝑛
+
π‘₯βˆ’π‘₯ 2
𝑆π‘₯π‘₯
Extrapolation: Often not reliable
10
20
x
30
40