Block 2: Linear regression by least squares
Week 8 · Prediction II · Imai §4.2.2–4.2.3 · 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.
Linear regression: \(Y = \alpha + \beta X + \epsilon\). Choose \(\alpha\) and \(\beta\) to minimize the sum of squared residuals. (The data preparation runs in the background.)
1. Fit the line
2. The line on the plot, RMSE and predictions
Conclusion: What margin does the line predict for a Democrat with score 0.5, and how does the prediction change when the score rises by 0.1?
predict() gives +0.018 at 0.5, -0.18 at 0.2 and +0.22 at 0.8: the prediction moves 0.066 per 0.1 (the slope times 0.1). The intercept is -0.31 and the RMSE is 0.26: typical errors are large.