Discussion 9

Exercise 9.1 #14

A restaurant feeds 400 customers per day. On the average 20 percent of the customers order apple pie.

(a) Give a range (called a 95 percent confidence interval) for the number of pieces of apple pie ordered on a given day such that you can be 95 percent sure that the actual number will fall in this range.

A 95% confidence interval corresponds to being 2 standard deviations from the mean, so we will use the following formula to find the interval:

\(point\quad estimate\pm 2\times SD\\ \overline { p } \pm 2\times \sqrt { \frac { p(1-p) }{ n } }\)

#Calculating SD
p <- 0.2
n <- 400
SD <- sqrt((p*(1-p))/n)

#Calculating 95% interval
lower <- (p - (2*SD))
upper <- (p + (2*SD))

sprintf("(%f, %f)", lower, upper)
## [1] "(0.160000, 0.240000)"

We are 95% confident that between 16% and 24% of customers will order apple pie.

We multiply our lower and upper bound by 400 in order to get the range in terms of number of pieces of apple pie.

n_lower <- lower*400
n_upper <- upper*400

sprintf("(%f, %f)", n_lower, n_upper)
## [1] "(64.000000, 96.000000)"

We are 95% confident that customers will order between 64 to 96 pieces of apple pie on a given day.

(b) How many customers must the restaurant have, on the average, to be at least 95 percent sure that the number of customers ordering pie on that day falls in the 19 to 21 percent range?

We will solve this problem by looking for “n” in our SD formula, thus, we ideally want our lower bound to be 19%, and again since we want a 95% confidence level, this corresponds to 2 standard deviations from the mean:

p - 2SD = 0.19, 0.2 - 2SD = 0.19, when we solve we find that SD = 0.005, and we are left with \(0.005=\sqrt { \frac { (0.2)(0.8) }{ n } }\)

p <- 0.2
q <- 0.8
n <- (p*q)/0.005^2
n
## [1] 6400

The restaurant must have 6,400 customers on average to be at least 95% sure that the number of customers ordering pie on that day falls in the 19 to 21 percent range.

We can test it in the fomula below with n = 6,400:

#Calculating SD
p <- 0.2
n <- 6400
SD <- sqrt((p*(1-p))/n)

#Calculating 95% interval
lower <- (p - (2*SD))
upper <- (p + (2*SD))

sprintf("(%f, %f)", lower, upper)
## [1] "(0.190000, 0.210000)"