QUESTION 1 Show your code for uploading and subsetting the data to create a new dataframe TO respond to question 1.

download.file("http://www.openintro.org/stat/data/atheism.RData", destfile = "atheism.RData")
load("atheism.RData")
spain12 <- subset(atheism, nationality == "Spain" & year == "2012")

ANSWER 1A:

prop.test(103, 1145, conf.level = .95)$conf.int
## [1] 0.07432656 0.10840018
## attr(,"conf.level")
## [1] 0.95

Looking at the code above, we can say that we are 95% confident that between 7.43% and 10.8% people in Spain are atheist.

ANSWER 1B:

This is a one tailed test.

H0: P = .10 Ha: P < .10

obs <- 0.09 * 1145
prop.test(obs, 1145, 0.10, alternative = "less")$p.value
## [1] 0.1403666

ANSWER 1B (cont.):

The p-value is not less than the value of significance, so we accept the null hypothesis. Not sufficient evidence that atheism declined from 2005 to 2012.

ANSWER 2:

The lower confidence level for Spain is 0.075 and the upper level is 0.108, while the lower confidence level for the U.S. is 0.637 and the upper level is 0.701. The confidence levels do not overlap because the values for the U.S. are much higher than the confidence levels for Spain. The values imply that the U.S. has a higher proportion of atheists than the Spain, with a significance of 5%.

ANSWER 3: We would have to sample 3,458 people to ensure we are within the guidelines for a margin of error of 1% and a confidence interval of 95%.

n <- ((1.96^2 *.1 * .9)/0.01^2)
n
## [1] 3457.44