### Class examples from Week 6: Samples and Populations ### Ken Benoit Feb 2010 ## Levin and Fox Table 6.1 example pop <- c(70, 86, 56, 40, 89, 99, 96, 80, 85, 52, 78, 49, 72, 94, 93, 90, 67, 57, 48, 30) (mu <- mean(pop)) (s1 <- sample(pop, 4)) mean(s1) (s2 <- sample(pop, 4)) mean(s2) (s3 <- sample(pop, 4)) mean(s3) ## Step-by-step illustration LF&F pp197-199 x <- c(1,5,2,3,4,1,2,2,4,3) mean(x) # step 1 (s <- sd(x)) # step 2 (s <- sqrt(sum(x^2)/10 - mean(x)^2)) # step 2 population version from L&F n <- length(x) # step 3 (sxbar <- s/sqrt(n-1)) (tval <- qt(1-.05/2, 9)) # step 4: t-critical value (me <- sxbar * tval) # step 5: margin of error c(mean(x)-me, mean(x)+me) # step 6: 95% confidence interval (tval99 <- qt(1-.01/2, 9)) # same computation for 99% CI (me <- sxbar * tval99) # margin of error c(mean(x)-me, mean(x)+me) # 95% confidence interval t.test(x) # easier way to get t-distribution 95% CI t.test(x, conf.level=.99) # 99% CI