Consider the obama_vs_mccain
dataset:
State Region Obama McCain Turnout Unemployment Income Population Catholic Protestant ...
1 Alabama IV 38.74 60.32 61.6 5.9 22732 4802982 6 80
2 Alaska X 37.89 59.42 68.0 6.6 29382 721523 NA NA
3 Arizona IX 44.91 53.39 55.7 7.1 25203 6412700 29 44
4 Arkansas VI 38.86 58.72 53.1 5.8 20977 2926229 8 79
5 California IX 60.94 36.91 62.0 8.2 29020 37341989 37 35
6 Colorado VIII 53.66 44.71 70.8 5.4 29679 5044930 21 49
7 Connecticut I 60.59 38.22 NA 6.2 36468 3581628 38 36
8 District of Columbia III 92.46 6.53 62.0 7.4 40846 601723 13 59
9 Delaware III 61.91 36.93 66.7 5.9 28935 900877 26 48
10 Florida IV 50.91 48.10 67.4 7.3 26503 18900773 27 49
...
Run a linear regression of Obama
as the dependent variable and Turnout
, Unemployment
, Income
, Protestant
, Black
and Urbanization
as the (main) independent variables (the last two variables are not shown above, but you can trust that they are contained in the dataset). Exclude the District of Columbia, which will be an outlier. Store your result in an object called obama_lm
.
(from: Cotton, 2013, Learning R, O’Reilly)