Inference for Distributions Marc H. Mehlman [email protected] University of New Haven Based on Rare Event Rule: “rare events happen – but not to me”. Marc Mehlman (University of New Haven) Inference for Distributions 1 / 42 Table of Contents 1 t Distribution 2 CI for µ: σ unknown 3 t-test: Mean (σ unknown) 4 t test: Matched Pairs 5 Two Sample z–Test: Means (σX and σY known) 6 Two Sample t–test: Means (σX and σY unknown) 7 Pooled Two Sample t–test: Means (σX = σY unknown) 8 Two Sample F –test: Variance 9 Chapter #7 R Assignment Marc Mehlman (University of New Haven) Inference for Distributions 2 / 42 t Distribution t Distribution t Distribution. Marc Mehlman (University of New Haven) Inference for Distributions 3 / 42 t Distribution If X1 , · · · , Xn is a normal random sample σ √ X̄ ∼ N µ, ⇒ n X̄ − µ √ ∼ N(0, 1). σ/ n If the random sample is not normal, but n ≥ 30, the above is also true (approximately) by the CLT. However, typically one does not know what σ equals so one is tempted to use s instead of σ. This gives Definition (Student t Distribution) If a random sample is normal or the sample size is ≥ 30 X̄ − µ √ ∼ t(n − 1), S/ n where t is the Student t Distribution with n − 1 degrees of freedom. Marc Mehlman (University of New Haven) Inference for Distributions 4 / 42 t Distribution The t Distributions When comparing the density curves of the standard Normal distribution and t distributions, several facts are apparent: The density curves of the t distributions are similar in shape to the standard Normal curve. The spread of the t distributions is a bit greater than that of the standard Normal distribution. The t distributions have more probability in the tails and less in the center than does the standard Normal. As the degrees of freedom increase, the t density curve approaches the standard Normal curve ever more closely. We can use Table D in the back of the book to determine critical values t* for t distributions with different degrees of freedom. Marc Mehlman (University of New Haven) Inference for Distributions 7 5 / 42 t Distribution Robustness The t procedures are exactly correct when the population is exactly Normal. This is rare. The t procedures are robust to small deviations from Normality, but: The sample must be a random sample from the population. Outliers and skewness strongly influence the mean and therefore the t procedures. Their impact diminishes as the sample size gets larger because of the Central Limit Theorem. As a guideline: When n < 15, the data must be close to Normal and without outliers. When 15 > n > 40, mild skewness is acceptable, but not outliers. When n > 40, the t statistic will be valid even with strong skewness. Marc Mehlman (University of New Haven) Inference for Distributions 6 / 42 CI for µ: σ unknown CI for µ: σ unknown Confidence intervals for µ when σ is unknown. Marc Mehlman (University of New Haven) Inference for Distributions 7 / 42 CI for µ: σ unknown Confidence intervals A confidence interval is a range of values that contains the true population parameter with probability (confidence level) C. We have a set of data from a population with both µ and σ unknown. We use x̅ to estimate µ, and s to estimate σ, using a t distribution (df n − 1). C is the area between −t* and t*. We find t* in the line of Table. The margin of error m is: m=t∗s/ √ n C m −t* Marc Mehlman (University of New Haven) Inference for Distributions m t* 8 / 42 CI for µ: σ unknown Definition (standard error) def S The standard error of the sample mean for σ unknown is SEx̄ = √ . n Theorem (CI for µ, σ unknown) Assume n ≥ 30 or the population is normal. Let s def margin of error = m = t ? (n − 1) ? √ = t ? (n − 1) ? SEx̄ . n Then the confidence interval is x̄ ± m. Marc Mehlman (University of New Haven) Inference for Distributions 9 / 42 CI for µ: σ unknown Example The meters of total rainfall for Jupa, Beliana in the first decade of each of the last sixteen centuries is given below: 3.790155 4.116425 3.628361 2.771781 3.989105 6.243354 5.124677 5.040272 4.227491 6.821760 3.183561 6.170435 5.286963 5.439190 3.323666 5.206938 Find a 90% confidence interval for the mean rainfall per first decade of each century. Solution: The following normal quartile plot indicates Normal Q−Q Plot that the data comes from a normal (or at least almost normal) distribution. Since σ is unknown and the distribution is close to normal with no outliers, R gives us ● ● 6 ● > mean(mdat)-qt(0.95,15)*sd(mdat)/sqrt(16) [1] 4.124238 > mean(mdat)+qt(0.95,15)*sd(mdat)/sqrt(16) [1] 5.171278 5 Sample Quantiles ● ● ● ● ● ● 4 ● ● Thus a 90% confidence interval is (4.124238, 5.171278). Notice ● ● ● 3 ● ● −2 −1 0 1 2 Theoretical Quantiles Marc Mehlman (University of New Haven) > t.test(mdat,mu=4.5,conf.level=0.90) One Sample t-test data: mdat t = 0.4948, df = 15, p-value = 0.6279 alternative hypothesis: true mean is not equal to 4.5 90 percent confidence interval: 4.124238 5.171278 sample estimates: mean of x 4.647758 Inference for Distributions 10 / 42 CI for µ: σ unknown Example The meters of total rainfall for Jupa, Beliana in the first decade of each of the last sixteen centuries is given below: 3.790155 4.116425 3.628361 2.771781 3.989105 6.243354 5.124677 5.040272 4.227491 6.821760 3.183561 6.170435 5.286963 5.439190 3.323666 5.206938 Find a 90% confidence interval for the mean rainfall per first decade of each century. Solution: The following normal quartile plot indicates Normal Q−Q Plot that the data comes from a normal (or at least almost normal) distribution. Since σ is unknown and the distribution is close to normal with no outliers, R gives us ● ● 6 ● > mean(mdat)-qt(0.95,15)*sd(mdat)/sqrt(16) [1] 4.124238 > mean(mdat)+qt(0.95,15)*sd(mdat)/sqrt(16) [1] 5.171278 5 Sample Quantiles ● ● ● ● ● ● 4 ● ● Thus a 90% confidence interval is (4.124238, 5.171278). Notice ● ● ● 3 ● ● −2 −1 0 1 2 Theoretical Quantiles Marc Mehlman (University of New Haven) > t.test(mdat,mu=4.5,conf.level=0.90) One Sample t-test data: mdat t = 0.4948, df = 15, p-value = 0.6279 alternative hypothesis: true mean is not equal to 4.5 90 percent confidence interval: 4.124238 5.171278 sample estimates: mean of x 4.647758 Inference for Distributions 10 / 42 t-test: Mean (σ unknown) t-test: Mean (σ unknown) t-test: Mean (σ unknown) Marc Mehlman (University of New Haven) Inference for Distributions 11 / 42 t-test: Mean (σ unknown) Theorem (t–test for the Mean (σ unknown)) Given a random sample, X1 , · · · , Xn , where either the random sample was sampled from a normal population or the sample size n ≥ 30, let the test statistic be T = X̄ − µ0 √ . S/ n Then T ∼ t(n − 1) under H0 : µ = µ0 . The p–value of a test of H0 1 versus H1 : µX > µ0 is P(T ≥ t). 2 versus H2 : µX < µ0 is P(T ≤ t). 3 versus H3 : µX 6= µ0 is 2P(T ≥ |t|). Marc Mehlman (University of New Haven) Inference for Distributions 12 / 42 t-test: Mean (σ unknown) Example The number of hours of Sesame Street that American 4 year olds watch each year is assumed to 2 distributed normally. Twenty-five 4 year olds are randomly sampled and one finds x̄ = 125 and sX = 100. What is the p–value for a test of H0 : µX = 120 versus HA : µX > 120? Solution: The population is normally distributed so the test statistic is t = 125 − 120 = 2.5 √ 10/ 25 comes from t(24) under H0 . Thus the p–value is > 1-pt(2.5,24) [1] 0.009827088 It seems unlikely that the average number of Sesame Street watching hours is 120 or less. Marc Mehlman (University of New Haven) Inference for Distributions 13 / 42 t-test: Mean (σ unknown) Example The number of hours of Sesame Street that American 4 year olds watch each year is assumed to 2 distributed normally. Twenty-five 4 year olds are randomly sampled and one finds x̄ = 125 and sX = 100. What is the p–value for a test of H0 : µX = 120 versus HA : µX > 120? Solution: The population is normally distributed so the test statistic is t = 125 − 120 = 2.5 √ 10/ 25 comes from t(24) under H0 . Thus the p–value is > 1-pt(2.5,24) [1] 0.009827088 It seems unlikely that the average number of Sesame Street watching hours is 120 or less. Marc Mehlman (University of New Haven) Inference for Distributions 13 / 42 t-test: Mean (σ unknown) Example > set.seed(1234) > ntab=rnorm(99,5,1) > t.test(ntab,mu=4.6) One Sample t-test data: ntab t = 2.2299, df = 98, p-value = 0.02804 alternative hypothesis: true mean is not equal to 4.6 95 percent confidence interval: 4.624239 5.016220 sample estimates: mean of x 4.820229 > t.test(ntab,mu=4.6,alternative="greater") One Sample t-test data: ntab t = 2.2299, df = 98, p-value = 0.01402 alternative hypothesis: true mean is greater than 4.6 95 percent confidence interval: 4.65623 Inf sample estimates: mean of x 4.820229 Marc Mehlman (University of New Haven) Inference for Distributions 14 / 42 t test: Matched Pairs t test: Matched Pairs Matched Pairs Marc Mehlman (University of New Haven) Inference for Distributions 15 / 42 t test: Matched Pairs Matched pairs t procedures Sometimes we want to compare treatments or conditions at the individual level. The data sets produced this way are not independent. The individuals in one sample are related to those in the other sample. Pre-test and post-test studies look at data collected on the same sample elements before and after some experiment is performed. Twin studies often try to sort out the influence of genetic factors by comparing a variable between sets of twins. Using people matched for age, sex, and education in social studies allows us to cancel out the effect of these potential lurking variables. Marc Mehlman (University of New Haven) Inference for Distributions 16 / 42 t test: Matched Pairs Theorem (Matched Pairs) Let (X1 , Y1 ), · · · , (Xn , Yn ) be a bivariate random sample and define def Dj = Xj − Yj . Assume n ≥ 30, or the Dj ’s are normal (or pretty much so). Let H0 : µD = d. The test statistic is T = D̄ − d √ ∼ t(n − 1) sD / n for H0 . A (1 − α)100% CI for µD is sD d¯ ± t ? (n − 1) ? √ . n Marc Mehlman (University of New Haven) Inference for Distributions 17 / 42 t test: Matched Pairs Example (Does lack of caffeine increase depression?) Randomly selected caffeine-dependent individuals were deprived of all caffeine–rich foods and assigned to receive daily pills. At one time the pills contained caffeine and, at another time they were a placebo. Depression was assessed quantitatively (higher scores represent greater depression). Find the p–value of the test H0 : µdiff = 0 Subject Caffeine Placebo Difference 1 5 16 11 2 5 23 18 3 4 5 1 versus 4 3 7 4 5 8 14 6 HA : µdiff ≥ 0 6 5 24 19 7 0 6 6 8 0 3 3 9 2 15 13 10 11 12 1 11 1 0 -1 Solution: The normal quartile plot to the left indicates that the data comes from a normal (or at least almost normal) distribution. Normal Q−Q Plot ● ● 15 > cdat=c(5,5,4,3,8,5,0,0,2,11,1) > pdat=c(16,23,5,7,14,24,6,3,15,12,0) > tstat=(mean(pdat-cdat)-0)/(sd(pdat-cdat)/sqrt(11)) > tstat [1] 3.530426 > 1-pt(tstat,10) [1] 0.002721472 ● 10 Sample Quantiles ● ● 5 ● ● ● ● 0 ● ● −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 It is very likely that caffeine deprivation causes an increase in rates of depression. Theoretical Quantiles Marc Mehlman (University of New Haven) Inference for Distributions 18 / 42 t test: Matched Pairs Example (Does lack of caffeine increase depression?) Randomly selected caffeine-dependent individuals were deprived of all caffeine–rich foods and assigned to receive daily pills. At one time the pills contained caffeine and, at another time they were a placebo. Depression was assessed quantitatively (higher scores represent greater depression). Find the p–value of the test H0 : µdiff = 0 Subject Caffeine Placebo Difference 1 5 16 11 2 5 23 18 3 4 5 1 versus 4 3 7 4 5 8 14 6 HA : µdiff ≥ 0 6 5 24 19 7 0 6 6 8 0 3 3 9 2 15 13 10 11 12 1 11 1 0 -1 Solution: The normal quartile plot to the left indicates that the data comes from a normal (or at least almost normal) distribution. Normal Q−Q Plot ● ● 15 > cdat=c(5,5,4,3,8,5,0,0,2,11,1) > pdat=c(16,23,5,7,14,24,6,3,15,12,0) > tstat=(mean(pdat-cdat)-0)/(sd(pdat-cdat)/sqrt(11)) > tstat [1] 3.530426 > 1-pt(tstat,10) [1] 0.002721472 ● 10 Sample Quantiles ● ● 5 ● ● ● ● 0 ● ● −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 It is very likely that caffeine deprivation causes an increase in rates of depression. Theoretical Quantiles Marc Mehlman (University of New Haven) Inference for Distributions 18 / 42 t test: Matched Pairs Example (cont.) Using R, one can find the p–value two other ways too. > t.test(pdat-cdat,mu=0,alternative="greater") One Sample t-test data: pdat - cdat t = 3.5304, df = 10, p-value = 0.002721 alternative hypothesis: true mean is greater than 0 95 percent confidence interval: 3.583269 Inf sample estimates: mean of x 7.363636 > t.test(pdat,cdat,paired=TRUE,mu=0,alternative="greater") Paired t-test data: pdat and cdat t = 3.5304, df = 10, p-value = 0.002721 alternative hypothesis: true difference in means is greater than 0 95 percent confidence interval: 3.583269 Inf sample estimates: mean of the differences 7.363636 Marc Mehlman (University of New Haven) Inference for Distributions 19 / 42 t test: Matched Pairs Without any assumptions of population distribution types or sample sizes one has: Theorem (Sign Test for Matched Pairs) Ignore pairs with differences of zero and let n be the count of the remaining pairs. The test statistic is the count, X , of pairs with a positive difference. To find the p–value of a test note that X ∼ BIN(n, 1/2) under the hypotheses H0 the median of the two matched pairs are the same. Example In the previous example concerning caffeine deprivation, ten out of eleven subjects experienced an increase in depression. Consider the signed test for matched pairs, H0 : median depression with caffeine = median depression with placebo HA : median depression with caffeine < median depression with placebo. versus Noticing that x = 10, the p–value is P(X ≥ 10) = P(X = 10) + P(X = 11) = 10 11 1 11 1 1 11 1 1 0 1− + 1− 10 2 2 11 2 2 or, using R, > 1-pbinom(9,11,1/2) [1] 0.005859375 Marc Mehlman (University of New Haven) Inference for Distributions 20 / 42 Two Sample z–Test: Means (σX and σY known) Two Sample z–Test: Means (σX and σY known) Two Sample z–Test: Means (σX and σY known) Marc Mehlman (University of New Haven) Inference for Distributions 21 / 42 Two Sample z–Test: Means (σX and σY known) Theorem (Two Sample z–Test: Means (σX and σY known)) Let X1 , · · · , XnX and Y1 , · · · , YnY be independent random samples where each random sample is either sampled from a normal population or has sample size ≥ 30, Let H0 : µ X = µ Y with test statistic X̄ − Ȳ Z=q 2 ∼ N(0, 1) σX σY2 nX + nY for H0 . A (1 − α)100% confidence interval for µX − µY is s σX2 σ2 x̄ − ȳ ± z ? + Y. nX nY Marc Mehlman (University of New Haven) Inference for Distributions 22 / 42 Two Sample z–Test: Means (σX and σY known) Example The range of Brand X wireless routers is distributed as N(µX , 17.7) and the range of Brand Y wireless routers is distributed as N(µY , 15.3). Suppose ten Brand X routers are sampled and X̄ = 131.2 meters. Further suppose that nine Brand Y routers are sampled and Ȳ = 141.5 meters. Find the p–value of the test of H0 : µX = µY versus HA : µX < µY . Solution: 131.2 − 141.5 z= q = −1.360229. 2 17.72 + 15.3 10 9 which comes from N(0, 1) under H0 . The p–value for the test is > zstat=(131.2-141.5)/sqrt((17.7^2/10)+(15.3^2/9)) > zstat [1] -1.360229 > pnorm(zstat,0,1) [1] 0.08687867 One must accept H0 at the 0.05 significance level and reject H0 at the 0.10 significance level. Marc Mehlman (University of New Haven) Inference for Distributions 23 / 42 Two Sample z–Test: Means (σX and σY known) Example The range of Brand X wireless routers is distributed as N(µX , 17.7) and the range of Brand Y wireless routers is distributed as N(µY , 15.3). Suppose ten Brand X routers are sampled and X̄ = 131.2 meters. Further suppose that nine Brand Y routers are sampled and Ȳ = 141.5 meters. Find the p–value of the test of H0 : µX = µY versus HA : µX < µY . Solution: 131.2 − 141.5 z= q = −1.360229. 2 17.72 + 15.3 10 9 which comes from N(0, 1) under H0 . The p–value for the test is > zstat=(131.2-141.5)/sqrt((17.7^2/10)+(15.3^2/9)) > zstat [1] -1.360229 > pnorm(zstat,0,1) [1] 0.08687867 One must accept H0 at the 0.05 significance level and reject H0 at the 0.10 significance level. Marc Mehlman (University of New Haven) Inference for Distributions 23 / 42 Two Sample t–test: Means (σX and σY unknown) Two Sample t–test: Means (σX and σY unknown) Two Sample t–test: Means (σX and σY unknown) Marc Mehlman (University of New Haven) Inference for Distributions 24 / 42 Two Sample t–test: Means (σX and σY unknown) Theorem (Conservative Two Sample t-test: Means (σX and σY unknown)) Let X1 , · · · , XnX and Y1 , · · · , YnY be independent random samples. Assume either the random samples were sampled from a normal population or the sum of the sample sizes, nX + nY , are ≥ 30. Let H 0 : µX = µY The (conservative) test statistic is X̄ − Ȳ T = q 2 ∼ t(min(nX − 1, nY − 1)) SX S2 + nYY nX for H0 . A (1 − α)100% confidence interval for µX − µY is s ? x̄ − ȳ ± t (min(nX − 1, nY − 1)) Marc Mehlman (University of New Haven) Inference for Distributions sX2 s2 + Y. nX nY 25 / 42 Two Sample t–test: Means (σX and σY unknown) Theorem (Welch’s t Test) Let X1 , · · · , XnX and Y1 , · · · , YnY be independent random samples. Assume either the random samples were sampled from a normal population or the each the sample sizes are ≥ 5. Let H0 : µX = µY The test statistic is T = s X̄ − Ȳ S2 X nX ∼ t (df) 2 S + nY Y where 2 sX nX df = 1 nX −1 s2 X nX 2 s + nY !2 Y !2 + n 1−1 Y s2 Y nY !2 for H0 . When using a table, let the degrees of freedom be largest integer that is less than or equal to df for a slightly more conservative test (statistical software can handle non–integer degree of freedoms). A (1 − α)100% confidence interval for µX − µY is v u 2 us s2 x̄ − ȳ ± t (df)t X + Y . nX nY ? Marc Mehlman (University of New Haven) Inference for Distributions 26 / 42 Two Sample t–test: Means (σX and σY unknown) Robustness: Two sample t–tests tend to be more robust than One sample t–test. This is especially true when either the two sample sizes are equal or the two populations have the similarly shaped distributions. When either (or both) of these conditions hold, the guidelines for using the Conservative Two Sample t–test or Welch’s t–test can be relaxed. Marc Mehlman (University of New Haven) Inference for Distributions 27 / 42 Two Sample t–test: Means (σX and σY unknown) Example Does smoking damage the lungs of children exposed to parental smoking? Forced Vital Capacity (FVC) is the volume (in milliliters) of air that an individual can exhale in 6 seconds. FVC was obtained for a sample of children not exposed to parental smoking and for a sample of children exposed to parental smoking. Parental smoking Mean FVC s n Yes 75.5 9.3 30 No 88.2 15.1 30 Is the mean FVC lower in the population of children exposed to parental smoking? We test: H0: µsmoke = µno <=> (µsmoke − µno) = 0 Ha: µsmoke < µno <=> (µsmoke − µno) < 0 (one-sided) Marc Mehlman (University of New Haven) Inference for Distributions 28 / 42 Two Sample t–test: Means (σX and σY unknown) Example (cont.) The test statistic is > (75.5-88.2)/sqrt(9.3^2/30 + 15.1^2/30) [1] -3.922419 The conservative test gives 29 for the degrees of freedom and a p–value of > tstat=(75.5-88.2)/sqrt(9.3^2/30 + 15.1^2/30) > tstat [1] -3.922419 > pt(tstat,29) [1] 0.0002468389 The degrees of freedom for Welch’s Test is 2 2 9.32 + 15.1 30 30 2 2 1 9.3 1 + 30−1 30−1 30 15.12 30 2 = 48.23342. (Use 48 if you looking up the p–value in a table). Using R, Welch’s test gives a p–value of > pt(-3.922419, 48.23342) [1] 0.0001385454 Marc Mehlman (University of New Haven) Inference for Distributions 29 / 42 Two Sample t–test: Means (σX and σY unknown) Example > dat1=rnorm(25,0.9,2.5) > dat2=rnorm(43,0.6,1.3) > t.test(dat1,dat2,mu=0.0) Welch Two Sample t-test data: dat1 and dat2 t = 1.2977, df = 29.947, p-value = 0.2043 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.4611103 2.0679355 sample estimates: mean of x mean of y 1.2426692 0.4392566 Marc Mehlman (University of New Haven) Inference for Distributions 30 / 42 Pooled Two Sample t–test: Means (σX = σY unknown) Pooled Two Sample t–test: Means (σX = σY unknown) Pooled Two Sample t–test: Means (σX = σY unknown) Marc Mehlman (University of New Haven) Inference for Distributions 31 / 42 Pooled Two Sample t–test: Means (σX = σY unknown) Theorem (Pooled Two Sample t–test: Means (σ = σX = σY unknown)) Let X1 , · · · , XnX and Y1 , · · · , YnY be independent random samples. Assume σ = σX = σY and that either the random samples were sampled from a normal population or the sum of the sample sizes, nX + nY , are ≥ 30. Define the pooled estimator of σ 2 , 2 2 (nX − 1)SX + (nY − 1)SY 2 def Sp = nX + nY − 2 . Let H0 : µX = µY The test statistic is T = Sp X̄ − Ȳ q 1 + 1 n n X ∼ t(nX + nY − 2) Y for H0 . A (1 − α)100% confidence interval for µX − µY is s ? x̄ − ȳ ± t (nX + nY − 2)sp Marc Mehlman (University of New Haven) 1 nX Inference for Distributions + 1 nY . 32 / 42 Pooled Two Sample t–test: Means (σX = σY unknown) Example > atab=rnorm(45,3,2) > btab=rnorm(50,3.5,2) > t.test(atab,btab,var.equal=TRUE) Two Sample t-test data: atab and btab t = -1.7116, df = 93, p-value = 0.0903 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -1.3836440 0.1026042 sample estimates: mean of x mean of y 3.356853 3.997373 Marc Mehlman (University of New Haven) Inference for Distributions 33 / 42 Two Sample F –test: Variance Two Sample F –test Two Sample F –Test: Variance Marc Mehlman (University of New Haven) Inference for Distributions 34 / 42 Two Sample F –test: Variance Definition Let X1 , · · · , Xn be a random sample from N(µX , σ) and let Y1 , · · · , Ym be an independent random sample N(µY , σ). Then SX2 ∼ F(n − 1, m − 1) SY2 is the F distribution with n − 1 degrees of freedom for the numerator and m − 1 degrees of freedom for the denominator. The F distribution is named after Sir Ronald A. Fisher. “Even scientists need their heroes, and R. A. Fisher was certainly the hero of 20th century statistics. His ideas dominated and transformed our field to an extent a Caesar or an Alexander might have envied.” – Bradley Efron Marc Mehlman (University of New Haven) Inference for Distributions 35 / 42 Two Sample F –test: Variance Theorem (Two–Sample F Test) Let X1 , · · · , Xn be a random sample from N(µX , σX ) and let Y1 , · · · , Ym be an independent random sample from N(µY , σY ). Let H0 : σX = σY . Then 2 def S under H0 . F = X2 ∼ F(n − 1, m − 1) SY Furthermore the p–value of H0 versus 1 HA : σX > σY is P(f ≥ F (n − 1, m − 1)). 2 HA : σX < σY is P(f ≤ F (n − 1, m − 1)). 3 HA : σX 6= σY is twice the smaller value from the two alternative hypothesis above. Warning The F–test is not robust with respect normal distribution assumptions. Marc Mehlman (University of New Haven) Inference for Distributions 36 / 42 Two Sample F –test: Variance Example The # of tail wags per minute of 11 randomly chosen Labrador dogs at feeding time was tallied and sample variance of 6.73 was calculated. The # of tail wags per minute of 9 randomly chosen terriers at feeding time was tallied and sample variance of 25.91 was calculated. Assuming that the number of wags for both types of dogs are normal, find the p–value of a test of H0 : σL = σT def SL2 2 ST Solution: F = versus HA : σL < σT . ∼ F(11 − 1, 9 − 1) under H0 and f = 6.73 25.91 = 0.26. The p–value of the left–tailed test is > pf(6.73/25.91,10,8) [1] 0.02510348 There is reason to reject the hypothesis that variance of tail wagging is the same between terriers and Labradors in favor of more tail wagging variance for terriers. Marc Mehlman (University of New Haven) Inference for Distributions 37 / 42 Two Sample F –test: Variance Example The # of tail wags per minute of 11 randomly chosen Labrador dogs at feeding time was tallied and sample variance of 6.73 was calculated. The # of tail wags per minute of 9 randomly chosen terriers at feeding time was tallied and sample variance of 25.91 was calculated. Assuming that the number of wags for both types of dogs are normal, find the p–value of a test of H0 : σL = σT def SL2 2 ST Solution: F = versus HA : σL < σT . ∼ F(11 − 1, 9 − 1) under H0 and f = 6.73 25.91 = 0.26. The p–value of the left–tailed test is > pf(6.73/25.91,10,8) [1] 0.02510348 There is reason to reject the hypothesis that variance of tail wagging is the same between terriers and Labradors in favor of more tail wagging variance for terriers. Marc Mehlman (University of New Haven) Inference for Distributions 37 / 42 Two Sample F –test: Variance Example > dat1=rnorm(25,0.9,2.5) > dat2=rnorm(43,0.6,1.5) > var.test(dat1,dat2) F test to compare two variances data: dat1 and dat2 F = 2.4715, num df = 24, denom df = 42, p-value = 0.009983 alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 1.242724 5.280972 sample estimates: ratio of variances 2.471486 Marc Mehlman (University of New Haven) Inference for Distributions 38 / 42 Two Sample F –test: Variance To use a F table: 1 To use a F table, chose X to be the random variable with the larger variance (thus the F statistic ≥ 1). 2 If the test is two–sided, use α/2 for the table. 3 When a degree of freedom can not be found in the table, use the closest value that is less than the desired degree of freedom for a conservative test. Marc Mehlman (University of New Haven) Inference for Distributions 39 / 42 Chapter #7 R Assignment Chapter #7 R Assignment Chapter #7 R Assignment Marc Mehlman (University of New Haven) Inference for Distributions 40 / 42 Chapter #7 R Assignment First create the normal datasets: > > > > set.seed(4321) ndat1=rnorm(73,3.1,1.9) ndat2=rnorm(57,2.9,2.3) ndat3=rnorm(83,3.5,2.3) and then do the problems: 1 For dataset ndat1, not knowing the mean is 3.1 or the standard deviation is 1.9, find the p–value of the test H0 : µ = 3.7 2 versus HA : µ < 3.7. The dataset “immer” (found on my website) contains the barley yield in years 1931 and 1932 where the same field are recorded. The matched pair yield data are presented in by the columns Y1 and Y2. Find a 97.5% confidence interval for the difference of the means, µY1 − µY2 , and use a matched pair t–test to find the p–value of H0 : µY1 = µY2 versus HA : µY1 6= µY2 . Marc Mehlman (University of New Haven) Inference for Distributions 41 / 42 Chapter #7 R Assignment 3 Assuming the means and standard deviations of ndat1 and ndat2 are unknown, use Welch’s t test to test if the means of the two data sets are equal. 4 Assuming the means and standard deviations of ndat2 and ndat3 are unknown, but we know the population variances are equal, use pooled two sample t test to test if the means of the two data sets are equal. 5 Test if the populations that ndat1 and ndat3 came from have the same variance. Marc Mehlman (University of New Haven) Inference for Distributions 42 / 42
© Copyright 2026 Paperzz