library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 2.2.1     ✔ purrr   0.2.5
## ✔ tibble  1.4.2     ✔ dplyr   0.7.5
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ readr   1.1.1     ✔ forcats 0.3.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## Evictions data
evic <- read.csv("Downloads/cities.csv", 
                 header=TRUE, 
                 stringsAsFactors = FALSE)
names(evic)
##  [1] "GEOID"                      "year"                      
##  [3] "name"                       "parent.location"           
##  [5] "population"                 "poverty.rate"              
##  [7] "renter.occupied.households" "pct.renter.occupied"       
##  [9] "median.gross.rent"          "median.household.income"   
## [11] "median.property.value"      "rent.burden"               
## [13] "pct.white"                  "pct.af.am"                 
## [15] "pct.hispanic"               "pct.am.ind"                
## [17] "pct.asian"                  "pct.nh.pi"                 
## [19] "pct.multiple"               "pct.other"                 
## [21] "eviction.filings"           "evictions"                 
## [23] "eviction.rate"              "eviction.filing.rate"      
## [25] "low.flag"                   "imputed"                   
## [27] "subbed"
# ONC data
oncDF <- read.csv("~/Desktop/MATH239/OneNightCount.csv",
                  header=TRUE,
                  stringsAsFactors = FALSE)
oncG<-oncDF%>%
  gather(City, Count, -c(Location,YEAR))

unique(oncG$City)
##  [1] "SEATTLE"         "KENT"            "NORTH.END"      
##  [4] "EAST.SIDE"       "SW.KING.CO"      "WHITE.CNTR"     
##  [7] "FEDERAL.WAY"     "RENTON"          "NIGHT.OWL.BUSES"
## [10] "AUBURN"          "VASHON.ISLAND"   "TOTAL"
evic_onc<-evic%>%
  filter(name %in% c("Auburn", "Federal Way",
                     "Kent", "Renton", 
                     "Seattle", "Vashon", 
                     "White Center"))



nameToONC<-data.frame(name=c("Auburn", "Federal Way",
                             "Kent", "Renton", 
                             "Seattle", "Vashon", 
                             "White Center"),
                      City=c("AUBURN", "FEDERAL.WAY", 
                             "KENT", "RENTON", 
                             "SEATTLE", "VASHON.ISLAND", 
                             "WHITE.CNTR"))
evicCity<-evic_onc%>%
  left_join(nameToONC, by="name")%>%
  left_join(oncG)%>%
  mutate(homeless_rate=Count/population)%>%
  filter(Location=="TOTAL")
## Warning: Column `name` joining character vector and factor, coercing into
## character vector
## Joining, by = "City"
## Warning: Column `City` joining factor and character vector, coercing into
## character vector
head(evicCity)
##     GEOID year   name parent.location population poverty.rate
## 1 5303180 2000 Auburn      Washington      40314        12.77
## 2 5303180 2000 Auburn      Washington      40314        12.77
## 3 5303180 2000 Auburn      Washington      40314        12.77
## 4 5303180 2000 Auburn      Washington      40314        12.77
## 5 5303180 2000 Auburn      Washington      40314        12.77
## 6 5303180 2000 Auburn      Washington      40314        12.77
##   renter.occupied.households pct.renter.occupied median.gross.rent
## 1                    8427.06                45.8               639
## 2                    8427.06                45.8               639
## 3                    8427.06                45.8               639
## 4                    8427.06                45.8               639
## 5                    8427.06                45.8               639
## 6                    8427.06                45.8               639
##   median.household.income median.property.value rent.burden pct.white
## 1                   39208                153400          26     79.92
## 2                   39208                153400          26     79.92
## 3                   39208                153400          26     79.92
## 4                   39208                153400          26     79.92
## 5                   39208                153400          26     79.92
## 6                   39208                153400          26     79.92
##   pct.af.am pct.hispanic pct.am.ind pct.asian pct.nh.pi pct.multiple
## 1      2.37         7.49       2.36      3.45      0.49         3.79
## 2      2.37         7.49       2.36      3.45      0.49         3.79
## 3      2.37         7.49       2.36      3.45      0.49         3.79
## 4      2.37         7.49       2.36      3.45      0.49         3.79
## 5      2.37         7.49       2.36      3.45      0.49         3.79
## 6      2.37         7.49       2.36      3.45      0.49         3.79
##   pct.other eviction.filings evictions eviction.rate eviction.filing.rate
## 1      0.13           295.43    192.79          2.29                 3.51
## 2      0.13           295.43    192.79          2.29                 3.51
## 3      0.13           295.43    192.79          2.29                 3.51
## 4      0.13           295.43    192.79          2.29                 3.51
## 5      0.13           295.43    192.79          2.29                 3.51
## 6      0.13           295.43    192.79          2.29                 3.51
##   low.flag imputed subbed   City Location YEAR Count homeless_rate
## 1        1       0      0 AUBURN    TOTAL 2016   110   0.002728581
## 2        1       0      0 AUBURN    TOTAL 2015   132   0.003274297
## 3        1       0      0 AUBURN    TOTAL 2014    97   0.002406112
## 4        1       0      0 AUBURN    TOTAL 2013    57   0.001413901
## 5        1       0      0 AUBURN    TOTAL 2012    44   0.001091432
## 6        1       0      0 AUBURN    TOTAL 2011    45   0.001116238
this.year<-2016

thisDat<-evicCity%>%
  filter(year==this.year)
mod_home<-lm(homeless_rate~median.household.income+eviction.rate, data=thisDat)
summary(mod_home)
## 
## Call:
## lm(formula = homeless_rate ~ median.household.income + eviction.rate, 
##     data = thisDat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -1.833e-03 -5.216e-04  1.819e-05  4.622e-04  1.933e-03 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              7.213e-03  9.844e-04   7.328 9.94e-10 ***
## median.household.income -5.822e-08  1.418e-08  -4.107 0.000132 ***
## eviction.rate           -2.413e-03  2.928e-04  -8.243 3.09e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0008106 on 56 degrees of freedom
##   (11 observations deleted due to missingness)
## Multiple R-squared:  0.5497, Adjusted R-squared:  0.5336 
## F-statistic: 34.18 on 2 and 56 DF,  p-value: 1.986e-10
mod_home1<-lm(homeless_rate~population+median.household.income+poverty.rate, data=thisDat)
summary(mod_home1)
## 
## Call:
## lm(formula = homeless_rate ~ population + median.household.income + 
##     poverty.rate, data = thisDat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0012830 -0.0005731 -0.0001098  0.0003178  0.0030235 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              1.916e-02  3.519e-03   5.444 1.25e-06 ***
## population               5.267e-09  6.232e-10   8.452 1.61e-11 ***
## median.household.income -2.378e-07  4.204e-08  -5.656 5.74e-07 ***
## poverty.rate            -3.768e-04  1.001e-04  -3.766 0.000406 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0007843 on 55 degrees of freedom
##   (11 observations deleted due to missingness)
## Multiple R-squared:  0.586,  Adjusted R-squared:  0.5635 
## F-statistic: 25.95 on 3 and 55 DF,  p-value: 1.361e-10
mod_home2<-lm(homeless_rate~poverty.rate+eviction.rate, data=thisDat)
summary(mod_home2)
## 
## Call:
## lm(formula = homeless_rate ~ poverty.rate + eviction.rate, data = thisDat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0015765 -0.0007216  0.0000269  0.0004056  0.0018401 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    2.285e-03  3.932e-04   5.811 3.08e-07 ***
## poverty.rate   1.287e-04  3.828e-05   3.361   0.0014 ** 
## eviction.rate -2.372e-03  3.092e-04  -7.671 2.69e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0008435 on 56 degrees of freedom
##   (11 observations deleted due to missingness)
## Multiple R-squared:  0.5125, Adjusted R-squared:  0.4951 
## F-statistic: 29.43 on 2 and 56 DF,  p-value: 1.837e-09
mod_home3<-lm(homeless_rate~rent.burden+eviction.rate, data=thisDat)
summary(mod_home3)
## 
## Call:
## lm(formula = homeless_rate ~ rent.burden + eviction.rate, data = thisDat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -2.554e-03 -6.567e-04  3.170e-06  3.910e-04  1.775e-03 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1.320e-03  1.954e-03   0.676    0.502    
## rent.burden    6.634e-05  6.497e-05   1.021    0.312    
## eviction.rate -2.070e-03  3.422e-04  -6.048 1.27e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0009161 on 56 degrees of freedom
##   (11 observations deleted due to missingness)
## Multiple R-squared:  0.4248, Adjusted R-squared:  0.4043 
## F-statistic: 20.68 on 2 and 56 DF,  p-value: 1.882e-07
mod_home4<-lm(homeless_rate~rent.burden+eviction.rate, data=thisDat)
summary(mod_home4)
## 
## Call:
## lm(formula = homeless_rate ~ rent.burden + eviction.rate, data = thisDat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -2.554e-03 -6.567e-04  3.170e-06  3.910e-04  1.775e-03 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1.320e-03  1.954e-03   0.676    0.502    
## rent.burden    6.634e-05  6.497e-05   1.021    0.312    
## eviction.rate -2.070e-03  3.422e-04  -6.048 1.27e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0009161 on 56 degrees of freedom
##   (11 observations deleted due to missingness)
## Multiple R-squared:  0.4248, Adjusted R-squared:  0.4043 
## F-statistic: 20.68 on 2 and 56 DF,  p-value: 1.882e-07