Exercise 1 - Comparing Proportions of Hits
In a previous exercise, we determined whether or not each poll predicted the correct winner for their state in the 2016 U.S. presidential election. Each poll was also assigned a grade by the poll aggregator. Now we're going to determine if polls rated A- made better predictions than polls rated C-.
In this exercise, filter the errors data for just polls with grades A- and C-. Calculate the proportion of times each grade of poll predicted the correct winner.
This exercise is part of the course
HarvardX Data Science Module 4 - Inference and Modeling
Exercise instructions
- Filter
errors
for grades A- and C-. - Group the data by grade and hit.
- Summarize the number of hits for each grade.
- Generate a two-by-two table containing the number of hits and misses for each grade. Try using the
spread
function to generate this table. - Calculate the proportion of times each grade was correct.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# The 'errors' data have already been loaded. Examine them using the `head` function.
head(errors)
# Generate an object called 'totals' that contains the numbers of good and bad predictions for polls rated A- and C-
# Print the proportion of hits for grade A- polls to the console
# Print the proportion of hits for grade C- polls to the console