Regression Example

Regression is a method to summarize how predictions or averages of an outcome varies across individuals defined by a set of predictors.

Example: US Presidential elections vs economic growth in period leading up to the election:

hibbs <- read_delim('data/hibbs.dat',trim_ws=TRUE, col_types='inncc')
M1 <- stan_glm(vote ~ growth, data=hibbs)
ggplot(data=hibbs, aes(x=growth, y=vote)) +
  geom_point() + ylab('Incumbant Vote') + xlab('Precent Growth') +
  geom_abline(intercept = coef(M1)[1], slope = coef(M1)[2], col='blue')

We can examine the coefficients by printing the model:

print(M1)
## stan_glm
##  family:       gaussian [identity]
##  formula:      vote ~ growth
##  observations: 16
##  predictors:   2
## ------
##             Median MAD_SD
## (Intercept) 46.3    1.7  
## growth       3.1    0.7  
## 
## Auxiliary parameter(s):
##       Median MAD_SD
## sigma 3.9    0.8   
## 
## ------
## * For help interpreting the printed output see ?print.stanreg
## * For info on the priors used see ?prior_summary.stanreg

The median model is \(y = 46.3 + 3.0x\)