Exercise 2. Pollster results for p
Create a new object called pollster_results
that contains the pollster's name, the end date of the poll, the proportion of voters who declared a vote for Clinton, the standard error of this estimate, and the lower and upper bounds of the confidence interval for the estimate.
This exercise is part of the course
HarvardX Data Science Module 4 - Inference and Modeling
Exercise instructions
- Use the
mutate
function to define four new columns:X_hat
,se_hat
,lower
, andupper
. Temporarily add these columns to thepolls
object that has already been loaded for you. - In the
X_hat
column, convert the raw poll results for Clinton to a proportion. - In the
se_hat
column, calculate the standard error ofX_hat
for each poll using thesqrt
function. - In the
lower
column, calculate the lower bound of the 95% confidence interval using theqnorm
function. - In the
upper
column, calculate the upper bound of the 95% confidence interval using theqnorm
function. - Use the
select
function to select the columns frompolls
to save to the new objectpollster_results
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# The `polls` object that filtered all the data by date and nation has already been loaded. Examine it using the `head` function.
head(polls)
# Create a new object called `pollster_results` that contains columns for pollster name, end date, X_hat, se_hat, lower confidence interval, and upper confidence interval for each poll.