Stat141 10/25 Inference for a single mean (including paired data and proportions) SW text Ch.6,9. > civec =c(.9, .95, .99) > errvec = 1 - civec #alpha = 1 - confidence (prob of coverage) > errvec [1] 0.10 0.05 0.01 > qnorm(1 - errvec/2) [1] 1.644854 1.959964 2.575829 > qt(1 - errvec/2,5) [1] 2.015048 2.570582 4.032143 > qt(1 - errvec/2,25) [1] 1.708141 2.059539 2.787436 > qt(1 - errvec/2,50) [1] 1.675905 2.008559 2.677793 > #cockroach respiration (9/27) > croach = c(55.95, 68.24, 52.73, 21.5, 23.78) > mean(croach) [1] 44.44 > sd(croach) [1] 20.7408 > mean(croach) - 1.96*sd(croach)/sqrt(5); mean(croach) + 1.96*sd(croach)/sqrt(5) [1] 26.25989 [1] 62.62011 > #endpoints of 95% CI if one assumes 5-1 is "very large" > mean(croach)-qt(.975,4)*sd(croach)/sqrt(5);mean(croach)+qt(.975,4)*sd(croach)/sqrt(5) [1] 18.68689 [1] 70.1931 > qnorm(.975);qt(.975,4) [1] 1.959964 [1] 2.776445 > t.test(croach) > t.test(croach, c= .9) One Sample t-test One Sample t-test data: croach data: croach t = 4.7911, df = 4, p-value = 0.008705 t = 4.7911, df = 4, p-value = 0.008705 alternative hypothesis: true mean alternative hypothesis: true mean is not equal to 0 is not equal to 0 95 percent confidence interval: 90 percent confidence interval: 18.68689 70.19311 24.66591 64.21409 sample estimates: sample estimates: mean of x mean of x 44.44 44.44 ------------------------------------------------------------------------------------ > #paired data SW Ch.9 is single mean inference, mean of differences > #SW ex 9.6 p.354 squirrels (SW already computed diff) > sqr = read.table(file="D:\\stat141\\squirrel.dat", header = T) > summary(sqr) person tree difference Min. : 60.0 Min. : 34.0 Min. :-217.00 1st Qu.:126.5 1st Qu.: 47.5 1st Qu.: -11.50 Median :189.0 Median : 54.0 Median : 144.00 Mean :190.2 Mean :118.3 Mean : 71.91 3rd Qu.:239.0 3rd Qu.:186.5 3rd Qu.: 167.50 Max. :326.0 Max. :293.0 Max. : 275.00 > sqr person tree difference person tree difference 1 81 137 -56 7 240 45 195 2 178 34 144 8 326 293 33 3 202 51 151 9 60 277 -217 4 325 50 275 10 119 83 36 5 238 54 184 11 189 41 148 6 134 236 -102 > attach(sqr) > #note SW normal prob plots (qq-plot via qnorm) to check distrib assumptions > t.test(difference);t.test(difference, c=.9) One Sample t-test One Sample t-test data: difference data: difference t = 1.6113, df = 10, p-value = 0.1382 t = 1.6113, df = 10, p-value = 0.1382 alternative hypothesis: true mean alternative hypothesis: true mean is not equal to 0 is not equal to 0 95 percent confidence interval: 90 percent confidence interval: -27.52795 171.34613 -8.977145 152.795327 sample estimates: sample estimates: mean of x mean of x 71.90909 71.90909 > qt(1 - errvec/2,10) [1] 1.812461 2.228139 3.169273 ----------------------------------------------------------------------------