Exercise 6 - Predicting the Winner
Even if a forecaster's confidence interval is incorrect, the overall predictions will do better if they correctly called the right winner.
Add two columns to the cis
table by computing, for each poll, the difference between the predicted spread and the actual spread, and define a column hit
that is true if the signs are the same.
This exercise is part of the course
HarvardX Data Science Module 4 - Inference and Modeling
Exercise instructions
- Use the
mutate
function to add two new variables to thecis
object:error
andhit
. - For the
error
variable, subtract the actual spread from the spread. - For the
hit
variable, return "TRUE" if the poll predicted the actual winner. Use thesign
function to check if their signs match - learn more with?sign
. - Save the new table as an object called
errors
. - Use the
tail
function to examine the last 6 rows oferrors
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# The `cis` data have already been loaded. Examine it using the `head` function.
head(cis)
# Create an object called `errors` that calculates the difference between the predicted and actual spread and indicates if the correct winner was predicted
# Examine the last 6 rows of `errors`