library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
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. ## The data has a high value of 2296, low value of 941 with values in between like 1394, 1964, 1836, 1044. I would put the mean closer to 16-1700.

## 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? ## I would not expect another student to have identical data points because of the total amount

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] 1257.775 1480.291

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?

Conditions on the design of the study. A) It must be reasonalbe to regard the data as a random sample from a large population. Also, Conditions on the form od the population distribution. A) if N is small, the population distribution must be approximately normal. B) If n is large, the population distribution need not be normal

Exercise 4

What does “95% confidence” mean? If you’re not sure, see Section 4.2.2.

How true the data sample is to the population. How much the SE and mean is close to 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?

I would say the average of the sample does match within the confidence interval.

Exercise 6

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] 1405.989 1659.611

I would say this is still within range of our population confidence interval. A few SE away.

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))

The lower half contains the mean of the confidence interval. This number matches the population mean exaclty.

2.

Pick a confidence level of your choosing, provided it is not 95%. What is the appropriate critical value?

90%, so z = 1.64

lower_vector <- samp_mean - 1.64 * samp_sd / sqrt(n) 
upper_vector <- samp_mean + 1.64 * samp_sd / sqrt(n)

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?

c(lower_vector[1], upper_vector[1])
## [1] 1426.693 1638.907
plot_ci(lower_vector, upper_vector, mean(population))

Wow, it is the same mean, but the plot is very different. i GUESS NO MATTER THE z SCORE THE CONFIDENCE INTERVAL WILL STILL RESULT THE SAME MEAN OF THE POPULATION.