Get startedGet started for free

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

View Course

Exercise instructions

  • Use the mutate function to add two new variables to the cis object: error and hit.
  • 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 the sign 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 of errors.

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`
Edit and Run Code