Get startedGet started for free

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

View Course

Exercise instructions

  • Use the mutate function to define four new columns: X_hat, se_hat, lower, and upper. Temporarily add these columns to the polls 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 of X_hat for each poll using the sqrt function.
  • In the lower column, calculate the lower bound of the 95% confidence interval using the qnorm function.
  • In the upper column, calculate the upper bound of the 95% confidence interval using the qnorm function.
  • Use the select function to select the columns from polls to save to the new object pollster_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.
Edit and Run Code