download.file("http://www.openintro.org/stat/data/ames.RData", destfile = "ames.RData")
load("ames.RData")
population <- ames$Gr.Liv.Area
samp <- sample(population, 60)
hist(samp)
sample_mean <- mean(samp)
mean(samp)
## [1] 1472.583
se <- sd(samp) / sqrt(60)
lower <- sample_mean - 1.96 * se
upper <- sample_mean + 1.96 * se
c(lower, upper)
## [1] 1351.138 1594.029
mean(population)
## [1] 1499.69
##Does your confidence interval capture the true average size of houses in Ames?
samp_mean <- rep(NA, 50)
samp_sd <- rep(NA, 50)
n <- 60
for(i in 1:50){
samp <- sample(population, n) # obtain a sample of size n = 60 from the population
samp_mean[i] <- mean(samp) # save sample mean in ith element of samp_mean
samp_sd[i] <- sd(samp) # save sample sd in ith element of samp_sd
}
lower_vector <- samp_mean - 1.96 * samp_sd / sqrt(n)
upper_vector <- samp_mean + 1.96 * samp_sd / sqrt(n)
c(lower_vector[1], upper_vector[1])
## [1] 1403.571 1628.363
##What proportion of your confidence intervals include the true population mean? Is this proportion exactly equal to the confidence level? If not, explain why.
plot_ci(lower_vector, upper_vector, mean(population))
##2 Pick a confidence level of your choosing, provided it is not 95%. What is the appropriate critical value?
abs(qt(.90, 49))
## [1] 1.299069
lower <- sample_mean - 1.6 * se
upper <- sample_mean + 1.6 * se
c(lower, upper)
## [1] 1373.444 1571.723