3.4 Statistical inference for 2 populations based on two samples Tests for a difference between two population means The first sample will be denoted as X 1, X 2,..., X m. The second sample will be denoted as Y 1, Y 2,..., Y n. The population means of the populations from which these samples are taken are denoted by µ X and µ Y, respectively. 1 / 63
Statistical inference for 2 populations based on two samples We consider 2 cases 1. Dependent samples - in this case we have n pairs of observations (X 1, Y 1 ),..., (X n, Y n ). 2. Two unrelated samples (X 1,..., X m ) and (Y 1,..., Y n ). 2 / 63
3.4.1 Tests for the difference between two population means - dependent samples Each pair of observations comes from either one individual under two different conditions e.g. the weights of a group before (X ) and after (Y ) a diet. or from two related sources e.g. the height of a father (X ) and his son (Y ). 3 / 63
Tests for the difference between two population means - dependent samples We wish to test the hypothesis H 0 : µ X = µ Y In the first example, this hypothesis states that the diet has no effect on weight. In the second example, this hypothesis states that on average fathers are as tall as their sons. 4 / 63
One and two-sided tests As before, we consider both one and two-sided tests. In a two-sided test the alternative is H A : µ X µ Y In the first example this states that the diet has some effect on weight. In the second example this states that the average height of fathers differs from the average height of their sons. 5 / 63
One and two-sided tests The alternative in a one-sided test may be of the form H A : µ X > µ Y. In the first example this states that the diet on average causes weight loss. In the second example this states that the average height of fathers is greater than the average height of their sons. 6 / 63
One and two-sided tests The alternative may be of the form H A : µ X < µ Y. In the first example this states that the diet on average causes a gain in weight. In the second example, this states that the average height of sons is greater than the average height of their fathers. 7 / 63
Testing procedure for 2 dependent samples When the two samples are dependent, we calculate the differences D i = X i Y i. We treat these differences as one sample and carry out the appropriate one sample test. Let µ D be the population mean of this difference. We have µ D = µ X µ Y. 8 / 63
Testing procedure for 2 dependent samples The null hypothesis corresponds to The alternatives H 0 : µ X = µ Y H 0 : µ D = 0. H A : µ X µ Y ; H A : µ X > µ Y ; H A : µ X < µ Y correspond to H A : µ D 0; H A : µ D > 0; H A : µ D < 0, respectively. 9 / 63
Testing procedure for 2 dependent samples Suppose a company promoting a diet stated that on average a person loses 4kg on this diet, this hypothesis is H 0 : µ X µ Y = 4 H 0 : µ D = 4. The alternative in this case would be that the diet is not as effective as the company states i.e. H A : µ X µ Y < 4 H A : µ D < 4. 10 / 63
Testing procedure for 2 dependent samples The test statistic for the null hypothesis H 0 : µ D = µ 0 is T = D µ 0 S.E.(D), where D is the mean of the sample of differences. This is simply the statistic used for a one-sample test for a population mean. If the sample size is large (n > 30), then this statistic has approximately a standard normal distribution. It should be noted that if the sample size is small, then this test assumes that the differences come from a normal distribution. If this condition is satisfied, then the test statistic has a Student t-distribution with n 1 degrees of freedom. 11 / 63
Example 3.4.1 8 athletes run 400m both at sea level and at altitude. Their times are given below. Test the hypothesis that altitude does not affect the average times of runners at a significance level of 5%. Runner 1 2 3 4 5 6 7 8 Sea Level 45.3 45.8 45.2 45.6 45.1 46.2 45.8 45.4 Altitude 45.2 45.5 45.4 45.4 45.0 45.6 45.5 45.2 12 / 63
Example 3.4.1 Since two times are given for each athlete, these samples are dependent. We calculate the differences D i = X i Y i, where X i and Y i are the times of the i-th athlete at sea level and altitude, respectively. The sample of differences is given by Runner 1 2 3 4 5 6 7 8 Sea Level 45.3 45.8 45.2 45.6 45.1 46.2 45.8 45.4 Altitude 45.2 45.5 45.4 45.4 45.0 45.6 45.5 45.2 Difference 0.1 0.3-0.2 0.2 0.1 0.6 0.3 0.2 13 / 63
Example 3.4.1 i) The hypotheses are ii) The test statistic is H 0 : µ D = 0 against H A : µ D 0. T = D µ 0 S.E.(D), where µ 0 is the mean difference according to the null hypothesis, here µ 0 = 0. 14 / 63
Example 3.4.1 iii) We calculate the realisation of the test statistic 0.1 + 0.3 +... + 0.2 D= 8 s 2 = 1 n (D i D) 2 n 1 i=1 = 0.2 = (0.1 0.2)2 + (0.3 0.2) 2 +... + (0.2 0.2) 2 7 s= 0.051 0.227. 0.051 Hence, S.E.(D) s n = 0.227 8 0.0802 t= 0.2 0 0.0802 2.49 15 / 63
Example 3.4.1 iv) Since the sample size is small, if these differences come from a normal distribution, this statistic has a Student t-distribution with 7 degrees of freedom. The test is two sided, thus the critical value is t n 1,α/2 = t 7,0.025 = 2.365. v) Since t = 2.49 > t n 1,α/2 = 2.365, we reject H 0. We conclude that altitude affects the runners times. 16 / 63
Use of duality for two-sided tests We can also use the duality between confidence intervals and two sided tests. In this case since the significance level is 5%, we calculate a 95% confidence interval for the mean difference. Since the samples are dependent, we treat the differences as one sample and use the appropriate formula to calculate a confidence interval for the true mean difference (in the appropriate population, e.g. all those on the given diet). If this interval contains the value from the null hypothesis, then we do not reject H 0. 17 / 63
Use of duality for two-sided tests Since the sample is small, this formula is This gives D ± t n 1,α/2 S.E.(D) = D ± st n 1,α/2 n 0.2 ± 0.0802 2.365 = 0.2 ± 0.19 = [0.01, 0.39] We are testing the hypothesis H 0 : µ D = 0. Since 0 does not belong to this confidence interval, we reject H 0 at a significance level of 5%. We have evidence that altitude affects runners times. 18 / 63
Assumptions of this test It should be noted that this test assumes that the differences come from a normal distribution. It is not clear whether this is satisfied. Since, the realisation of the test statistic is close to the critical value, we should be somewhat sceptical of our conclusion (more data should be collected). 19 / 63
3.4.2 Tests for the difference between two population means: independent samples In this case the two samples come from two unrelated populations. e.g. the height of Americans and Irish, the times of two different groups of runners. We consider two cases 1. Large sample tests (both samples have at least 30 observations). 2. Small sample tests. 20 / 63
Large Samples Assume that we have samples (X 1,..., X m ) and (Y 1,..., Y n ) from populations with population means µ X and µ Y (where m and n are at least 30). We use the difference between the two sample means, X Y, to estimate the difference between the two population means, µ X µ Y. The standard error of this estimate is σx 2 S.E.(X Y ) = m + σ2 Y n. This is approximated using S.E.(X Y ) s 2 X m + s2 Y n. 21 / 63
Large Samples Suppose we wish to test the hypothesis that H 0 : µ X µ Y = d i.e. the difference between the two population means is d. In two-tailed tests the alternative is H A : µ X µ Y d. If the test is two-tailed, we can always label the two samples in such a way that the alternative is H A : µ X µ Y > d 22 / 63
Large Samples When both samples are large (m, n > 30), the test statistic is Z = (X Y ) d S.E.(X Y ) This statistic has approximately a standard normal distribution. Critical values and p-values are calculated in the same way as in one sample tests. i.e. The p-value for a two sided test is p = P( Z > t ) = 2P(Z > t ). The p-value for a one sided test is p = P(Z > t). 23 / 63
Large samples The critical value for a two sided test is Z α/2 = t,α/2. H 0 is rejected if and only if t > t,α/2. The critical value for a one sided test is Z α = t,α. H 0 is rejected if and only if t > t,α. It should be noted that, as before, the realisation of the test statistic is a measure of the distance between the data and H 0. e.g. when the difference between the sample means is much greater than d, then the realisation of the test statistic will be much greater than 0. 24 / 63
Example 3.4.2 The average height of 100 Dutch men is 176cm and their standard deviation 12cm. The average height of 50 Japanese men is 169cm and their standard deviation is 10cm. Test at a significance level of 1% the hypothesis that the average heights of Dutch men and Japanese men are equal. 25 / 63
Example 3.4.2 i) We have H 0 : µ X µ Y = 0; H A : µ X µ Y 0, where µ X is the mean height of all Dutch men and µ Y the mean height of all Japanese men. 26 / 63
Example 3.4.2 ii) We use the test statistic Z= X Y S.E.(X Y ) s 2 X S.E.(X Y ) m + s2 Y n 12 2 = 100 + 102 50 = 3.44 1.8547 The realisation of this test statistic is t = 176 169 1.8547 3.77. 27 / 63
Example 3.4.2 iv) From the table for the standard normal distribution, the p-value for this test is p = 2P(Z > 3.77) = 0.0002. v) Since p < α = 0.01, we reject H 0 at a significance level of 1%. Also, since p < 0.001, we have very strong evidence that the mean heights of Dutchmen and Japanese differ. From the data we may state that Dutchmen are taller on average than Japanese men. 28 / 63
Example 3.4.2 iv) We can also use the appropriate critical value. Since both samples are large and this is a two sided test, this value is given by Z α/2 = t,α/2 = 2.576. v) Since t = 3.77 > t,α/2 = 2.576, we reject H 0 at a significance level of 1%. We have strong evidence that the mean heights of Dutchmen and Japanese differ. 29 / 63
Duality for two independent samples When both samples are large, the 100(1 α)% confidence interval for the difference between two population means is (X Y ) ± t,α/2 S.E.(X Y ) We can use the duality between confidence intervals and two sided tests. 30 / 63
Example 3.4.3 Calculate a 95% confidence interval for the difference between the mean height of Dutch and Japanese men. Test the hypothesis that on average Dutch men are 10cm taller than Japanese men (data from previous example). We are testing H 0 : µ X µ Y = 10 against H A : µ X µ Y 10. 31 / 63
Example 3.4.3 Since the samples are large, the confidence interval for the difference between the population means is (X Y )±t,α/2 S.E.(X Y ) t,α/2 =t,0.025 = 1.96 Hence, the confidence interval is (176 169) ± 1.96 1.8547 = 7 ± 3.64 = [3.36, 10.64] Since 10 [3.36, 10.64], we do not reject H 0 at a significance level of 5%. The is no evidence against the hypothesis that on average Dutchmen are 10cm taller than Japanese men. 32 / 63
Small sample tests In the case where at least one of the samples is small, the test for the difference between two population means assumes that the observations come from normal distributions with equal variances (i.e. σ 2 X = σ2 Y = σ2 ). 33 / 63
Test for equality of variances Before we carry out the test for a difference between two population means, we should carry out an F test for the equality of two variances. We test H 0 : σ 2 X = σ2 Y against H A : σ 2 X σ2 Y The test statistic, F, is the ratio between the two sample variances. F = max{s2 X, s2 Y } min{s 2 X, s2 Y }. When this ratio is close to one we do not reject the null hypothesis that the population variances are equal. Ratios much greater than 1 indicate that the null hypothesis is not true. 34 / 63
Test for equality of variances Suppose the observations in both samples come from a normal distribution. F has an F distribution with j 1 and k 1 degrees of freedom, where j and k are the number of observations in the sample with the largest and smallest variance, respectively. We reject H 0 if and only if the realisation of the test statistic, f, satisfies f > F j 1,k 1,α/2, where P(F > F j 1,k 1,α/2 = α/2). 35 / 63
Test for equality of variances Critical values of the F j 1,k 1,p are given in Table 9. j 1 and k 1 correspond to the column and row number, respectively. This test is normally carried out at a significance level of 5%. Each cell contains 4 critical values. The first is for p = 0.05, the second (in brackets) for p = 0.025 (this is the appropriate value), the third for p = 0.01 and the fourth for p = 0.001. Note that if the two variances are not equal, the assumptions of the test for a difference between two means, presented below, do not hold. The appropriate procedure in this case is not covered in the course. 36 / 63
Test for difference between two means (small samples) Given the hypothesis regarding the equality of variances was not rejected, we use a pooled estimate of the variances, s 2 p, where s 2 p = (m 1)s2 X + (n 1)s2 Y m + n 2 This is a weighted average of the sample variances, in which the sample with the largest number of observations has the largest weight. The standard error of the difference between the sample means is. S.E.(X Y ) = s p 1 m + 1 n 37 / 63
Test for difference between two means (small samples) Suppose we wish to test the null hypothesis The test statistic used is H 0 : µ X µ Y = d. T = (X Y ) d S.E.(X Y ). Given the assumptions of the test are satisfied (the observations come from normal distributions with a common variance), then this statistic has a student t distribution with m + n 2 degrees of freedom. A 100(1 α)% confidence interval for the difference between the two population means, µ X µ Y, is given by (X Y ) ± t m+n 2,α/2 S.E.(X Y ). 38 / 63
Test for difference between two means (small samples) The critical value for the two sided test with is t m+n 2,α/2. H A : µ X µ Y d. We reject H 0 iff t > t m+n 2,α/2. If the test is two sided, we can always label the two samples such that the alternative is of the form H A : µ X µ Y > d. The critical value for such a test is t m+n 2,α. We reject H 0 iff t > t m+n 2,α. 39 / 63
Example 3.4.4 The average height of 13 Dutch men is 176cm and their standard deviation 12cm. The average height of 11 Japanese men is 169cm and their standard deviation is 10cm. Test at a significance level of 5% the hypothesis that the average heights of Dutch men and Japanese men are equal. 40 / 63
Example 3.4.4 Since the sample sizes are small, we first test the assumption that the population variances are equal. i) We have ii) The test statistic is H 0 : σ 2 X = σ2 Y against H A : σ 2 X σ2 Y F = max{s2 X, s2 Y } min{s 2 X, s2 Y }. iii) The realisation of this test statistic is f = max{122, 10 2 } min{12 2, 10 2 } = 1.44 41 / 63
Example 3.4.4 iv) We read the appropriate critical value. Since there are 13 observations in the sample with the greatest variance, j 1 = 12. Similarly, k 1 = 10. Since α = 0.05, the critical value is F 12,10,0.025 = 3.62. v) Since f < F 12,10,0.025 = 3.62, we do not reject H 0. Hence, we may assume that the two population variances are equal. 42 / 63
Example 3.4.4 We now proceed to test the hypothesis regarding the equality of the two means. i) We have H 0 : µ X µ Y = 0 against H A : µ X µ Y 0. ii) The test statistic for this test is where T = X Y S.E.(X Y ), S.E.(X Y )=s p 1 m + 1 n s 2 p= (m 1)s2 X + (n 1)s2 Y m + n 2. 43 / 63
Example 3.4.4 iii) We calculate the realisation of the test statistic. The pooled variance is s 2 p = (13 1) 122 + (11 1) 10 2 12 + 10 = 124. The standard error of the difference between the two sample means is 1 S.E.(X Y )=s p m + 1 n 1 =124 13 + 1 11 4.56. The realisation of the test statistic is t = 176 169 4.56 1.53. 44 / 63
Example 3.4.4 iv) The critical value for the test is t m+n 2,α/2 = t 22,0.025 = 2.074. v) Since t = 1.53 < t m+n 2,α/2 = 2.074, we do not reject H 0. There is no evidence that the mean height of Dutchmen differs from the mean height of Japanese. 45 / 63
Use of duality It should be noted that we can carry out this test using the duality between two sided tests and confidence intervals. The formula for a 100(1 α)% confidence interval for the difference between two population means when the sample sizes are small is (X Y ) ± t m+n 2,α/2 S.E.(X Y ). Since we are carrying out a test at a significance level of 5%, we calculate a 95% confidence interval. This is given by (176 169) ± t 22,0.025 S.E.(X Y )=7 ± 2.074 4.56 =7 ± 9.46 = [ 2.46, 16.46] 46 / 63
Use of duality Since we are testing H 0 : µ X µ Y = 0, We reject the null hypothesis if and only if 0 does not belong to this confidence interval. Since 0 belongs to this confidence interval, we do not reject H 0 at a significance level of 5%. There is no evidence that the mean height of Dutchmen differs from the mean height of Japanese. 47 / 63
Confidence intervals for the difference between two population proportions Suppose we have two independent, large samples from distinct populations. Suppose the i-th sample has n i observations and the number of individuals showing the trait of interest in the i-th sample is x i. Let the proportion of individuals exhibiting these traits in the i-th population be p i and the proportion of individuals exhibiting these traits in the i-th sample be ˆp i, where ˆp i = x i n i. The difference between the two sample proportions is used to estimate the difference between the two population proportions. 48 / 63
Confidence intervals for the difference between two population proportions The standard error of the difference between the two sample proportions is p 1 (1 p 1 ) S.E.(ˆp 1 ˆp 2 ) = + p 2(1 p 2 ) n 1 n 2 As before, the standard error of this difference depends on the (unknown) population proportions. When we calculate a confidence interval for the difference between population proportions, this standard error can be approximated using ˆp 1 (1 ˆp 1 ) S.E.(ˆp 1 ˆp 2 ) = + ˆp 2(1 ˆp 2 ). n 1 n 2 49 / 63
Confidence intervals for the difference between two population proportions An approximate 100(1 α)% confidence interval for the difference between two population proportions is given by (ˆp 1 ˆp 2 ) ± t m+n 2,α/2 S.E.(ˆp 1 ˆp 2 ) Note that this procedure should not be used e.g. to calculate a confidence interval for the difference between the level of support of two political parties in a single population. 50 / 63
Example 3.4.5 120 of 300 male applicants for an engineering course were accepted and 40 of 80 female applicants. Calculate a 95% confidence interval for the difference in the proportion of males and females accepted for the course. 51 / 63
Example 3.4.5 The sample proportions are ˆp 1 = 120 300 = 0.4; ˆp 2 = 40 80 = 0.5 The estimate of the standard error of the difference between the two proportions is given by ˆp 1 (1 ˆp 1 ) S.E.(ˆp 1 ˆp 2 )= + ˆp 2(1 ˆp 2 ) n 1 n 2 0.4 0.6 0.5 0.5 = + 0.063 300 80 52 / 63
Example 3.4.5 The confidence interval for the difference between the two proportions is (ˆp 1 ˆp 2 ) ± t,α/2 S.E.(ˆp 1 ˆp 2 )=0.1 ± 1.96 0.063 =0.1 ± 0.123 = [ 0.023, 0.223]. 53 / 63
Hypothesis testing Suppose we want to test the hypothesis The test statistic for this test is H 0 : p 1 = p 2. Z = (ˆp 1 ˆp 2 ) S.E.(ˆp 1 ˆp 2 ). This statistic has approximately a standard normal distribution. Let t be the realisation of this statistic. 54 / 63
Hypothesis testing In order to estimate the standard error of the difference between the two sample proportions under the null hypothesis, we calculate the pooled proportion p. This is the total number of individuals with the trait in both samples divided by the total number of individuals in both samples p = x 1 + x 2 n 1 + n 2. We have [ 1 S.E.(ˆp 1 ˆp 2 ) p(1 p) + 1 ]. n 1 n 2 55 / 63
Hypothesis testing For two tailed tests with H A : p 1 p 2 the critical value is Z α/2 = t,α/2. We reject H 0 if and only if t > t,α/2. The p-value is 2P(Z > t ). 56 / 63
Hypothesis testing In the case of one tailed tests, we can always number the samples such that the alternative is The critical value is Z α = t,α. H A : p 1 > p 2. We reject H 0 if and only if t > t,α. The p-value is P(Z > t). 57 / 63
Example 3.4.6 120 of 300 male applicants for an engineering course were accepted and 40 of 80 female applicants. Test at a significance level of 5% the hypothesis that the proportion of males accepted equals the proportion of females accepted. 58 / 63
Example 3.4.6 The hypotheses are ii) The statistic used is H 0 : p 1 = p 2 against H A : p 1 p 2 Z = ˆp 1 ˆp 2 S.E.(ˆp 1 ˆp 2 ). 59 / 63
Example 3.4.6 iii) We calculate the realisation of the test statistic. The pooled proportion is p = x 1 + x 2 120 + 40 = n 1 + n 2 300 + 80 0.421. The estimate of the standard error of the difference between the two sample proportions under H 0 is [ 1 S.E.(ˆp 1 ˆp 2 ) p(1 p) + 1 ] n 1 n 2 [ 1 = 0.421 0.579 300 + 1 ] 0.062 80 60 / 63
Example 3.4.6 The sample proportions are ˆp 1 = 120 300 = 0.4; ˆp 2 = 40 80 = 0.5. The realisation of the test statistic is t = 0.4 0.5 0.062 1.61 iv) The critical value for this test is t,0.025 = 1.96. v) Since t = 1.61 < t,0.025 = 1.96, we do not reject H 0 at a significance level of 5%. There is no evidence that the admission rates vary according to sex. 61 / 63
Example 3.4.6 In iv) we could calculate the p-value p = 2P(Z > t ) = 2P(Z > 1.61) = 2 0.0537 = 0.1074. Since p > 0.05, we do not reject H 0. There is no evidence that the admission rates vary. 62 / 63
Example 3.4.6 As in the one sample case, we can use the duality between two-sided hypothesis tests and confidence intervals. Since different approximations are used to estimate the standard error of the difference between the sample proportions, this duality is only approximate. Suppose we wish to test H 0 : p 1 = p 2 (i.e. p1 p2 = 0). In this example the 95% confidence interval for the difference between the two proportions was [-0.023, 0.223]. Since 0 belongs to this confidence interval, we do not reject H 0 at a significance level of approximately 5%. There is no evidence that the admission rates vary. 63 / 63