data <- read.csv('./Data/childpov18_southfull.csv',
colClasses = c("character", "character", "character",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric"))
View(data)
names(data)[names(data)=="X2016.child.poverty"] <- "child.pov.2016"
Subset data for information from the state of Florida
fl_pov <- data %>% subset(State == "FL")
checking data for any missing data or errors
summary(fl_pov)
## FIPS State County_Name Longitude
## Length:67 Length:67 Length:67 Min. :-87.37
## Class :character Class :character Class :character 1st Qu.:-83.53
## Mode :character Mode :character Mode :character Median :-82.30
## Mean :-82.70
## 3rd Qu.:-81.34
## Max. :-80.45
## Latitude child.pov.2016 unemployment_13 per_lhs_13
## Min. :25.49 Min. : 9.5 Min. : 4.80 Min. : 6.80
## 1st Qu.:27.59 1st Qu.:19.8 1st Qu.: 6.70 1st Qu.:12.15
## Median :29.46 Median :24.8 Median : 7.50 Median :14.80
## Mean :28.95 Mean :25.8 Mean : 7.53 Mean :16.89
## 3rd Qu.:30.27 3rd Qu.:30.3 3rd Qu.: 8.20 3rd Qu.:21.55
## Max. :30.87 Max. :43.2 Max. :11.90 Max. :35.90
## per_black_13 per_hispanic_13 per_ag_13 per_construction_13
## Min. : 2.879 Min. : 2.165 Min. : 0.2472 Min. : 3.547
## 1st Qu.: 8.564 1st Qu.: 4.991 1st Qu.: 0.6878 1st Qu.: 6.059
## Median :12.026 Median : 8.461 Median : 1.5255 Median : 7.078
## Mean :14.156 Mean :12.773 Mean : 4.0100 Mean : 7.329
## 3rd Qu.:17.316 3rd Qu.:17.251 3rd Qu.: 4.7649 3rd Qu.: 8.434
## Max. :55.038 Max. :64.862 Max. :32.9980 Max. :13.496
## per_manufacturing_13 per_retail_13 per_healthss_13 per_singlemom_13
## Min. : 0.5988 Min. : 4.824 Min. :13.20 Min. : 3.106
## 1st Qu.: 4.2823 1st Qu.:11.572 1st Qu.:19.53 1st Qu.: 8.235
## Median : 4.9995 Median :12.984 Median :21.53 Median : 9.851
## Mean : 5.7126 Mean :12.884 Mean :21.55 Mean : 9.905
## 3rd Qu.: 6.4280 3rd Qu.:14.519 3rd Qu.:23.44 3rd Qu.:11.628
## Max. :18.1385 Max. :17.608 Max. :38.73 Max. :15.867
## urban rural lnchildpov lnunemployment
## Min. :0.0000 Min. :0.00000 Min. :2.251 Min. :1.569
## 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:2.986 1st Qu.:1.902
## Median :1.0000 Median :0.00000 Median :3.211 Median :2.015
## Mean :0.6567 Mean :0.02985 Mean :3.199 Mean :2.004
## 3rd Qu.:1.0000 3rd Qu.:0.00000 3rd Qu.:3.411 3rd Qu.:2.104
## Max. :1.0000 Max. :1.00000 Max. :3.766 Max. :2.477
## lnlesshs lnblack lnhispanic lnag
## Min. :1.917 Min. :1.058 Min. :0.7723 Min. :-1.3974
## 1st Qu.:2.497 1st Qu.:2.147 1st Qu.:1.6076 1st Qu.:-0.3743
## Median :2.695 Median :2.487 Median :2.1355 Median : 0.4223
## Mean :2.752 Mean :2.468 Mean :2.2209 Mean : 0.6201
## 3rd Qu.:3.070 3rd Qu.:2.852 3rd Qu.:2.8476 3rd Qu.: 1.5612
## Max. :3.581 Max. :4.008 Max. :4.1723 Max. : 3.4964
## lnconstruction lnmanufacturing lnretail lnhealthss
## Min. :1.266 Min. :-0.5128 Min. :1.574 Min. :2.580
## 1st Qu.:1.801 1st Qu.: 1.4544 1st Qu.:2.449 1st Qu.:2.972
## Median :1.957 Median : 1.6093 Median :2.564 Median :3.070
## Mean :1.956 Mean : 1.6457 Mean :2.536 Mean :3.056
## 3rd Qu.:2.132 3rd Qu.: 1.8606 3rd Qu.:2.675 3rd Qu.:3.155
## Max. :2.602 Max. : 2.8980 Max. :2.868 Max. :3.657
## lnsinglemom lnchpov17 lnuninsured lnincome_ratio
## Min. :1.133 Min. :2.230 Min. :2.682 Min. :1.324
## 1st Qu.:2.108 1st Qu.:2.960 1st Qu.:2.989 1st Qu.:1.400
## Median :2.288 Median :3.127 Median :3.069 Median :1.483
## Mean :2.256 Mean :3.160 Mean :3.095 Mean :1.495
## 3rd Qu.:2.453 3rd Qu.:3.434 3rd Qu.:3.201 3rd Qu.:1.560
## Max. :2.764 Max. :3.940 Max. :3.503 Max. :1.840
## lnsevere_housing lnteenbirth lnunmarried
## Min. :2.269 Min. :2.833 Min. :0.010
## 1st Qu.:2.748 1st Qu.:3.547 1st Qu.:3.507
## Median :2.902 Median :3.818 Median :3.653
## Mean :2.896 Mean :3.831 Mean :3.580
## 3rd Qu.:3.043 3rd Qu.:4.106 3rd Qu.:3.858
## Max. :3.500 Max. :4.536 Max. :4.505
equation <- child.pov.2016 ~ rural + urban + lnmanufacturing + lnag +
lnretail + lnhealthss + lnconstruction + lnlesshs +
lnunemployment + lnsinglemom + lnblack + lnhispanic +
lnuninsured + lnincome_ratio + lnteenbirth + lnunmarried
limit set for numbers greater than 5 decimal places in the output and summaries
options(scipen = 5)
ols <- lm(equation, data=fl_pov)
summary(ols)
##
## Call:
## lm(formula = equation, data = fl_pov)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.5357 -2.1319 0.0606 3.2863 7.9391
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -90.98435 33.86566 -2.687 0.00977 **
## rural -10.79332 13.65817 -0.790 0.43312
## urban -2.12635 2.78053 -0.765 0.44803
## lnmanufacturing 0.01683 1.94885 0.009 0.99314
## lnag 1.62445 1.25335 1.296 0.20090
## lnretail 4.06307 4.70995 0.863 0.39245
## lnhealthss 6.91556 6.16230 1.122 0.26712
## lnconstruction 4.21861 3.58955 1.175 0.24546
## lnlesshs 5.80446 4.47108 1.298 0.20017
## lnunemployment 4.49477 7.36454 0.610 0.54441
## lnsinglemom 2.16433 4.04671 0.535 0.59513
## lnblack 0.72746 1.89375 0.384 0.70251
## lnhispanic -0.69094 2.16398 -0.319 0.75084
## lnuninsured 9.71712 9.87077 0.984 0.32964
## lnincome_ratio 6.90062 7.97192 0.866 0.39084
## lnteenbirth 1.57326 2.07719 0.757 0.45237
## lnunmarried 0.34605 3.31773 0.104 0.91735
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.917 on 50 degrees of freedom
## Multiple R-squared: 0.5971, Adjusted R-squared: 0.4682
## F-statistic: 4.632 on 16 and 50 DF, p-value: 0.00001488
There does show to be a significant p-value for OLS: p-value=.00001488.
Let’s keep going and try some spatial tests.
#Creating a list of contiguity neighbors Used to determine any spatial relationships in the residuals. In order to create a county polygon using data from Federal Information Processing Standards codes (FIPS).
fips <- county.fips
fips.codes <- separate(data = fips, col = polyname, into = c("state", "county"), sep = ",")
fl_fips <- subset(fips.codes, state=="florida", select=fips)
florida <- map(database = "county", regions = "florida", fill=T, plot=F)
fl_sp = map2SpatialPolygons(florida,fl_fips$fips,CRS("+proj=longlat"))
require(maptools)
sf::sf_use_s2(FALSE)
## Spherical geometry (s2) switched off
cleangeo like janitor, but for spatial data
file <- system.file("extdata", "example.shp", package = "cleangeo")
sp <- readShapePoly(file)
## Warning: readShapePoly is deprecated; use rgdal::readOGR or sf::st_read
cleaned <- clgeo_Clean(fl_sp)
## Warning in proj4string(sp): CRS object has comment, which is lost in output
report.clean <- clgeo_CollectionReport(cleaned)
clgeo_SummaryReport(report.clean)
## type valid issue_type
## NA's:67 Mode:logical NA's:67
## TRUE:67
neighb.data <- poly2nb(cleaned, queen=T)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
cont.neighb <- nb2listw(neighb.data,style="W", zero.policy = TRUE)
Now that we have created a spatial dataset and a list of neighbors, we can determine if there is any residual spatial dependence. # Moran’s Correlation and LaGrange Multiplier Tests examines residuals of the OLS regression with a spatial relationship matrix
lm.morantest(ols, cont.neighb)
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## Moran I statistic standard deviate = 2.4161, p-value = 0.007844
## alternative hypothesis: greater
## sample estimates:
## Observed Moran I Expectation Variance
## 0.138362502 -0.050573743 0.006115038
Looking above, we can see a significant p-value of 0.007844, so we would reject the null hypothesis that says there is no spatial correlation in the residuals.
**This would suggest we could use a spatial model to look at this data.
#LaGrange Multiplier Test
lm.LMtests(ols, cont.neighb, test="all")
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## LMerr = 2.6928, df = 1, p-value = 0.1008
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## LMlag = 1.2994, df = 1, p-value = 0.2543
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## RLMerr = 1.526, df = 1, p-value = 0.2167
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## RLMlag = 0.13272, df = 1, p-value = 0.7156
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = equation, data = fl_pov)
## weights: cont.neighb
##
## SARMA = 2.8255, df = 2, p-value = 0.2435
The results show:
LMerr LMlag RLMerr RLMlag SARMA
0.1008 0.2543 0.2167 0.7156 0.2435
Closest model would be LMerr with a p-value of 0.1008, but is still high. We can look at some other techniques.
SLX.model <- spatialreg::lmSLX(equation, data=fl_pov, cont.neighb)
summary(SLX.model)
##
## Call:
## lm(formula = formula(paste("y ~ ", paste(colnames(x)[-1], collapse = "+"))),
## data = as.data.frame(x), weights = weights)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.9927 -2.0568 -0.0043 2.4013 7.4728
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -107.77849 128.12757 -0.841 0.4061
## rural -5.76269 18.61433 -0.310 0.7588
## urban -1.54521 3.73365 -0.414 0.6816
## lnmanufacturing -2.62664 2.60719 -1.007 0.3208
## lnag 1.80951 1.44226 1.255 0.2182
## lnretail 0.82431 5.49114 0.150 0.8816
## lnhealthss -3.85507 7.94030 -0.486 0.6304
## lnconstruction 5.41070 4.41202 1.226 0.2285
## lnlesshs 1.91850 5.57862 0.344 0.7330
## lnunemployment 9.11259 10.34407 0.881 0.3845
## lnsinglemom 5.08905 5.23966 0.971 0.3383
## lnblack 0.86955 2.38109 0.365 0.7172
## lnhispanic -0.02924 3.09028 -0.009 0.9925
## lnuninsured 1.83023 12.64017 0.145 0.8857
## lnincome_ratio 10.37007 9.54845 1.086 0.2851
## lnteenbirth 2.31784 2.54917 0.909 0.3696
## lnunmarried 1.28510 4.63295 0.277 0.7832
## lag.rural -12.26697 34.62787 -0.354 0.7253
## lag.urban -9.11103 8.40301 -1.084 0.2859
## lag.lnmanufacturing 3.97812 5.90102 0.674 0.5048
## lag.lnag 1.84862 3.15880 0.585 0.5623
## lag.lnretail 24.12769 13.32925 1.810 0.0791 .
## lag.lnhealthss 25.66410 17.09610 1.501 0.1425
## lag.lnconstruction -1.68061 11.71790 -0.143 0.8868
## lag.lnlesshs 3.49059 13.26319 0.263 0.7940
## lag.lnunemployment -15.86400 20.88975 -0.759 0.4528
## lag.lnsinglemom -4.08135 12.64943 -0.323 0.7489
## lag.lnblack -1.86342 5.52750 -0.337 0.7381
## lag.lnhispanic 2.72957 6.45089 0.423 0.6749
## lag.lnuninsured -11.81837 31.32179 -0.377 0.7083
## lag.lnincome_ratio -7.79462 22.29783 -0.350 0.7288
## lag.lnteenbirth 2.52898 5.77249 0.438 0.6641
## lag.lnunmarried -1.09233 9.15226 -0.119 0.9057
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.725 on 34 degrees of freedom
## Multiple R-squared: 0.7435, Adjusted R-squared: 0.5021
## F-statistic: 3.08 on 32 and 34 DF, p-value: 0.0008246
One-way interaction where potentially our neighbors have an impact on us, but that is the limit of the interactions.
No significance among the lag variables.
Now to examine the combined impacts of the x and lagged x variables.
summary(spatialreg::impacts(SLX.model, cont.neighb), zstats = TRUE)[["pzmat"]]
## Direct Indirect Total
## rural 0.7568776 0.7231506 0.6629451
## urban 0.6789763 0.2782505 0.3093468
## lnmanufacturing 0.3137132 0.5002216 0.8369565
## lnag 0.2096115 0.5583953 0.2962940
## lnretail 0.8806733 0.0702754 0.1089580
## lnhealthss 0.6273167 0.1333123 0.1616722
## lnconstruction 0.2200653 0.8859567 0.7868536
## lnlesshs 0.7309193 0.7924129 0.6856755
## lnunemployment 0.3783459 0.4476043 0.7472062
## lnsinglemom 0.3314208 0.7469595 0.9431870
## lnblack 0.7149698 0.7360284 0.8782394
## lnhispanic 0.9924503 0.6722002 0.6790580
## lnuninsured 0.8848728 0.7059351 0.7659406
## lnincome_ratio 0.2774579 0.7266627 0.9201027
## lnteenbirth 0.3632155 0.6613069 0.4897173
## lnunmarried 0.7814867 0.9049970 0.9868011
Not much to see above.
#Spatial Lag Model
Remember that the Spatial Lag Model is a global model where the dependent variable among our neighbors influences our dependent variable.
sp.lag.model <- spatialreg::lagsarlm(equation, data=fl_pov, cont.neighb)
summary(sp.lag.model, Nagelkerke = TRUE)
##
## Call:
## spatialreg::lagsarlm(formula = equation, data = fl_pov, listw = cont.neighb)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.393219 -2.298661 0.081436 3.451123 8.622888
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -87.04223 28.87946 -3.0140 0.002578
## rural -9.97734 11.57589 -0.8619 0.388739
## urban -1.51848 2.36398 -0.6423 0.520652
## lnmanufacturing -0.49291 1.65183 -0.2984 0.765397
## lnag 1.30377 1.06584 1.2232 0.221245
## lnretail 2.59973 4.01568 0.6474 0.517377
## lnhealthss 4.48096 5.29580 0.8461 0.397478
## lnconstruction 4.19502 3.04401 1.3781 0.168166
## lnlesshs 6.01418 3.78942 1.5871 0.112490
## lnunemployment 6.42540 6.29793 1.0202 0.307614
## lnsinglemom 2.92494 3.46392 0.8444 0.398444
## lnblack 0.85063 1.61179 0.5278 0.597669
## lnhispanic -0.75509 1.83410 -0.4117 0.680562
## lnuninsured 8.30324 8.49835 0.9770 0.328549
## lnincome_ratio 7.23122 6.75731 1.0701 0.284560
## lnteenbirth 1.37470 1.76359 0.7795 0.435693
## lnunmarried 0.45913 2.81190 0.1633 0.870296
##
## Rho: 0.22107, LR test value: 1.7787, p-value: 0.18231
## Asymptotic standard error: 0.1304
## z-value: 1.6953, p-value: 0.090027
## Wald statistic: 2.8739, p-value: 0.090027
##
## Log likelihood: -203.4871 for lag model
## ML residual variance (sigma squared): 25.147, (sigma: 5.0147)
## Nagelkerke pseudo-R-squared: 0.60768
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 444.97, (AIC for lm: 444.75)
## LM test for residual autocorrelation
## test value: 4.1081, p-value: 0.042678
High non-significant p-value of 0.18231
summary(spatialreg::impacts(sp.lag.model, listw = cont.neighb, R=100), zstats = TRUE)[["pzmat"]]
## Direct Indirect Total
## rural 0.32724646 0.4851426 0.33553324
## urban 0.63013363 0.7269717 0.64010873
## lnmanufacturing 0.82195512 0.8781106 0.83195836
## lnag 0.26860951 0.4816283 0.29067653
## lnretail 0.46163246 0.5953601 0.47356922
## lnhealthss 0.37220919 0.5577882 0.38307783
## lnconstruction 0.16861033 0.4084414 0.18752933
## lnlesshs 0.07543541 0.3129556 0.08778777
## lnunemployment 0.32562564 0.4732610 0.34859265
## lnsinglemom 0.42076171 0.4969440 0.41728056
## lnblack 0.52321249 0.6260286 0.52672065
## lnhispanic 0.62659837 0.6713015 0.62232206
## lnuninsured 0.26666701 0.4372395 0.27359192
## lnincome_ratio 0.36591033 0.4699139 0.37264230
## lnteenbirth 0.55364005 0.7170296 0.58163361
## lnunmarried 0.94264083 0.8989204 0.92779570
Now for closest spatial model: Spatial Error Model
#Spatial Error Model
sp.err.model <- spatialreg::errorsarlm(equation, data=fl_pov, cont.neighb)
summary(sp.err.model, Nagelkerke = TRUE)
##
## Call:
## spatialreg::errorsarlm(formula = equation, data = fl_pov, listw = cont.neighb)
##
## Residuals:
## Min 1Q Median 3Q Max
## -18.89049 -1.92268 0.22525 2.60905 9.22989
##
## Type: error
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -77.65217 28.86801 -2.6899 0.007147
## rural -4.66943 10.83498 -0.4310 0.666498
## urban -0.57803 2.06319 -0.2802 0.779351
## lnmanufacturing -2.41776 1.61501 -1.4971 0.134378
## lnag 0.98122 1.00138 0.9799 0.327151
## lnretail -0.34792 3.51838 -0.0989 0.921228
## lnhealthss 1.19510 5.39773 0.2214 0.824776
## lnconstruction 4.62089 2.72070 1.6984 0.089428
## lnlesshs 5.88513 3.54609 1.6596 0.096993
## lnunemployment 8.59968 6.31854 1.3610 0.173506
## lnsinglemom 2.55664 3.27098 0.7816 0.434442
## lnblack 1.97198 1.44762 1.3622 0.173127
## lnhispanic -0.65460 1.96938 -0.3324 0.739596
## lnuninsured 10.10061 8.32074 1.2139 0.224783
## lnincome_ratio 8.34966 6.09057 1.3709 0.170401
## lnteenbirth 1.33029 1.52156 0.8743 0.381957
## lnunmarried 1.14786 2.50481 0.4583 0.646764
##
## Lambda: 0.57064, LR test value: 7.6314, p-value: 0.0057362
## Asymptotic standard error: 0.11507
## z-value: 4.9589, p-value: 0.00000070897
## Wald statistic: 24.591, p-value: 0.00000070897
##
## Log likelihood: -200.5607 for error model
## ML residual variance (sigma squared): 21.287, (sigma: 4.6137)
## Nagelkerke pseudo-R-squared: 0.6405
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 439.12, (AIC for lm: 444.75)
**Note the significant p-value. The most significant variables are construction work with a p-value of 0.089 and less than high school degree with a p-value of 0.096.
spatialreg::Hausman.test(sp.err.model)
##
## Spatial Hausman test (asymptotic)
##
## data: NULL
## Hausman test = 15.559, df = 17, p-value = 0.5553
The Hausman test resulted in a high p-value of 0.5553, which would fail to reject the null hypothesis that spatial error model is needed.
#Spatial Durbin Error Model
The results of this model can determine if lagged y, error, or lagged x values are important in the model, or whether the model should be simplifed to include only the lagged y values (lag model), lagged x values (SLX), the errors (error model), or a simple OLS. The Spatial Durbin Error Model contains components of OLS, SLX, and Spatial Error models. The results of this model can determine if both errors and lagged x values are important in the model, or whether the model should be simplifed to include only the lagged x values (SLX), the errors (error model), or a simple OLS.
The Spatial Durbin Error Model contains components of OLS, SLX, and Spatial Error models.
sd.err <- spatialreg::errorsarlm(equation, fl_pov, cont.neighb, etype = "emixed")
sdm <- spatialreg::lagsarlm(equation, fl_pov, cont.neighb, type = "mixed")
Remembering that the Spatial Durbin Error Model is a local model which includes the errors and lag x values, we can view a summary of that model.
summary(sd.err, Nagelkerke = TRUE)
##
## Call:
## spatialreg::errorsarlm(formula = equation, data = fl_pov, listw = cont.neighb,
## etype = "emixed")
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.0540 -2.7501 0.1192 2.4125 6.6689
##
## Type: error
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -66.36229 86.92271 -0.7635 0.445187
## rural -7.46181 13.70401 -0.5445 0.586098
## urban -2.34505 2.56066 -0.9158 0.359772
## lnmanufacturing -3.42804 1.85339 -1.8496 0.064370
## lnag 1.78271 1.03683 1.7194 0.085545
## lnretail 0.47045 3.75805 0.1252 0.900378
## lnhealthss -5.62065 5.79588 -0.9698 0.332163
## lnconstruction 5.78170 3.06341 1.8873 0.059114
## lnlesshs 0.59343 3.86048 0.1537 0.877832
## lnunemployment 10.35068 7.35782 1.4068 0.159499
## lnsinglemom 4.59901 3.76958 1.2200 0.222452
## lnblack 0.91187 1.68161 0.5423 0.587636
## lnhispanic 0.22939 2.26785 0.1011 0.919434
## lnuninsured 3.01887 9.30083 0.3246 0.745499
## lnincome_ratio 12.56086 6.55894 1.9151 0.055483
## lnteenbirth 3.10961 1.72023 1.8077 0.070658
## lnunmarried 0.91490 3.36565 0.2718 0.785750
## lag.rural -24.82528 24.48394 -1.0139 0.310611
## lag.urban -9.42667 5.86477 -1.6073 0.107981
## lag.lnmanufacturing 2.72568 4.28129 0.6366 0.524353
## lag.lnag 2.01369 2.18165 0.9230 0.356001
## lag.lnretail 26.55530 8.72364 3.0441 0.002334
## lag.lnhealthss 26.52600 11.77224 2.2533 0.024242
## lag.lnconstruction -5.27437 8.19452 -0.6436 0.519805
## lag.lnlesshs 8.75007 9.05500 0.9663 0.333881
## lag.lnunemployment -14.32580 14.51160 -0.9872 0.323547
## lag.lnsinglemom -8.00408 8.70547 -0.9194 0.357870
## lag.lnblack -0.06083 3.65177 -0.0167 0.986710
## lag.lnhispanic 4.06342 4.85157 0.8375 0.402285
## lag.lnuninsured -24.73316 22.72526 -1.0884 0.276438
## lag.lnincome_ratio -15.14975 14.74081 -1.0277 0.304071
## lag.lnteenbirth 3.65333 3.91610 0.9329 0.350872
## lag.lnunmarried -3.79596 6.31737 -0.6009 0.547922
##
## Lambda: -0.42012, LR test value: 1.8444, p-value: 0.17444
## Asymptotic standard error: 0.18106
## z-value: -2.3203, p-value: 0.020325
## Wald statistic: 5.3838, p-value: 0.020325
##
## Log likelihood: -188.3277 for error model
## ML residual variance (sigma squared): 15.577, (sigma: 3.9468)
## Nagelkerke pseudo-R-squared: 0.75047
## Number of observations: 67
## Number of parameters estimated: 35
## AIC: 446.66, (AIC for lm: 446.5)
Many of the lag variables, apart from retail and working in healthcare, were not significant, which supports use of an error model. We do see some significance with variables: work in manufacturing, ag, construction, and income ratio.
Examining the impacts matrix as we have before we can determine if the Spatial Durbin Error Model is the most appropriate model for our data or if we should restrict the model to a spatial error, SLX, or OLS model.
summary(spatialreg::impacts(sd.err, listw = cont.neighb, R = 100), zstats = TRUE)[["pzmat"]]
## Direct Indirect Total
## rural 0.58609834 0.310610777 0.233732864
## urban 0.35977182 0.107980513 0.083569441
## lnmanufacturing 0.06437047 0.524352981 0.873096624
## lnag 0.08554457 0.356001048 0.085977072
## lnretail 0.90037774 0.002334084 0.003892412
## lnhealthss 0.33216303 0.024242357 0.028273091
## lnconstruction 0.05911435 0.519805087 0.955382668
## lnlesshs 0.87783181 0.333881447 0.259167548
## lnunemployment 0.15949885 0.323546578 0.761982837
## lnsinglemom 0.22245213 0.357869941 0.710871911
## lnblack 0.58763642 0.986709766 0.831126928
## lnhispanic 0.91943410 0.402284986 0.348910928
## lnuninsured 0.74549861 0.276438213 0.345146270
## lnincome_ratio 0.05548308 0.304071161 0.868272521
## lnteenbirth 0.07065765 0.350871871 0.123940227
## lnunmarried 0.78574960 0.547922152 0.707495941
*** This model did however, produce significant results for variables retail and healthss, but not many of the impacts are significant, meaning it may be best to use spatial error, SLX, or OLS models.
This will help us test the HO that we should restrict the model to a more simple model. *****The first step is to determine if we should restrict the model from a Spatial Durbin Error model to a spatial error mode.
LR.Sarlm(sd.err,sp.err.model)
##
## Likelihood ratio for spatial linear models
##
## data:
## Likelihood ratio = 24.466, df = 16, p-value = 0.07981
## sample estimates:
## Log likelihood of sd.err Log likelihood of sp.err.model
## -188.3277 -200.5607
For this model, we would fail to reject the null hypothesis with a p-value of 0.079. ****means restrict the model to a spatial error model.
#Creating a list of K-neighbors
create xy data from the polygons
all.xy <-centroid(fl_sp)
colnames(all.xy) <- c("x","y")
We will examine k = 1, k = 3, and k = 5. Then we need to calculate the distance value so the model can create a radius to encompass the neighbors. Finally, we need to produce the list of neighbors within the neighborhood.
#Create neighbors
all.dist.k1 <- knn2nb(knearneigh(all.xy, k=1, longlat = TRUE))
all.dist.k3 <- knn2nb(knearneigh(all.xy, k=3, longlat = TRUE))
all.dist.k5 <- knn2nb(knearneigh(all.xy, k=5, longlat = TRUE))
all.dist.k9 <- knn2nb(knearneigh(all.xy, k=9, longlat = TRUE))
#Determine max k distance value to neighbor
all.max.k1 <- max(unlist(nbdists(all.dist.k1, all.xy, longlat=TRUE)))
all.max.k3 <- max(unlist(nbdists(all.dist.k3, all.xy, longlat=TRUE)))
all.max.k5 <- max(unlist(nbdists(all.dist.k5, all.xy, longlat=TRUE)))
all.max.k9 <- max(unlist(nbdists(all.dist.k9, all.xy, longlat=TRUE)))
#Calculate neighbors based on distance
all.sp.dist.k1 <- dnearneigh(all.xy, d1=0, d2=1 * all.max.k1, longlat = TRUE)
all.sp.dist.k3 <- dnearneigh(all.xy, d1=0, d2=1 * all.max.k3, longlat = TRUE)
all.sp.dist.k5 <- dnearneigh(all.xy, d1=0, d2=1 * all.max.k5, longlat = TRUE)
all.sp.dist.k9 <- dnearneigh(all.xy, d1=0, d2=1 * all.max.k9, longlat = TRUE)
#Create neighbor list
all.dist.neighb.k1 <- nb2listw(all.sp.dist.k1,style="W", zero.policy = TRUE)
all.dist.neighb.k3 <- nb2listw(all.sp.dist.k3,style="W", zero.policy = TRUE)
all.dist.neighb.k5 <- nb2listw(all.sp.dist.k5,style="W", zero.policy = TRUE)
all.dist.neighb.k9 <- nb2listw(all.sp.dist.k9,style="W", zero.policy = TRUE)
#Distance Lag Model
calculating distance for k=1, k=3, and k=5
all.dist.lag.k1 <- spatialreg::lagsarlm(equation, data = fl_pov, listw = all.dist.neighb.k1)
all.dist.lag.k3 <- spatialreg::lagsarlm(equation, data = fl_pov, listw = all.dist.neighb.k3)
all.dist.lag.k5 <- spatialreg::lagsarlm(equation, data = fl_pov, listw = all.dist.neighb.k5)
all.dist.lag.k9 <- spatialreg::lagsarlm(equation, data = fl_pov, listw = all.dist.neighb.k9)
Summary for k=1 for distance lag model
summary(all.dist.lag.k1, Nagelkerke = TRUE)
##
## Call:
## spatialreg::lagsarlm(formula = equation, data = fl_pov, listw = all.dist.neighb.k1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.439700 -2.255317 0.038032 3.237488 8.238631
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -91.06519 29.10108 -3.1293 0.001752
## rural -9.85041 11.73568 -0.8394 0.401270
## urban -1.94268 2.39254 -0.8120 0.416807
## lnmanufacturing -0.14354 1.67456 -0.0857 0.931691
## lnag 1.42989 1.08824 1.3139 0.188865
## lnretail 3.68119 4.04557 0.9099 0.362859
## lnhealthss 5.93190 5.33416 1.1121 0.266113
## lnconstruction 4.38651 3.08358 1.4225 0.154870
## lnlesshs 5.86788 3.84355 1.5267 0.126840
## lnunemployment 5.26110 6.34438 0.8293 0.406961
## lnsinglemom 2.47765 3.49280 0.7094 0.478101
## lnblack 0.83466 1.62787 0.5127 0.608138
## lnhispanic -0.61968 1.86082 -0.3330 0.739121
## lnuninsured 8.76861 8.60513 1.0190 0.308204
## lnincome_ratio 7.43093 6.84848 1.0850 0.277900
## lnteenbirth 1.59892 1.78488 0.8958 0.370352
## lnunmarried 0.51649 2.85081 0.1812 0.856232
##
## Rho: 0.09843, LR test value: 0.55789, p-value: 0.45511
## Asymptotic standard error: 0.11065
## z-value: 0.88956, p-value: 0.3737
## Wald statistic: 0.79132, p-value: 0.3737
##
## Log likelihood: -204.0975 for lag model
## ML residual variance (sigma squared): 25.827, (sigma: 5.082)
## Nagelkerke pseudo-R-squared: 0.60046
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 446.19, (AIC for lm: 444.75)
## LM test for residual autocorrelation
## test value: 3.5943, p-value: 0.057977
For k=1, there is a high p-value of 0.455.
Now summary for k=3
summary(all.dist.lag.k3, Nagelkerke = TRUE)
##
## Call:
## spatialreg::lagsarlm(formula = equation, data = fl_pov, listw = all.dist.neighb.k3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.590815 -1.883141 0.025802 3.038713 8.046561
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -85.51925 29.56018 -2.8931 0.003815
## rural -11.46826 11.76901 -0.9744 0.329835
## urban -2.15439 2.39926 -0.8979 0.369219
## lnmanufacturing 0.12118 1.68301 0.0720 0.942600
## lnag 1.72588 1.08144 1.5959 0.110509
## lnretail 4.17542 4.05311 1.0302 0.302927
## lnhealthss 7.50344 5.30319 1.4149 0.157100
## lnconstruction 4.04843 3.08893 1.3106 0.189984
## lnlesshs 5.91115 3.85660 1.5327 0.125341
## lnunemployment 4.12892 6.34220 0.6510 0.515032
## lnsinglemom 2.06864 3.48639 0.5933 0.552950
## lnblack 0.66404 1.63151 0.4070 0.684000
## lnhispanic -0.77434 1.87479 -0.4130 0.679586
## lnuninsured 9.86235 8.59990 1.1468 0.251465
## lnincome_ratio 5.99832 6.86100 0.8743 0.381975
## lnteenbirth 1.50597 1.78900 0.8418 0.399903
## lnunmarried 0.10519 2.86488 0.0367 0.970711
##
## Rho: -0.16616, LR test value: 0.35553, p-value: 0.551
## Asymptotic standard error: 0.22566
## z-value: -0.73635, p-value: 0.46152
## Wald statistic: 0.54221, p-value: 0.46152
##
## Log likelihood: -204.1986 for lag model
## ML residual variance (sigma squared): 25.924, (sigma: 5.0916)
## Nagelkerke pseudo-R-squared: 0.59926
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 446.4, (AIC for lm: 444.75)
## LM test for residual autocorrelation
## test value: 2.8304, p-value: 0.092497
Another high p-value when looking at k=3
summary for k=5
summary(all.dist.lag.k5, Nagelkerke = TRUE)
##
## Call:
## spatialreg::lagsarlm(formula = equation, data = fl_pov, listw = all.dist.neighb.k5)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.764074 -1.875385 0.057619 2.937377 7.806374
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -75.11955 30.53059 -2.4605 0.01388
## rural -10.95274 11.66880 -0.9386 0.34792
## urban -1.95360 2.37577 -0.8223 0.41090
## lnmanufacturing 0.19370 1.66727 0.1162 0.90751
## lnag 1.72940 1.06973 1.6167 0.10595
## lnretail 3.75739 4.02388 0.9338 0.35042
## lnhealthss 6.86005 5.31616 1.2904 0.19691
## lnconstruction 3.89830 3.06631 1.2713 0.20361
## lnlesshs 5.19459 3.83217 1.3555 0.17525
## lnunemployment 4.72378 6.28569 0.7515 0.45234
## lnsinglemom 2.41993 3.45485 0.7004 0.48365
## lnblack 0.75824 1.62249 0.4673 0.64026
## lnhispanic -0.85950 1.86767 -0.4602 0.64537
## lnuninsured 9.56863 8.53577 1.1210 0.26229
## lnincome_ratio 6.54787 6.82980 0.9587 0.33770
## lnteenbirth 1.46359 1.77306 0.8255 0.40911
## lnunmarried 0.14000 2.84366 0.0492 0.96073
##
## Rho: -0.44113, LR test value: 0.99821, p-value: 0.31774
## Asymptotic standard error: 0.36556
## z-value: -1.2067, p-value: 0.22753
## Wald statistic: 1.4562, p-value: 0.22753
##
## Log likelihood: -203.8773 for lag model
## ML residual variance (sigma squared): 25.502, (sigma: 5.0499)
## Nagelkerke pseudo-R-squared: 0.60308
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 445.75, (AIC for lm: 444.75)
## LM test for residual autocorrelation
## test value: 12.626, p-value: 0.00038038
Summary for k=9
summary(all.dist.lag.k9, Nagelkerke = TRUE)
##
## Call:
## spatialreg::lagsarlm(formula = equation, data = fl_pov, listw = all.dist.neighb.k9)
##
## Residuals:
## Min 1Q Median 3Q Max
## -19.89170 -2.10754 0.10097 2.93051 8.11083
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -43.742469 33.032567 -1.3242 0.1854
## rural -7.606373 11.171539 -0.6809 0.4960
## urban -1.810781 2.283536 -0.7930 0.4278
## lnmanufacturing -0.218313 1.598295 -0.1366 0.8914
## lnag 1.546575 1.025513 1.5081 0.1315
## lnretail 3.705166 3.852276 0.9618 0.3361
## lnhealthss 5.386195 5.211044 1.0336 0.3013
## lnconstruction 3.690656 2.943141 1.2540 0.2098
## lnlesshs 5.466702 3.663311 1.4923 0.1356
## lnunemployment 4.740590 6.029240 0.7863 0.4317
## lnsinglemom 1.416634 3.317687 0.4270 0.6694
## lnblack 1.207983 1.572358 0.7683 0.4423
## lnhispanic -0.031701 1.770047 -0.0179 0.9857
## lnuninsured 5.716757 8.073327 0.7081 0.4789
## lnincome_ratio 9.208319 6.614922 1.3921 0.1639
## lnteenbirth 1.487104 1.699795 0.8749 0.3816
## lnunmarried 0.959698 2.713991 0.3536 0.7236
##
## Rho: -1.3037, LR test value: 4.3867, p-value: 0.03622
## Asymptotic standard error: 0.54869
## z-value: -2.376, p-value: 0.017502
## Wald statistic: 5.6453, p-value: 0.017502
##
## Log likelihood: -202.183 for lag model
## ML residual variance (sigma squared): 23.419, (sigma: 4.8393)
## Nagelkerke pseudo-R-squared: 0.62266
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 442.37, (AIC for lm: 444.75)
## LM test for residual autocorrelation
## test value: 3.0579, p-value: 0.080346
For k=9, there is a significant p-value of 0.03622
#K-distance Error Model
Run for neighbors 1,3,5, and 9
all.dist.err.k1 <- spatialreg::errorsarlm(equation, data = fl_pov, listw = all.dist.neighb.k1)
all.dist.err.k3 <- spatialreg::errorsarlm(equation, data = fl_pov, listw = all.dist.neighb.k3)
all.dist.err.k5 <- spatialreg::errorsarlm(equation, data = fl_pov, listw = all.dist.neighb.k5)
all.dist.err.k9 <- spatialreg::errorsarlm(equation, data = fl_pov, listw = all.dist.neighb.k9)
**Distance error model for just k=1.
summary(all.dist.err.k1, Nagelkerke = TRUE)
##
## Call:
## spatialreg::errorsarlm(formula = equation, data = fl_pov, listw = all.dist.neighb.k1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -19.5104558 -1.8676623 0.0022013 2.5168449 9.6488607
##
## Type: error
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -88.99295 28.29785 -3.1449 0.001662
## rural -5.73112 11.18617 -0.5123 0.608413
## urban -1.29278 2.15594 -0.5996 0.548747
## lnmanufacturing -1.42006 1.61559 -0.8790 0.379415
## lnag 1.37140 1.11193 1.2333 0.217445
## lnretail 0.47835 3.68657 0.1298 0.896760
## lnhealthss 2.94828 5.25330 0.5612 0.574644
## lnconstruction 5.15856 2.77374 1.8598 0.062916
## lnlesshs 4.91330 3.56602 1.3778 0.168262
## lnunemployment 7.49766 6.25590 1.1985 0.230724
## lnsinglemom 1.94801 3.29134 0.5919 0.553945
## lnblack 2.03029 1.47045 1.3807 0.167361
## lnhispanic -0.66007 1.92542 -0.3428 0.731734
## lnuninsured 11.93894 8.25986 1.4454 0.148341
## lnincome_ratio 10.06912 6.13112 1.6423 0.100528
## lnteenbirth 1.35922 1.58934 0.8552 0.392434
## lnunmarried 0.94519 2.57484 0.3671 0.713553
##
## Lambda: 0.44563, LR test value: 5.6989, p-value: 0.016975
## Asymptotic standard error: 0.11511
## z-value: 3.8712, p-value: 0.0001083
## Wald statistic: 14.986, p-value: 0.0001083
##
## Log likelihood: -201.5269 for error model
## ML residual variance (sigma squared): 22.325, (sigma: 4.7249)
## Nagelkerke pseudo-R-squared: 0.62998
## Number of observations: 67
## Number of parameters estimated: 19
## AIC: 441.05, (AIC for lm: 444.75)
This model with k=1 was significant with a p-value of 0.0169, the closest variable is construction.
#Mapping the results for child poverty and Retail Work
dist.err.data <- summary(all.dist.err.k1, correlation=TRUE, Nagelkerke = TRUE)
dist.err.output <- cbind.data.frame(fl_pov$FIPS,
dist.err.data$fitted.values,
dist.err.data$residual,
fl_pov$child.pov.2016,
fl_pov$lnretail,
fl_pov$lnhealthss,
fl_pov$lnincome_ratio,
stringsAsFactors = FALSE)
#Renaming columns
colnames(dist.err.output) <- c("fips","fitted","resid","childpov",
"Retail","Healthss","Income Ratio")
fl_fortify <- fortify(fl_sp)
fl_poly <- merge(x = fl_fortify, y = dist.err.output,
by.x = "id", by.y = "fips", all = TRUE)
bivariate_data <- bi_class(fl_poly, x = childpov, y = Retail,
dim = 3, style = "quantile")
legend <- bi_legend(pal = "GrPink",
dim = 3,
xlab = "Child Poverty",
ylab = "Retail Work",
size = 6)
world <- map_data("world")
states <- map_data("state")
southern_states <- subset(states, region %in%
c("texas", "arkansas", "louisiana", "mississippi",
"alabama", "georgia", "florida", "north carolina",
"south carolina", "tennessee", "oklahoma",
"kentucky", "west virginia", "virginia",
"maryland", "delaware", "district of columbia"))
retail_pov_map <- ggplot() +
geom_polygon(data = world, aes(x=long,y=lat, group=group), fill = "gray95", color = "white") +
geom_polygon(data = states, aes(x=long,y=lat, group=group), fill = "gray", color = "white") +
geom_polygon(data = southern_states, aes(x=long,y=lat, group=group), fill = NA, size = 0.01, color = "white") +
geom_polygon(data = bivariate_data, aes(x=long, y=lat, group=group, fill = bi_class), color = "grey50", show.legend = FALSE) +
bi_scale_fill(pal = "GrPink", dim = 3) +
coord_map("conic", lat0 = 30, xlim=c(-88,-80), ylim=c(24,31)) +
theme_void() + theme(legend.title.align=0.5) +
theme(panel.background = element_rect(fill = 'deepskyblue'),
panel.grid.major = element_line(colour = NA)) +
labs(x = "Longitude", y = "Latitude", fill = "Child Poverty",
title = "Bivariate Map of Child Poverty and Retail Work") +
theme(plot.title = element_text(face = "bold", hjust = 0.5))
retail_pov_map
legend_map <- ggdraw() +
draw_plot(retail_pov_map, 0, 0, 1, 1) +
draw_plot(legend, -0.000000444, 0.12, 0.6, 0.30)
legend_map
#Mapping the results for child poverty and Healthss
dist.err.data1 <- summary(all.dist.err.k1, correlation=TRUE, Nagelkerke = TRUE)
dist.err.output1 <- cbind.data.frame(fl_pov$FIPS,
dist.err.data1$fitted.values,
dist.err.data1$residual,
fl_pov$child.pov.2016,
fl_pov$lnretail,
fl_pov$lnhealthss,
fl_pov$lnincome_ratio,
stringsAsFactors = FALSE)
#Renaming columns
colnames(dist.err.output1) <- c("fips","fitted","resid","childpov",
"Retail","Healthss","Income Ratio")
fl_fortify1 <- fortify(fl_sp)
fl_poly <- merge(x = fl_fortify, y = dist.err.output1,
by.x = "id", by.y = "fips", all = TRUE)
bivariate_data1 <- bi_class(fl_poly, x = childpov, y = Healthss,
dim = 3, style = "quantile")
legend1 <- bi_legend(pal = "GrPink",
dim = 3,
xlab = "Child Poverty",
ylab = "Health SS",
size = 6)
world <- map_data("world")
states <- map_data("state")
southern_states <- subset(states, region %in%
c("texas", "arkansas", "louisiana", "mississippi",
"alabama", "georgia", "florida", "north carolina",
"south carolina", "tennessee", "oklahoma",
"kentucky", "west virginia", "virginia",
"maryland", "delaware", "district of columbia"))
healthss_pov_map1 <- ggplot() +
geom_polygon(data = world, aes(x=long,y=lat, group=group), fill = "gray95", color = "white") +
geom_polygon(data = states, aes(x=long,y=lat, group=group), fill = "gray", color = "white") +
geom_polygon(data = southern_states, aes(x=long,y=lat, group=group), fill = NA, size = 0.01, color = "white") +
geom_polygon(data = bivariate_data1, aes(x=long, y=lat, group=group, fill = bi_class), color = "grey50", show.legend = FALSE) +
bi_scale_fill(pal = "GrPink", dim = 3) +
coord_map("conic", lat0 = 30, xlim=c(-88,-80), ylim=c(24,31)) +
theme_void() + theme(legend.title.align=0.5) +
theme(panel.background = element_rect(fill = 'deepskyblue'),
panel.grid.major = element_line(colour = NA)) +
labs(x = "Longitude", y = "Latitude", fill = "Child Poverty",
title = "Bivariate Map of Child Poverty and Healthcare Work") +
theme(plot.title = element_text(face = "bold", hjust = 0.5))
healthss_pov_map1
legend_map1 <- ggdraw() +
draw_plot(healthss_pov_map1, 0, 0, 1, 1) +
draw_plot(legend1, -0.000000444, 0.12, 0.6, 0.30)
legend_map1
#Mapping the results for child poverty and Income Ratio
dist.err.data2 <- summary(all.dist.err.k1, correlation=TRUE, Nagelkerke = TRUE)
dist.err.output2 <- cbind.data.frame(fl_pov$FIPS,
dist.err.data2$fitted.values,
dist.err.data2$residual,
fl_pov$child.pov.2016,
fl_pov$lnretail,
fl_pov$lnhealthss,
fl_pov$lnincome_ratio,
stringsAsFactors = FALSE)
#Renaming columns
colnames(dist.err.output2) <- c("fips","fitted","resid","childpov",
"Retail","Healthss","Income_Ratio")
fl_fortify2 <- fortify(fl_sp)
fl_poly2 <- merge(x = fl_fortify, y = dist.err.output2,
by.x = "id", by.y = "fips", all = TRUE)
bivariate_data2 <- bi_class(fl_poly2, x = childpov, y = Income_Ratio,
dim = 3, style = "quantile")
legend2 <- bi_legend(pal = "DkViolet",
dim = 3,
xlab = "Child Poverty",
ylab = "Income Ratio",
size = 6)
world <- map_data("world")
states <- map_data("state")
southern_states <- subset(states, region %in%
c("texas", "arkansas", "louisiana", "mississippi",
"alabama", "georgia", "florida", "north carolina",
"south carolina", "tennessee", "oklahoma",
"kentucky", "west virginia", "virginia",
"maryland", "delaware", "district of columbia"))
Income_pov_map2 <- ggplot() +
geom_polygon(data = world, aes(x=long,y=lat, group=group), fill = "gray95", color = "white") +
geom_polygon(data = states, aes(x=long,y=lat, group=group), fill = "gray", color = "white") +
geom_polygon(data = southern_states, aes(x=long,y=lat, group=group), fill = NA, size = 0.01, color = "white") +
geom_polygon(data = bivariate_data2, aes(x=long, y=lat, group=group, fill = bi_class), color = "grey50", show.legend = FALSE) +
bi_scale_fill(pal = "DkViolet", dim = 3) +
coord_map("conic", lat0 = 30, xlim=c(-88,-80), ylim=c(24,31)) +
theme_void() + theme(legend.title.align=0.5) +
theme(panel.background = element_rect(fill = 'deepskyblue'),
panel.grid.major = element_line(colour = NA)) +
labs(x = "Longitude", y = "Latitude", fill = "Child Poverty",
title = "Bivariate Map of Child Poverty and Income Ratio") +
theme(plot.title = element_text(face = "bold", hjust = 0.5))
Income_pov_map2
legend_map2 <- ggdraw() +
draw_plot(Income_pov_map2, 0, 0, 1, 1) +
draw_plot(legend2, -0.000000444, 0.12, 0.6, 0.30)
legend_map2
#Mapping the results for child poverty and Construction
dist.err.data3 <- summary(all.dist.err.k1, correlation=TRUE, Nagelkerke = TRUE)
dist.err.output3 <- cbind.data.frame(fl_pov$FIPS,
dist.err.data3$fitted.values,
dist.err.data3$residual,
fl_pov$child.pov.2016,
fl_pov$lnretail,
fl_pov$lnhealthss,
fl_pov$lnincome_ratio,
fl_pov$lnconstruction,
stringsAsFactors = FALSE)
#Renaming columns
colnames(dist.err.output3) <- c("fips","fitted","resid","childpov",
"Retail","Healthss","Income_Ratio","construction")
fl_fortify3 <- fortify(fl_sp)
fl_poly3 <- merge(x = fl_fortify3, y = dist.err.output3,
by.x = "id", by.y = "fips", all = TRUE)
bivariate_data3 <- bi_class(fl_poly3, x = childpov, y = construction,
dim = 3, style = "quantile")
legend3 <- bi_legend(pal = "Brown",
dim = 3,
xlab = "Child Poverty",
ylab = "In Construction",
size = 6)
world <- map_data("world")
states <- map_data("state")
southern_states <- subset(states, region %in%
c("texas", "arkansas", "louisiana", "mississippi",
"alabama", "georgia", "florida", "north carolina",
"south carolina", "tennessee", "oklahoma",
"kentucky", "west virginia", "virginia",
"maryland", "delaware", "district of columbia"))
Construction_pov_map3 <- ggplot() +
geom_polygon(data = world, aes(x=long,y=lat, group=group), fill = "gray95", color = "white") +
geom_polygon(data = states, aes(x=long,y=lat, group=group), fill = "gray", color = "white") +
geom_polygon(data = southern_states, aes(x=long,y=lat, group=group), fill = NA, size = 0.01, color = "white") +
geom_polygon(data = bivariate_data3, aes(x=long, y=lat, group=group, fill = bi_class), color = "grey50", show.legend = FALSE) +
bi_scale_fill(pal = "Brown", dim = 3) +
coord_map("conic", lat0 = 30, xlim=c(-88,-80), ylim=c(24,31)) +
theme_void() + theme(legend.title.align=0.5) +
theme(panel.background = element_rect(fill = 'deepskyblue'),
panel.grid.major = element_line(colour = NA)) +
labs(x = "Longitude", y = "Latitude", fill = "Child Poverty",
title = "Bivariate Map of Child Poverty and Construction Work") +
theme(plot.title = element_text(face = "bold", hjust = 0.5))
Construction_pov_map3
legend_map3 <- ggdraw() +
draw_plot(Construction_pov_map3, 0, 0, 1, 1) +
draw_plot(legend3, -0.000000444, 0.12, 0.6, 0.30)
legend_map3
#Mapping the results for child poverty and less than a high school degree
dist.err.data4 <- summary(all.dist.err.k1, correlation=TRUE, Nagelkerke = TRUE)
dist.err.output4 <- cbind.data.frame(fl_pov$FIPS,
dist.err.data4$fitted.values,
dist.err.data4$residual,
fl_pov$child.pov.2016,
fl_pov$lnretail,
fl_pov$lnhealthss,
fl_pov$lnincome_ratio,
fl_pov$lnconstruction,
fl_pov$lnlesshs,
stringsAsFactors = FALSE)
#Renaming columns
colnames(dist.err.output4) <- c("fips","fitted","resid","childpov",
"Retail","Healthss","Income_Ratio","construction","less_high_school_degree")
fl_fortify4 <- fortify(fl_sp)
fl_poly4 <- merge(x = fl_fortify4, y = dist.err.output4,
by.x = "id", by.y = "fips", all = TRUE)
bivariate_data4 <- bi_class(fl_poly4, x = childpov, y = less_high_school_degree,
dim = 3, style = "quantile")
legend4 <- bi_legend(pal = "Brown",
dim = 3,
xlab = "Child Poverty",
ylab = "Less than a high school degree",
size = 6)
world <- map_data("world")
states <- map_data("state")
southern_states <- subset(states, region %in%
c("texas", "arkansas", "louisiana", "mississippi",
"alabama", "georgia", "florida", "north carolina",
"south carolina", "tennessee", "oklahoma",
"kentucky", "west virginia", "virginia",
"maryland", "delaware", "district of columbia"))
HS_Degree_pov_map4 <- ggplot() +
geom_polygon(data = world, aes(x=long,y=lat, group=group), fill = "gray95", color = "white") +
geom_polygon(data = states, aes(x=long,y=lat, group=group), fill = "gray", color = "white") +
geom_polygon(data = southern_states, aes(x=long,y=lat, group=group), fill = NA, size = 0.01, color = "white") +
geom_polygon(data = bivariate_data4, aes(x=long, y=lat, group=group, fill = bi_class), color = "grey50", show.legend = FALSE) +
bi_scale_fill(pal = "Brown", dim = 3) +
coord_map("conic", lat0 = 30, xlim=c(-88,-80), ylim=c(24,31)) +
theme_void() + theme(legend.title.align=0.5) +
theme(panel.background = element_rect(fill = 'deepskyblue'),
panel.grid.major = element_line(colour = NA)) +
labs(x = "Longitude", y = "Latitude", fill = "Child Poverty",
title = "Bivariate Map of Child Poverty and Less than a High School Degree") +
theme(plot.title = element_text(face = "bold", hjust = 0.5))
HS_Degree_pov_map4
legend_map4 <- ggdraw() +
draw_plot(HS_Degree_pov_map4, 0, 0, 1, 1) +
draw_plot(legend4, -0.000000444, 0.12, 0.6, 0.30)
legend_map4