MAT2377 Rafa l Kulik Version 2015/November/23 Rafa l Kulik
Rafa l Kulik 1
Rafa l Kulik 2
Rafa l Kulik 3
Rafa l Kulik 4
The Z-test Test on the mean of a normal distribution, σ known Suppose X 1,..., X n is a random sample from a population with mean µ and variance σ 2, and let X = 1 n n i=1 X i denote the sample mean. If the population is normal, then X exact N (µ, σ 2 /n) ; Even if the population is not normal, if n is large enough then by the approx Central Limit Theorem X N (µ, σ 2 /n). We will assume that the population variance σ 2 is known, but the hypothesis concerns the unknown population mean µ. Rafa l Kulik 5
We are going to test H 0 : µ = µ 0, where µ 0 is a constant. Step 1: H 0 : µ = µ 0 Step 2: Choose H A as one of 1. H A : µ < µ 0 (one-sided test) 2. H A : µ > µ 0 (one-sided test) 3. H A : µ µ 0 (two-sided test) The form of hypotheses will depend on what we try to show or to conclude. As alternative, we choose what we try to demonstrate by data. Rafa l Kulik 6
Examples: 1. Suppose that an old method of production yields 100 articles/day on average. We want to introduce a new method which is supposed to be more effective (in other words, the average daily production will be bigger than 100). The appropriate test is H 0 : µ = 100 vs. H A : µ > 100. 2. Suppose that a manufacturer states that the mean lifetime of tires is 60,000km. A group of customers believes that the mean is lower than 60,000km. The appropriate test is H 0 : µ = 60, 000 vs. H A : µ < 60, 000. Rafa l Kulik 7
3. A physician is interested whether a particular drug has significant effect on a blood pressure. He measures blood pressure after the treatment and compares with the usual one of 110. The appropriate test is H 0 : µ = 110 vs. H A : µ 110. In the first case we may reject H 0 only if a sample mean is much bigger than 100. In the second, only if a sample mean is much smaller than 60,000. In the last case, we may reject H 0 if a sample mean is much smaller or much bigger than 110. In the first case, if we reject H 0, we have strong evidence that the new method improves. If we formulate H A in the first case as H A : µ 100, then me may reject H 0 if the sample mean is small. If we reject H 0, then the only meaning of it is that the new method is different. Rafa l Kulik 8
Step 3: Choose α - probability of type I error: α = P (reject H 0 H 0 is true). Typically α = 0.01, 0.05. Step 4: Computation of the test statistics X. Step 5: Calculation of p-value by comparing the test statistics with the observed value of the test statistics. Rafa l Kulik 9
Examples 1. Components are manufactured to have strength normally distributed with mean µ = 40 units and standard deviation σ = 1.2 units. A modification have been tried, for which an increase in mean strength is claimed (the standard deviation remains the same). A random sample of n = 12 components produced using the modified process had strength 42.5, 39.8, 40.3, 43.1, 39.6, 41.0, 39.9, 42.1, 40.7, 41.6, 42.1, 40.8, Do the data provide strong evidence that the mean strength exceeds 40 units? (Use α = 0.05) Rafa l Kulik 10
Step 1 H 0 : µ = 40 Step 2 H A : µ > 40 Computation of p-value: Observed value of the sample mean is x = 41.125. Hence p-value = P ( X 41.125) = P ( X 41.125) ( X µ0 = P σ/ n 41.125 µ ) 0 σ/ = P (Z 3.25) 0.006. n So, p-value is smaller than α - reject H 0. If the model µ = 40 is true, the event { X 41.125} is very unlikely. Rafa l Kulik 11
2. A set of scales is working acceptably if the measurement differs from the true weight by a normally distributed random error with sd σ = 0.007 grams. It is suspected that the scale is over-reading. To test it, 10 measurements are made on a 1.0 gram gold-standard weight, giving a set of measurements which average out to 1.0038g. Is this the evidence that the scale is over-reading? (Use α = 0.05 and then α = 0.01) Step 1 and 2 H 0 : µ = 1.0 vs. H A : µ > 1.0 Computation of p-value: Observed value of the sample mean is x = 1.0038. Hence p-value = P ( X 1.0038) = P = P ( Z 0.0038 0.007/ 10 ( X µ0 σ/ n 1.0038 µ 0 σ/ n Do not reject H 0 for α = 0.01, do reject H 0 for α = 0.05. ) ) 1 Φ(1.7166) 0.043. Rafa l Kulik 12
3. In the previous example, let s assume that we are interested whether the scales work properly (which means that both under-reading and over-reading are not acceptable). Step 1 H 0 : µ = 1.0; Step 2 H A : µ 1.0 Computation of p-value: Observed value of the sample mean is x = 1.0038. Hence p-value = 2 P ( X 1.0038) = 2 P = 2 P ( Z 0.0038 ) 0.007/ 10 ( X µ0 σ/ n 1.0038 µ ) 0 σ/ n 0.086 Do not reject H 0 for α = 0.01, do not reject H 0 for α = 0.05. Rafa l Kulik 13
4. An average class marks are normally distributed with mean µ = 60 and variance σ 2 = 100. Nine students are selected from the class and their average mark was 55. Test, whether this class is below average. Solution: Step 1 H 0 : µ = 60 Step 2 H A : µ < 60 Computation of p-value P ( X 55) = P ( Z ) 55 60 10/ 9 = 0.07. There is not enough evidence to reject the claim that the class is average, regardless whether we use α = 0.05 or α = 0.01. Rafa l Kulik 14
5. An average class marks have mean µ = 60 and variance σ 2 = 100. 100 students are selected from the class and their average mark was 55. Test, whether this class is below average. Solution: Step 1 H 0 : µ = 60 Step 2 H A : µ < 60 Computation of p-value P ( X 55) = P ( Z 55 60 10/ 100 ) = 0 We reject the claim that the class is average for either choice of α. Rafa l Kulik 15
Tests and confidence intervals If α is given, then we reject H 0 : µ = µ 0 in favor of H A : µ µ 0 only if µ is not in the (1 α) confidence interval for µ 0. Example: A manufacturer claims that a particular type of an engine uses 20 gallons of fuel to operate for one hour. From previous studies it is known that the amount of fuel used per hour is normally distributed with variance σ 2 = 25. A sample of size n = 9 has been taken and the following value has been obtained: x = 23. Should we accept the manufacturer s claim? Use α = 0.05. Step 1 H 0 : µ = 20 Step 2 H A : µ 20 Rafa l Kulik 16
Computation of p-value p-value = 2 P ( X 23) = 2 P ( X 23) = 2 P ( X µ0 σ/ n 23 µ ) 0 σ/ n = 2 P (Z 1.8) 2 0.036 = 0.072. Do not reject H 0 since p-value is bigger than α. Confidence interval: x ± z α/2 σ/ n = 23 ± 1.96 5/ 9 = (19.73; 26.26). We will not reject the claim that µ = 20, µ = 19.74, µ = 26.20 etc. Indeed, let s consider H 0 : µ = 26.20 vs. H A : µ 26.20. Then the observed value of z 0 = x µ 0 σ/ n = 1.92. Now, z 0 < 1.96 = z α/2. Rafa l Kulik 17
Example: We are interested in the mean burning rate of a solid propellant used to power aircrew escape systems. We want to determine whether or not the mean burning rate is 50 cms/second. The sample of 10 specimens is tested and we observe x = 48.5. Assume normality and σ = 2.5. Solution: Step 1 H 0 : µ = 50 Step 2 H A : µ 50 Step 5 p-value = 2 P ( X 48.5) = 2 P ( X 48.5) = 2 P Do not reject H 0 for α = 0.01, reject for α = 0.05. ( X µ0 σ/ n x µ ) 0 σ/ n = 2 P (Z 2.4) 2 0.0082 = 0.0164. Rafa l Kulik 18
t-test If data are normal and σ is unknown we can estimate it by S = 1 n 1 n ( Xi X ) 2 i=1 Then we use the following test statistics: T = X µ S/ n t n 1 and say T has Student s t-distribution with n 1 degrees of freedom. Rafa l Kulik 19
How does it works: We have the following data 18.0 17.4 15.5 16.8 19.0 17.8 17.4 15.8 17.9 16.3 16.9 18.6 17.7 16.4 18.2 18.7 from N (µ, σ 2 ) with completely unknown µ and σ 2. Test H 0 : µ = 16.6 against H A : µ > 16.6. Use α = 0.05. Rafa l Kulik 20
Step 1 H 0 : µ = 16.6 Step 2 H A : µ > 16.6 Computation of p-value The observed value of the sample mean is x = 17.4. Hence P ( X 17.4) = P ( X µ0 S/ n = P (T 0 > 3.081) ) 17.4 16.6 > S/4 where T 0 t 15. From the t-tables we see that = P ( T 0 17.4 ) 16.6 S/4 P (T 0 2.947) 0.005 and P (t 15 3.286) 0.0025. Hence the p-value is somewhere between these, i.e. in the interval (0.0025, 0.005), in particular it is 0.05, strong evidence against H 0 : µ = 16.6. Rafa l Kulik 21
Test on proportion Example: A group of 100 adult American Catholics have been asked: Do you favor allowing women to be priests?. 60 of them answered YES. Is this the strong evidence that more than half American Catholics favor allowing women to be priests? Solution Model: X-number of people who answered YES, X B(100, p). H 0 : p = 0.5, H A : p > 0.5, Under H 0, X B(100, 0.5) Rafa l Kulik 22
p-value: P (X 60): P (X 60) = 1 P (X < 60) = 1 P (X 59) ( ) X np 59 np = 1 P np(1 p) np(1 p) = 1 P (Z 1.9) = 0.0287. Reject H 0 for α = 0.05, don t reject for α = 0.01. Rafa l Kulik 23
Paired test Assumptions: X 11,..., X 1n is a random sample from population 1 X 21,..., X 2n is a random sample from population 2 Two populations are not independent and normal with means µ 1 and µ 2, respectively. Variances are unknown We want to test H 0 : µ 1 = µ 2, H A : µ 1 µ 2. Rafa l Kulik 24
Solution: Compute differences D i = X 1i X 2i and consider t-test from page 36. The test statistics is T 0 = D S D / n t n 1, where D = 1 n S 2 D = 1 n 1 n 1 i=1 n D i, i=1 (D i D) 2 Note: You can also consider one-sided alternatives for both two-sample and paired test. Rafa l Kulik 25
Example Ten engineers knowledge of basic statistical concepts was measured on a scale of 100 before and after a short course in statistical quality control. The result are as follows: Engineer 1 2 3 4 5 6 7 8 9 10 Before X 1i 43 82 77 39 51 66 55 61 79 43 After X 2i 51 84 74 48 53 61 59 75 82 48 Let µ 1 and µ 2 be the mean mean score before and after the course. Test H 0 : µ 1 = µ 2 against µ 1 < µ 2. Rafa l Kulik 26
Solution: The differences D i = X 1i X 2i are: Engineer 1 2 3 4 5 6 7 8 9 10 Before X 1i 43 82 77 39 51 66 55 61 79 43 After X 2i 51 84 74 48 53 61 59 75 82 48 Difference D i -8-2 3-9 -2 5-4 -14-3 -5 so that the observed sample mean is -2.9, the observed sample variance is SD 2 = 31.21. The test statistic is T 0 = D S D / n t n 1. Rafa l Kulik 27
We compute P ( D 2.9) = P ( ) D 0 S D / n 2.9 31.21/10 = P (t 9 < 1.64) = P (t 9 > 1.64) (0.05, 0.1) Do not reject H 0 when α = 0.05 or α = 0.01. Rafa l Kulik 28
Assumptions: Two Sample Test X 11,..., X 1n1 is a random sample from population 1 X 21,..., X 2n2 is a random sample from population 2 Two populations are independent We want to test H 0 : µ 1 = µ 2, H A : µ 1 µ 2. Let X 1 = 1 n 1 n 1 i=1 X 1i, X2 = 1 n 2 n 2 i=1 X 2i. Rafa l Kulik 29
Case 1: Known variances σ 2 1 and σ 2 2 Example: A researcher is interested to assess whether an income in Alberta is higher than in Ontario. A sample of 100 people from Alberta has been interviewed yielding the sample mean x 1 = 33000. A sample of 80 people from Ontario yields the sample mean x 2 = 32000. Do we have enough evidence that people in Alberta get more on average than in Ontario? From the previous studies it is known that the population standard deviations are respectively, σ 1 = 5000 and σ 2 = 2000. Solution: H 0 : µ 1 = µ 2 ; H 1 : µ 1 > µ 2. The observed difference is 1000. To compute P ( X1 X 2 > 1000 ) X 1 = P X 2 0 1000 0 > σ1 2/n 1 + σ2 2/n 50002 /100 + 2000 2 /80 2 = P (Z > 1.82) = 0.035 Reject H 0 when α = 0.05, do not reject when α = 0.01. Rafa l Kulik 30
Case 2: Unknown variances σ 2 1 = σ 2 2; small sample size Example: A researcher wants to test that on average a new fertilizer yields taller plants. Plants were divided into two groups: a control group treated with an old fertilizer and a study group treated with the new fertilizer. The following data are obtained: Test H 0 : µ 1 = µ 2 vs. H 1 : µ 1 < µ 2. Sample size Sample Mean Sample Variance n 1 = 8 x 1 = 43.14 s 2 1 = 71.65 n 2 = 8 x 2 = 47.79 s 2 2 = 52.66 Rafa l Kulik 31
Solution: H 0 : µ 1 = µ 2 ; H 1 : µ 1 < µ 2. The observed difference is 4.65. To compute P ( X1 X 2 < 4.65 ) X 1 = P X 2 0 4.65 0 < s 1 p n + 1 7.88 1/8 + 1/8 1 n 2 = P (t n1 +n 2 2 < 1.18) = P (t 14 < 1.18) = P (t 14 > 1.18) (0.1, 0.2). Here, s 2 p is the pooled variance which is computed as follows: s 2 p = (n 1 1)s 2 1 + (n 2 1)s 2 2 n 1 + n 2 2 = 62.155. Do not reject H 0 when α = 0.05, do not reject when α = 0.01. Rafa l Kulik 32
Case 3: Unknown variances σ 2 1, σ 2 2; large sample size Example: A researcher wants to test that on average a new fertilizer yields taller plants. Plants were divided into two groups: a control group treated with an old fertilizer and a study group treated with the new fertilizer. The following data are obtained: Sample size Sample Mean Sample Variance n 1 = 100 x 1 = 43.14 s 2 1 = 71.65 n 2 = 100 x 2 = 47.79 s 2 2 = 52.66 Test H 0 : µ 1 = µ 2 vs. H 1 : µ 1 < µ 2. Rafa l Kulik 33
Solution: H 0 : µ 1 = µ 2 ; H 1 : µ 1 < µ 2. The observed difference is 4.65. To compute P ( X1 X 2 < 4.65 ) = P X 1 X 2 0 < s 2 1 n 1 + s2 2 n 2 = P (Z < 4.18) = 0. 4.65 0 71.65 100 + 52.66 100 Reject H 0 when α = 0.05, reject when α = 0.01. Rafa l Kulik 34
Difference of two proportions We consider a proportion of recaptured moths in the light-coloured (p 1 ) and the dark colorued (p 2 ) populations. Among the n 1 = 137 light-coloured moths, y 1 = 18 were recaptured; among the n 2 = 493 light-coloured moths, y 2 = 131 were recaptured. Is there a significant difference between the proportion of recaptured moths? Solution: H 0 : p 1 = p 2 ; H 1 : p 1 p 2. The observed proportions are ˆp 1 = y 1 n 1 = 0.131; ˆp 2 = y 2 n 2 = 0.266; ˆp 1 ˆp 2 = 0.135 Rafa l Kulik 35
We compute p-value as 2 P (ˆp 1 ˆp 2 0.135): 2 P ( ˆp 1 ˆp 2 0 ˆp(1 ˆp) 1/n1 + 1/n 2 ) 0.135 0. 0.2365(1 0.2365) 1/137 + 1/493 We get 2 P (ˆp 1 ˆp 2 0.135) = 2P (Z < 3.29) 0. Here, ˆp is the pooled proportion: ˆp = n 1 n 1 + n 2 ˆp 1 + n 2 n 1 + n 2 ˆp 2. Rafa l Kulik 36
R-commands t.test(x,mu=5) is the command for H 0 : µ = 5 against H 1 : µ 5 when σ is unknown (t-test) t.test(x,mu=5,alternative="greater") is the command for H 0 : µ = 5 against H 1 : µ > 5 when σ is unknown (t-test) t.test(x,mu=5,alternative="less") is the command for H 0 : µ = 5 against H 1 : µ < 5 when σ is unknown (t-test) t.test(x,y,paired=true) is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 = µ 2 in case of paired samples, when variances are unknown. t.test(x,y,paired=true,alternative="greater") is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 > µ 2 in case of paired samples, when variances are unknown. Rafa l Kulik 37
t.test(x,y,paired=true,alternative="less") is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 < µ 2 in case of paired samples, when variances are unknown. t.test(x,y,var.equal=true) is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 = µ 2 in case of two independent samples, when variances are unknown (Case 2). t.test(x,y,var.equal=true,alternative="greater") is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 > µ 2 in case of two independent samples, when variances are unknown (Case 2). t.test(x,y,var.equal=true,alternative="less") is the command for H 0 : µ 1 = µ 2 against H 1 : µ 1 < µ 2 in case of two independent samples, when variances are unknown (Case 2). Rafa l Kulik 38