Sampling From Ames, Iowa

The Data

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)
Exercise 1
Describe the distribution of your sample. What would you say is the “typical” size within your sample? Also state precisely what you interpreted “typical” to mean.
summary(samp)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     630    1068    1430    1455    1664    4676
hist(samp, main = "Histogram of Sample (n=60) House Sizes", xlab = "House Size (sq. ft.)")

hist(samp, probability = TRUE)
x <- 500:3000
y <- dnorm(x = x, mean = mean(samp), sd = sd(samp))
lines(x = x, y = y, col = "blue")

plot(samp, main = "Plot of Sample House Size", ylab = "House Size (sq. ft.)")

table(samp) 
## samp
##  630  641  816  864  875  909  948  968  970  971  996 1040 1043 1077 1092 1155 
##    1    1    1    1    1    1    1    1    1    1    1    3    1    1    2    1 
## 1187 1222 1228 1235 1254 1264 1271 1320 1352 1388 1417 1442 1473 1481 1494 1496 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1527 1553 1555 1594 1610 1626 1630 1632 1652 1658 1680 1728 1730 1744 1764 1775 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1857 1874 1950 1969 1982 2004 2362 2473 4676 
##    1    1    1    1    1    1    1    1    1
qqnorm(samp)
qqline(samp)

shapiro.test(samp)
## 
##  Shapiro-Wilk normality test
## 
## data:  samp
## W = 0.76969, p-value = 2.556e-08
Answer: The “typical” size within the sample of 60 is between 1400 and 1500 square feet of living area. “Typical” for this data set is based on the median of the population is 1400 and the mean is 1473. However, however the data from the sample is not normal. The data is right skewed, as is shown in the histogram above, due to a few upper sized outliers, portrayed in the dotplot above. The Shapiro-Wilk p-value is: 0.0001511. Since this value is less than 0.001 there is very strong evidence for non-normality of the data. This is also supported by the qqplot above which shows consistency with the qq normality line only in the center portion of the line, near the mean and median (consistent with the CLT since n > 30), with the upper and lower quartile data distant set apart from the normality line.
Exercise 2
*Would you expect another student’s distribution to be identical to yours? Would you expect it to be similar? Why or why not?
Answer: I would not expect another student’s distribution to be identical to mine, however another student’s distribution may be very similar. This is due to the fact that each sample is randomly selected from a very large nonnormal data set. However since, the sample is over 30, it is possible that the mean of the other student’s distribution would be similar to mine with slight normalcy in the data close to the mean.

Confidence Intervals

sample_mean <- mean(samp)
se <- sd(samp) / sqrt(60)
lower <- sample_mean - 1.96 * se
upper <- sample_mean + 1.96 * se
c(lower, upper)
## [1] 1308.167 1601.700
Exercise 3
*For the confidence interval to be valid, the sample mean must be normally distributed and have standard error s/√n. What conditions must be met for this to be true? ##### Answer: As is stated above according to the central limit theorem (CLT), if a sample size is sufficiently large then even if a data set is nonnormal, the sampling mean should be normal. “Sufficiently large” is interpreted as a sample size of 30 or greater. In this case the sample size is 60, twice the required size, therefore the CLT should apply. Given that the sampling mean will be normal, the standard error formula of s/√n applies to this situation.
Exercise 4
What does “95% confidence” mean? If you’re not sure, see Section 4.2.2.
Answer: 95% confidence indicates a range of values that we are 95% certain contains the true mean of the population.
mean(population)
## [1] 1499.69
Exercise 5
Does your confidence interval capture the true average size of houses in Ames? If you are working on this lab in a classroom, does your neighbor’s interval capture this value?
Answer: Yes. My confidence interval does capture the true average size of houses in Ames. I am not working on this lab in a classroom, however I assume that nearly all of the students completing this exercise had the mean within their interval. There were likely slight variations in the exact interval minimum and maximum numbers provided based on their own random sample.
Exercise 6
Each student in your class should have gotten a slightly different confidence interval. What proportion of those intervals would you expect to capture the true population mean? Why? If you are working in this lab in a classroom, collect data on the intervals created by other students in the class and calculate the proportion of intervals that capture the true population mean.
Answer: I would expect 95% of the students in the classroom to have intervals that include the population mean. Since the confidence interval is 95% I would expect 95% of random samples taken to have that interval include the true population mean.
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] 1305.628 1585.072

On your own

1. Using the following function (which was downloaded with the data set), plot all intervals. 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?
cl <- 99
alpha <- 1-(cl/100)
cp <- 1-(alpha/2) 
cp
## [1] 0.995
Answer: The critical value for 99 is 2.57.
cl <- 68
alpha <- 1-(cl/100)
cp <- 1-(alpha/2) 
cp
## [1] 0.84
Answer: The critical value for 68 is 0.842.
cl <- 80
alpha <- 1-(cl/100)
cp <- 1-(alpha/2) 
cp
## [1] 0.9
Answer: The critical value for 80 is 1.282.
cl <- 95
alpha <- 1-(cl/100)
cp <- 1-(alpha/2) 
cp
## [1] 0.975
3. Calculate 50 confidence intervals at the confidence level you chose in the previous question. You do not need to obtain new samples, simply calculate new intervals based on the sample means and standard deviations you have already collected. Using the plot_ci function, plot all intervals and calculate the proportion of intervals that include the true population mean. How does this percentage compare to the confidence level selected for the intervals?
lower_vector <- samp_mean - 1.282 * samp_sd/sqrt(n)
upper_vector <- samp_mean + 1.282 * samp_sd/sqrt(n)
c(lower_vector[1], upper_vector[1])
## [1] 1353.96 1536.74
plot_ci(lower_vector, upper_vector, mean(population))

Answer: There are 10 out of 50 intervals that do not include the population mean. 80% of the intervals include the true population mean, which is the confidence level I selected.