Block 2: Predicting state outcomes from polls

Week 7 · Prediction I · Imai §4.1.1 · about 4 min

NoteHow this works

Run each cell with Run Code, look at the output, then answer the question at the end of the block. Every cell is editable; Start Over resets it. Errors are information: read them.

pres08: election result by state (Obama, McCain in percent, electoral votes EV). polls08: one row = one poll (state, pollster, Obama, McCain, middate).

1. Load, compute margins and dates

How many polls, how many states?

2. The prediction: the latest polls in each state

For each state we average the margin of the polls on the latest day. Read the loop line by line: what are state.data and latest? (The data preparation runs in the background.)

Conclusion: For Alabama, is the latest poll margin (Obama minus McCain) positive or negative?
Alabama is a deep-red state: the margin is -25. Obama lost Alabama in the actual election as well (39% vs. 60%).