You are on page 1of 9

9.

2 Confidence Intervals in R
Winter 2021
Mon: 4:30-6:20pm
Wed: 5:00-6:50pm

Professor: Clarence Au
Date: Apr 7th, 2021
Learning Objectives
12.6  Determine confidence intervals using R.

Textbook

Practice Questions
Review Example

Sudbury is planning on passing a new bylaw and is interested in


what proportion of citizens plan on voting. 516 people were selected
randomly from the population, and 289 said they would vote. Find a
precise 95% confidence interval for the proportion of voters.
p hat = 0.56, q hat = 0.44, z* (based on 95%) = 1.96
SE = 0.02185
= 0.56 z* x sqrt (0.56 x 0.44 / 516)
= 0.56 z* x 0.02185
R CODE
= 0.56 1.96 (0.02185)
z.crit<-qnorm(0.95/2+0.5, 0, 1, lower.tail=TRUE)
= 0.56 0.042826 = (0.5172, 0.6028) p.hat-z.crit*SE
p.hat+z.crit*SE

lower , upper
A Guide to R – Using Functions to Create
Confidence Intervals

input
function_name<-function(var){

Do something a function

return(new_variable) }
output
Building a Confidence Interval Function
p hat, n (sample size), cl
(confidence level)

q hat = 1 – p hat, SE =
z*= qnorm (0.95/2+0.5, 0, 1,
lower.tail=TRUE)

lower and upper confidence


interval
A Guide to R – Calling a Function

function_name(var1, var2…)

Confidence_interval (p hat, n, cl)


Review Example

Sudbury is planning on passing a new bylaw and is interested in


what proportion of citizens plan on voting. 516 people were
selected randomly from the population, and 289 said they would
vote. Construct and interpret a 95% confidence interval.

CI(289/516, 516, 0.95)


Example

Sudbury is planning on passing a new bylaw and is interested in


what proportion of citizens plan on voting. 516 people were
selected randomly from the population, and 289 said they would
vote. Construct and interpret a 99% confidence interval.

CI(289/516, 516, 0.99)


Learning Check

In a random sample of 1050 adult Canadians there are 556


people that were willing to pay more for products with social and
environmental benefits.
What is a 99% confidence interval for the proportion?

CI(556/1050, 1050, 0.99)


#or
BinomCI(556, 1050, 0.99, method="wald")

You might also like