Read in data
election = read.csv("election.csv", header=TRUE, sep = ",")
Problem 2a
cor(election$growth, election$vote_pct)
## [1] 0.6499847
Problem 2b
incumbent_pct = lm(vote_pct ~ growth, data = election)
incumbent_pct
##
## Call:
## lm(formula = vote_pct ~ growth, data = election)
##
## Coefficients:
## (Intercept) growth
## 49.6505 0.7969
Problem 2c
plot(election$growth, election$vote_pct,
pch = 16,
xlab="GDP Growth",
ylab = "Incumbent Vote Percentage",
main = "Growth vs. Vote PCT")
Problem 2d
df = as.data.frame(c(0,1,2,3,4,5))
colnames(df) = "growth"
df$pred = predict(incumbent_pct, df)
df
## growth pred
## 1 0 49.65054
## 2 1 50.44747
## 3 2 51.24441
## 4 3 52.04135
## 5 4 52.83829
## 6 5 53.63522