```# Page 1

#Exercise 1.  Suppose I picked out a sample of 25 M&M's where 11 were blue.
#Exercise 2. p^hat = 11/25 in my case
#Exercise 3. Other people in the room all had values between about 10/25 and 18/25

#Question 1. It is very unlikely that a small sample will give a proportion that is /exactly/ equal.
#Question 2. We should give some range which we think the true proportion lies with, e.g. between 10/25 and 18/25.

#Page 2

#Question 1. (Go to http://www.rossmanchance.com/applets/OneProp/OneProp.htm?candy=2)
#Question 2. (Go to http://www.rossmanchance.com/applets/OneProp/OneProp.htm?candy=2)

#Page 3

#Question 3. (Go to http://www.rossmanchance.com/applets/OneProp/OneProp.htm?candy=2)
#Question 4. ME should be approximately equal to 0.45*(p^), such that the interval ((p^) - ME, (p^) + ME) will contain tru value of p = 0.5

#ME Excersice 2. Increasing the sample size reduces the margin of error.

#Confidence Interval Excersice 1.

#Question 1. Zc = 1.96
#Question 2. ME for 95% confidence level

n <- 25
p <- 13/25
Zc <- 1.96
ME <- Zc*(sqrt((p*(1-p))/n))
print(paste("ME = ", ME))

#Question 3. To calculate confidence interval

print("((p^) - ME ,(p^) + ME)")
print(paste("(", p-ME, " , ",p+ME  ,")"))

#Page 4

#Question 4. Yess. Confidence interval contains the true value of p = 0.5
#Question 5. 95%

#Confidence Interval Excersice 2.

#Question 1. (Go to  http://rossmanchance.com/applets/ConfSim.html)
#Question 2. (Go to  http://rossmanchance.com/applets/ConfSim.html)
#Question 3. 93,94,96,98 percent
#Question 4. After repeating step 3 multiple times, around 2 to 7 percent of intevals do not contains true value of p = 0.5
#Question 5. 90% confidence interval are narrower than 95%. 81 to 95 percent intervals contains true value of p = 0.5
#Question 6. Confidence interval width and confidence level are inversely related.

#Confidence Interval Excersice 3.
#Question 1. prop.test()
#Question 2.

test <- prop.test(13,25, conf.level = 0.95)
print(test)

#Question 3.

print("Manually calculated confidence interval")
print(paste("(", p-ME, " , ",p+ME  ,")"))
print("Confidence interval calculated using R")
print(test\$conf.int)

#Page 5

setwd("~/bd4isu/")