Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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