library(tidycensus)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.5
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tmap)
v10_Profile <- load_variables(2011, "acs5/profile", cache = TRUE) #demographic profile tables
v19_Profile <- load_variables(2019, "acs5/profile", cache = TRUE) #demographic
#Search for variables by using grep()
v10_Profile[grep(x = v10_Profile$label, "Income", ignore.case = TRUE), c("name", "label")]
## # A tibble: 174 x 2
## name label
## <chr> <chr>
## 1 DP03_0051 Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS~
## 2 DP03_0051P Percent!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)~
## 3 DP03_0052 Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS~
## 4 DP03_0052P Percent!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)~
## 5 DP03_0053 Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS~
## 6 DP03_0053P Percent!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)~
## 7 DP03_0054 Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS~
## 8 DP03_0054P Percent!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)~
## 9 DP03_0055 Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS~
## 10 DP03_0055P Percent!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)~
## # ... with 164 more rows
v19_Profile[grep(x = v19_Profile$label, "Income", ignore.case = TRUE), c("name", "label")]
## # A tibble: 174 x 2
## name label
## <chr> <chr>
## 1 DP03_0051 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS~
## 2 DP03_0051P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)~
## 3 DP03_0052 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS~
## 4 DP03_0052P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)~
## 5 DP03_0053 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS~
## 6 DP03_0053P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)~
## 7 DP03_0054 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS~
## 8 DP03_0054P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)~
## 9 DP03_0055 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS~
## 10 DP03_0055P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)~
## # ... with 164 more rows
v10_Profile_race <- load_variables(2011, "acs5/profile", cache = TRUE) #demographic profile tables
v19_Profile_race <- load_variables(2019, "acs5/profile", cache = TRUE) #demographic
#Search for variables by using grep()
v10_Profile_race[grep(x = v10_Profile$label, "Race", ignore.case = TRUE), c("name", "label")]
## # A tibble: 106 x 2
## name label
## <chr> <chr>
## 1 DP05_0028 Estimate!!RACE!!Total population
## 2 DP05_0028P Percent!!RACE!!Total population
## 3 DP05_0029 Estimate!!RACE!!One race
## 4 DP05_0029P Percent!!RACE!!One race
## 5 DP05_0030 Estimate!!RACE!!Two or more races
## 6 DP05_0030P Percent!!RACE!!Two or more races
## 7 DP05_0031 Estimate!!RACE!!One race
## 8 DP05_0031P Percent!!RACE!!One race
## 9 DP05_0032 Estimate!!RACE!!One race!!White
## 10 DP05_0032P Percent!!RACE!!One race!!White
## # ... with 96 more rows
v19_Profile_race[grep(x = v19_Profile$label, "Race", ignore.case = TRUE), c("name", "label")]
## # A tibble: 106 x 2
## name label
## <chr> <chr>
## 1 DP05_0033 Estimate!!RACE!!Total population
## 2 DP05_0033P Percent!!RACE!!Total population
## 3 DP05_0034 Estimate!!RACE!!Total population!!One race
## 4 DP05_0034P Percent!!RACE!!Total population!!One race
## 5 DP05_0035 Estimate!!RACE!!Total population!!Two or more races
## 6 DP05_0035P Percent!!RACE!!Total population!!Two or more races
## 7 DP05_0036 Estimate!!RACE!!Total population!!One race
## 8 DP05_0036P Percent!!RACE!!Total population!!One race
## 9 DP05_0037 Estimate!!RACE!!Total population!!One race!!White
## 10 DP05_0037P Percent!!RACE!!Total population!!One race!!White
## # ... with 96 more rows
variables_of_interest<-c("DP03_0062","DP05_0032P","DP05_0033P")
income11<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2011,
variables="DP03_0062" ,
geometry = T,
output = "wide")
## Getting data from the 2007-2011 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================= | 34%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|============================== | 44%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|========================================================== | 84%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
pct_white11<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2011,
variables="DP05_0032P" ,
geometry = T,
output = "wide")
## Getting data from the 2007-2011 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_white19<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2019,
variables="DP05_0037P" ,
geometry = T,
output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
pct_black11<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2011,
variables="DP05_0033P" ,
geometry = T,
output = "wide")
## Getting data from the 2007-2011 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_black19<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2019,
variables="DP05_0038P" ,
geometry = T,
output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_white11 <- pct_white11 %>%
mutate(pwhite_11 = DP05_0032PE,
pwhite_er_11 = DP05_0032PM/1.645,
pwhite_cv_11 =100* (pwhite_er_11/pwhite_11)) %>%
filter(complete.cases(pwhite_11), is.finite(pwhite_cv_11)==T)
pct_white19 <- pct_white19 %>%
mutate(pwhite_19 = DP05_0037PE,
pwhite_er_19 = DP05_0037PM/1.645,
pwhite_cv_19 =100* (pwhite_er_19/pwhite_19)) %>%
filter(complete.cases(pwhite_19), is.finite(pwhite_cv_19)==T)
#merge the two years worth of data
mdat_white<-tigris::geo_join(pct_white11, as.data.frame(pct_white19), by_sp="GEOID", by_df="GEOID")
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help
head(mdat_white)
## Simple feature collection with 6 features and 14 fields
## Active geometry column: geometry.x
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -97.78608 ymin: 30.27364 xmax: -97.70428 ymax: 30.35988
## Geodetic CRS: NAD83
## GEOID NAME.x DP05_0032PE DP05_0032PM
## 1 48453001501 Census Tract 15.01, Travis County, Texas 95.7 2.7
## 2 48453001503 Census Tract 15.03, Travis County, Texas 81.7 6.8
## 3 48453001504 Census Tract 15.04, Travis County, Texas 84.5 5.7
## 4 48453001505 Census Tract 15.05, Travis County, Texas 94.7 3.1
## 5 48453001602 Census Tract 16.02, Travis County, Texas 72.9 6.3
## 6 48453001603 Census Tract 16.03, Travis County, Texas 96.1 2.6
## pwhite_11 pwhite_er_11 pwhite_cv_11 NAME.y
## 1 95.7 1.641337 1.715086 Census Tract 15.01, Travis County, Texas
## 2 81.7 4.133739 5.059656 Census Tract 15.03, Travis County, Texas
## 3 84.5 3.465046 4.100646 Census Tract 15.04, Travis County, Texas
## 4 94.7 1.884498 1.989967 Census Tract 15.05, Travis County, Texas
## 5 72.9 3.829787 5.253480 Census Tract 16.02, Travis County, Texas
## 6 96.1 1.580547 1.644690 Census Tract 16.03, Travis County, Texas
## DP05_0037PE DP05_0037PM pwhite_19 pwhite_er_19 pwhite_cv_19 rank
## 1 93.1 3.2 93.1 1.945289 2.089462 1
## 2 77.4 5.5 77.4 3.343465 4.319722 1
## 3 82.6 5.8 82.6 3.525836 4.268566 1
## 4 90.3 3.5 90.3 2.127660 2.356212 1
## 5 70.3 6.1 70.3 3.708207 5.274832 1
## 6 87.3 7.2 87.3 4.376900 5.013631 1
## geometry.x geometry.y
## 1 POLYGON ((-97.75436 30.3376... MULTIPOLYGON (((-97.75501 3...
## 2 POLYGON ((-97.71885 30.3377... MULTIPOLYGON (((-97.72633 3...
## 3 POLYGON ((-97.71596 30.3423... MULTIPOLYGON (((-97.73661 3...
## 4 POLYGON ((-97.73836 30.3438... MULTIPOLYGON (((-97.73917 3...
## 5 POLYGON ((-97.77687 30.2777... MULTIPOLYGON (((-97.78592 3...
## 6 POLYGON ((-97.74911 30.2988... MULTIPOLYGON (((-97.76826 3...
acstest<-function(names,geoid, est1, err1, est2, err2, alpha, yr1, yr2, span){
se1<-err1/qnorm(.90)
se2<-err2/qnorm(.90)
yrs1<-seq(yr1, to=yr1-span)
yrs2<-seq(yr2, to=yr2-span)
C<-mean(yrs2%in%yrs1)
diff<- (est1-est2)
test<-(est1-est2) / (sqrt(1-C)*sqrt((se1^2+se2^2)))
crit<-qnorm(1-alpha/2)
pval<-2*pnorm(abs(test),lower.tail=F)
result<-NULL
result[pval > alpha]<-"insignificant change"
result[pval < alpha & test < 0]<- "significant increase"
result[pval < alpha & test > 0]<-"significant decrease"
data.frame(name=names,geoid=geoid, est1=est1, est2=est2, se1=se1, se2=se2,difference=diff, test=test, result=result, pval=pval)
}
diff_white_1119<-acstest(names = mdat_white$NAME.x, geoid = mdat_white$GEOID, est1 = mdat_white$pwhite_11, est2 = mdat_white$pwhite_19, err1 = mdat_white$pwhite_er_11, err2=mdat_white$pwhite_er_19,alpha = .05, yr1 = 2011, yr2=2019, span = 5)
head(diff_white_1119)
## name geoid est1 est2 se1
## 1 Census Tract 15.01, Travis County, Texas 48453001501 95.7 93.1 1.280742
## 2 Census Tract 15.03, Travis County, Texas 48453001503 81.7 77.4 3.225573
## 3 Census Tract 15.04, Travis County, Texas 48453001504 84.5 82.6 2.703789
## 4 Census Tract 15.05, Travis County, Texas 48453001505 94.7 90.3 1.470482
## 5 Census Tract 16.02, Travis County, Texas 48453001602 72.9 70.3 2.988399
## 6 Census Tract 16.03, Travis County, Texas 48453001603 96.1 87.3 1.233307
## se2 difference test result pval
## 1 1.517917 2.6 1.3091348 insignificant change 0.19048868
## 2 2.608920 4.3 1.0364972 insignificant change 0.29997027
## 3 2.751224 1.9 0.4925568 insignificant change 0.62232577
## 4 1.660222 4.4 1.9839448 significant decrease 0.04726199
## 5 2.893529 2.6 0.6250463 insignificant change 0.53194069
## 6 3.415313 8.8 2.4234600 significant decrease 0.01537345
table(diff_white_1119$result)
##
## insignificant change significant decrease significant increase
## 138 28 51
acs_merge<-left_join(mdat_white, diff_white_1119, by=c("GEOID"="geoid"))
tmap_mode("plot")
## tmap mode set to plotting
p1<-tm_shape(acs_merge)+
tm_polygons(c("pwhite_11"), title=c("% white in 2011"), breaks=c(0,10,20,30,40,50,60,70,80,90,100),palette="Blues")+
#tm_format("World", legend.outside=T, title.size =4)+
tm_scale_bar()+
tm_layout(title="Travis County Percent White Estimates 2011", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_compass()
p2<-tm_shape(acs_merge)+
tm_polygons(c("pwhite_19"), title=c("% white 2019"),breaks=c(0,10,20,30,40,50,60,70,80,90,100), palette="Blues")+
#tm_format("World", title="Dallas County Vacancy CV", legend.outside=T)+
tm_layout(title="Travis County Percent White Estimates 2019", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
p3 <- tm_shape(acs_merge)+
tm_polygons(c("result"), title=c("Changes"), palette = "Dark2")+
#tm_format("World", title="San Antonio Poverty Rate CV", legend.outside=T)+
tm_layout(title="Travis County Percent White Estimate Changes", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
tmap_arrange(p1, p2, p3)
pct_black11 <- pct_black11 %>%
mutate(pblack_11 = DP05_0033PE,
pblack_er_11 = DP05_0033PM/1.645,
pblack_cv_11 =100* (pblack_er_11/pblack_11)) %>%
filter(complete.cases(pblack_11), is.finite(pblack_cv_11)==T)
pct_black19 <- pct_black19 %>%
mutate(pblack_19 = DP05_0038PE,
pblack_er_19 = DP05_0038PM/1.645,
pblack_cv_19 =100* (pblack_er_19/pblack_19)) %>%
filter(complete.cases(pblack_19), is.finite(pblack_cv_19)==T)
#merge the two years worth of data
mdat_black<-tigris::geo_join(pct_black11, as.data.frame(pct_black19), by_sp="GEOID", by_df="GEOID")
head(mdat_black)
## Simple feature collection with 6 features and 14 fields
## Active geometry column: geometry.x
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -97.78608 ymin: 30.27364 xmax: -97.70428 ymax: 30.35988
## Geodetic CRS: NAD83
## GEOID NAME.x DP05_0033PE DP05_0033PM
## 1 48453001501 Census Tract 15.01, Travis County, Texas 0.5 0.7
## 2 48453001503 Census Tract 15.03, Travis County, Texas 5.2 4.3
## 3 48453001504 Census Tract 15.04, Travis County, Texas 2.3 2.9
## 4 48453001505 Census Tract 15.05, Travis County, Texas 0.9 1.0
## 5 48453001602 Census Tract 16.02, Travis County, Texas 1.7 2.1
## 6 48453001603 Census Tract 16.03, Travis County, Texas 1.6 2.0
## pblack_11 pblack_er_11 pblack_cv_11 NAME.y
## 1 0.5 0.4255319 85.10638 Census Tract 15.01, Travis County, Texas
## 2 5.2 2.6139818 50.26888 Census Tract 15.03, Travis County, Texas
## 3 2.3 1.7629179 76.64861 Census Tract 15.04, Travis County, Texas
## 4 0.9 0.6079027 67.54475 Census Tract 15.05, Travis County, Texas
## 5 1.7 1.2765957 75.09387 Census Tract 16.02, Travis County, Texas
## 6 1.6 1.2158055 75.98784 Census Tract 16.03, Travis County, Texas
## DP05_0038PE DP05_0038PM pblack_19 pblack_er_19 pblack_cv_19 rank
## 1 1.6 1.8 1.6 1.0942249 68.38906 1
## 2 5.7 2.7 5.7 1.6413374 28.79539 1
## 3 1.2 1.4 1.2 0.8510638 70.92199 1
## 4 0.9 0.9 0.9 0.5471125 60.79027 1
## 5 1.5 1.5 1.5 0.9118541 60.79027 1
## 6 1.1 1.0 1.1 0.6079027 55.26389 1
## geometry.x geometry.y
## 1 POLYGON ((-97.75436 30.3376... MULTIPOLYGON (((-97.75501 3...
## 2 POLYGON ((-97.71885 30.3377... MULTIPOLYGON (((-97.72633 3...
## 3 POLYGON ((-97.71596 30.3423... MULTIPOLYGON (((-97.73661 3...
## 4 POLYGON ((-97.73836 30.3438... MULTIPOLYGON (((-97.73917 3...
## 5 POLYGON ((-97.77687 30.2777... MULTIPOLYGON (((-97.78592 3...
## 6 POLYGON ((-97.74911 30.2988... MULTIPOLYGON (((-97.76826 3...
diff_black_1119<-acstest(names = mdat_black$NAME.x, geoid = mdat_black$GEOID, est1 = mdat_black$pblack_11, est2 = mdat_black$pblack_19, err1 = mdat_black$pblack_er_11, err2=mdat_black$pblack_er_19,alpha = .05, yr1 = 2011, yr2=2019, span = 5)
head(diff_black_1119)
## name geoid est1 est2 se1
## 1 Census Tract 15.01, Travis County, Texas 48453001501 0.5 1.6 0.3320443
## 2 Census Tract 15.03, Travis County, Texas 48453001503 5.2 5.7 2.0397008
## 3 Census Tract 15.04, Travis County, Texas 48453001504 2.3 1.2 1.3756122
## 4 Census Tract 15.05, Travis County, Texas 48453001505 0.9 0.9 0.4743490
## 5 Census Tract 16.02, Travis County, Texas 48453001602 1.7 1.5 0.9961330
## 6 Census Tract 16.03, Travis County, Texas 48453001603 1.6 1.1 0.9486980
## se2 difference test result pval
## 1 0.8538282 -1.1 -1.2007159 insignificant change 0.2298614
## 2 1.2807424 -0.5 -0.2076015 insignificant change 0.8355401
## 3 0.6640886 1.1 0.7201207 insignificant change 0.4714507
## 4 0.4269141 0.0 0.0000000 insignificant change 1.0000000
## 5 0.7115235 0.2 0.1633785 insignificant change 0.8702204
## 6 0.4743490 0.5 0.4713972 insignificant change 0.6373571
table(diff_black_1119$result)
##
## insignificant change significant decrease significant increase
## 151 25 20
acs_merge_black<-left_join(mdat_black, diff_black_1119, by=c("GEOID"="geoid"))
tmap_mode("plot")
## tmap mode set to plotting
p1_black<-tm_shape(acs_merge_black)+
tm_polygons(c("pblack_11"), title=c("% black in 2011"),breaks=c(0,10,20,30,40,50,60,70,80,90,100), palette="Blues")+
#tm_format("World", legend.outside=T, title.size =4)+
tm_scale_bar()+
tm_layout(title="Travis County Percent Black Estimates 2011", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_compass()
p2_black<-tm_shape(acs_merge_black)+
tm_polygons(c("pblack_19"), title=c("% black 2019"),breaks=c(0,10,20,30,40,50,60,70,80,90,100), palette="Blues")+
#tm_format("World", title="Dallas County Vacancy CV", legend.outside=T)+
tm_layout(title="Travis County Percent Black Estimates 2019", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
p3_black<- tm_shape(acs_merge_black)+
tm_polygons(c("result"), title=c("Changes"), palette = "Dark2")+
#tm_format("World", title="San Antonio Poverty Rate CV", legend.outside=T)+
tm_layout(title="Travis County Percent Black Estimate Changes", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
tmap_arrange(p1_black, p2_black, p3_black)
pct_hispanic11<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2011,
variables="DP05_0066P" ,
geometry = T,
output = "wide")
## Getting data from the 2007-2011 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_hispanic19<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2019,
variables="DP05_0071P" ,
geometry = T,
output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_hispanic11 <- pct_hispanic11 %>%
mutate(phispanic_11 = DP05_0066PE,
phispanic_er_11 = DP05_0066PM/1.645,
phispanic_cv_11 =100* (phispanic_er_11/phispanic_11)) %>%
filter(complete.cases(phispanic_11), is.finite(phispanic_cv_11)==T)
pct_hispanic19 <- pct_hispanic19 %>%
mutate(phispanic_19 = DP05_0071PE,
phispanic_er_19 = DP05_0071PM/1.645,
phispanic_cv_19 =100* (phispanic_er_19/phispanic_19)) %>%
filter(complete.cases(phispanic_19), is.finite(phispanic_cv_19)==T)
#merge the two years worth of data
mdat_hispanic<-tigris::geo_join(pct_hispanic11, as.data.frame(pct_hispanic19), by_sp="GEOID", by_df="GEOID")
head(mdat_hispanic)
## Simple feature collection with 6 features and 14 fields
## Active geometry column: geometry.x
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -97.78608 ymin: 30.27364 xmax: -97.70428 ymax: 30.35988
## Geodetic CRS: NAD83
## GEOID NAME.x DP05_0066PE DP05_0066PM
## 1 48453001501 Census Tract 15.01, Travis County, Texas 11.7 4.1
## 2 48453001503 Census Tract 15.03, Travis County, Texas 33.2 6.7
## 3 48453001504 Census Tract 15.04, Travis County, Texas 14.6 5.2
## 4 48453001505 Census Tract 15.05, Travis County, Texas 15.5 5.9
## 5 48453001602 Census Tract 16.02, Travis County, Texas 15.2 5.9
## 6 48453001603 Census Tract 16.03, Travis County, Texas 4.4 2.8
## phispanic_11 phispanic_er_11 phispanic_cv_11
## 1 11.7 2.492401 21.30257
## 2 33.2 4.072948 12.26792
## 3 14.6 3.161094 21.65133
## 4 15.5 3.586626 23.13952
## 5 15.2 3.586626 23.59622
## 6 4.4 1.702128 38.68472
## NAME.y DP05_0071PE DP05_0071PM phispanic_19
## 1 Census Tract 15.01, Travis County, Texas 8.6 2.4 8.6
## 2 Census Tract 15.03, Travis County, Texas 26.6 5.0 26.6
## 3 Census Tract 15.04, Travis County, Texas 18.4 4.3 18.4
## 4 Census Tract 15.05, Travis County, Texas 11.3 4.5 11.3
## 5 Census Tract 16.02, Travis County, Texas 12.4 5.5 12.4
## 6 Census Tract 16.03, Travis County, Texas 8.2 3.9 8.2
## phispanic_er_19 phispanic_cv_19 rank geometry.x
## 1 1.458967 16.96473 1 POLYGON ((-97.75436 30.3376...
## 2 3.039514 11.42674 1 POLYGON ((-97.71885 30.3377...
## 3 2.613982 14.20642 1 POLYGON ((-97.71596 30.3423...
## 4 2.735562 24.20852 1 POLYGON ((-97.73836 30.3438...
## 5 3.343465 26.96343 1 POLYGON ((-97.77687 30.2777...
## 6 2.370821 28.91245 1 POLYGON ((-97.74911 30.2988...
## geometry.y
## 1 MULTIPOLYGON (((-97.75501 3...
## 2 MULTIPOLYGON (((-97.72633 3...
## 3 MULTIPOLYGON (((-97.73661 3...
## 4 MULTIPOLYGON (((-97.73917 3...
## 5 MULTIPOLYGON (((-97.78592 3...
## 6 MULTIPOLYGON (((-97.76826 3...
diff_hispanic_1119<-acstest(names = mdat_hispanic$NAME.x, geoid = mdat_hispanic$GEOID, est1 = mdat_hispanic$phispanic_11, est2 = mdat_hispanic$phispanic_19, err1 = mdat_hispanic$phispanic_er_11, err2=mdat_hispanic$phispanic_er_19,alpha = .05, yr1 = 2011, yr2=2019, span = 5)
head(diff_hispanic_1119)
## name geoid est1 est2 se1
## 1 Census Tract 15.01, Travis County, Texas 48453001501 11.7 8.6 1.944831
## 2 Census Tract 15.03, Travis County, Texas 48453001503 33.2 26.6 3.178138
## 3 Census Tract 15.04, Travis County, Texas 48453001504 14.6 18.4 2.466615
## 4 Census Tract 15.05, Travis County, Texas 48453001505 15.5 11.3 2.798659
## 5 Census Tract 16.02, Travis County, Texas 48453001602 15.2 12.4 2.798659
## 6 Census Tract 16.03, Travis County, Texas 48453001603 4.4 8.2 1.328177
## se2 difference test result pval
## 1 1.138438 3.1 1.3756182 insignificant change 0.16893988
## 2 2.371745 6.6 1.6643260 insignificant change 0.09604730
## 3 2.039701 -3.8 -1.1872352 insignificant change 0.23513487
## 4 2.134571 4.2 1.1932548 insignificant change 0.23276962
## 5 2.608920 2.8 0.7318178 insignificant change 0.46427976
## 6 1.849961 -3.8 -1.6685919 insignificant change 0.09519829
table(diff_hispanic_1119$result)
##
## insignificant change significant decrease significant increase
## 156 25 36
acs_merge_hispanic<-left_join(mdat_hispanic, diff_hispanic_1119, by=c("GEOID"="geoid"))
tmap_mode("plot")
## tmap mode set to plotting
p1_hispanic<-tm_shape(acs_merge_hispanic)+
tm_polygons(c("phispanic_11"), title=c("% Hispanic in 2011"),breaks=c(0,10,20,30,40,50,60,70,80,90,100), palette="Blues")+
#tm_format("World", legend.outside=T, title.size =4)+
tm_scale_bar()+
tm_layout(title="Travis County Percent Hispanic Estimates 2011", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_compass()
p2_hispanic<-tm_shape(acs_merge_hispanic)+
tm_polygons(c("phispanic_19"), title=c("% hispanic 2019"),breaks=c(0,10,20,30,40,50,60,70,80,90,100), palette="Blues")+
#tm_format("World", title="Dallas County Vacancy CV", legend.outside=T)+
tm_layout(title="Travis County Percent Hispanic Estimates 2019", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
p3_hispanic<- tm_shape(acs_merge_hispanic)+
tm_polygons(c("result"), title=c("Changes"), palette = "Dark2")+
#tm_format("World", title="San Antonio Poverty Rate CV", legend.outside=T)+
tm_layout(title="Travis County Percent Hispanic Estimate Changes", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
tmap_arrange(p1_hispanic, p2_hispanic, p3_hispanic)
#income
pct_income11<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2011,
variables="DP03_0051" ,
geometry = T,
output = "wide")
## Getting data from the 2007-2011 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_income19<-get_acs(geography = "tract",
state="TX",
county = "Travis",
year = 2019,
variables="DP03_0051" ,
geometry = T,
output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
pct_income11 <- pct_income11 %>%
mutate(pincome_11 = DP03_0051E,
pincome_er_11 = DP03_0051M/1.645,
pincome_cv_11 =100* (pincome_er_11/pincome_11)) %>%
filter(complete.cases(pincome_11), is.finite(pincome_cv_11)==T)
pct_income19 <- pct_income19 %>%
mutate(pincome_19 = DP03_0051E,
pincome_er_19 = DP03_0051M/1.645,
pincome_cv_19 =100* (pincome_er_19/pincome_19)) %>%
filter(complete.cases(pincome_19), is.finite(pincome_cv_19)==T)
#merge the two years worth of data
mdat_income<-tigris::geo_join(pct_income11, as.data.frame(pct_income19), by_sp="GEOID", by_df="GEOID")
head(mdat_income)
## Simple feature collection with 6 features and 14 fields
## Active geometry column: geometry.x
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -97.78608 ymin: 30.27364 xmax: -97.70428 ymax: 30.35988
## Geodetic CRS: NAD83
## GEOID NAME.x DP03_0051E.x
## 1 48453001501 Census Tract 15.01, Travis County, Texas 2287
## 2 48453001503 Census Tract 15.03, Travis County, Texas 1780
## 3 48453001504 Census Tract 15.04, Travis County, Texas 2190
## 4 48453001505 Census Tract 15.05, Travis County, Texas 2230
## 5 48453001602 Census Tract 16.02, Travis County, Texas 1594
## 6 48453001603 Census Tract 16.03, Travis County, Texas 1745
## DP03_0051M.x pincome_11 pincome_er_11 pincome_cv_11
## 1 111 2287 67.47720 2.9504680
## 2 95 1780 57.75076 3.2444247
## 3 60 2190 36.47416 1.6654869
## 4 35 2230 21.27660 0.9541074
## 5 123 1594 74.77204 4.6908429
## 6 140 1745 85.10638 4.8771566
## NAME.y DP03_0051E.y DP03_0051M.y pincome_19
## 1 Census Tract 15.01, Travis County, Texas 2317 164 2317
## 2 Census Tract 15.03, Travis County, Texas 1974 115 1974
## 3 Census Tract 15.04, Travis County, Texas 2884 198 2884
## 4 Census Tract 15.05, Travis County, Texas 2371 138 2371
## 5 Census Tract 16.02, Travis County, Texas 1681 98 1681
## 6 Census Tract 16.03, Travis County, Texas 1847 106 1847
## pincome_er_19 pincome_cv_19 rank geometry.x
## 1 99.69605 4.302807 1 POLYGON ((-97.75436 30.3376...
## 2 69.90881 3.541480 1 POLYGON ((-97.71885 30.3377...
## 3 120.36474 4.173535 1 POLYGON ((-97.71596 30.3423...
## 4 83.89058 3.538194 1 POLYGON ((-97.73836 30.3438...
## 5 59.57447 3.543990 1 POLYGON ((-97.77687 30.2777...
## 6 64.43769 3.488776 1 POLYGON ((-97.74911 30.2988...
## geometry.y
## 1 MULTIPOLYGON (((-97.75501 3...
## 2 MULTIPOLYGON (((-97.72633 3...
## 3 MULTIPOLYGON (((-97.73661 3...
## 4 MULTIPOLYGON (((-97.73917 3...
## 5 MULTIPOLYGON (((-97.78592 3...
## 6 MULTIPOLYGON (((-97.76826 3...
diff_income_1119<-acstest(names = mdat_income$NAME.x, geoid = mdat_income$GEOID, est1 = mdat_income$pincome_11, est2 = mdat_income$pincome_19, err1 = mdat_income$pincome_er_11, err2=mdat_income$pincome_er_19,alpha = .05, yr1 = 2011, yr2=2019, span = 5)
head(diff_income_1119)
## name geoid est1 est2 se1
## 1 Census Tract 15.01, Travis County, Texas 48453001501 2287 2317 52.65274
## 2 Census Tract 15.03, Travis County, Texas 48453001503 1780 1974 45.06316
## 3 Census Tract 15.04, Travis County, Texas 48453001504 2190 2884 28.46094
## 4 Census Tract 15.05, Travis County, Texas 48453001505 2230 2371 16.60222
## 5 Census Tract 16.02, Travis County, Texas 48453001602 1594 1681 58.34493
## 6 Census Tract 16.03, Travis County, Texas 48453001603 1745 1847 66.40886
## se2 difference test result pval
## 1 77.79324 -30 -0.3193641 insignificant change 7.494505e-01
## 2 54.55014 -194 -2.7418185 significant increase 6.110008e-03
## 3 93.92111 -694 -7.0716259 significant increase 1.531287e-12
## 4 65.46017 -141 -2.0878771 significant increase 3.680892e-02
## 5 46.48620 -87 -1.1662263 insignificant change 2.435230e-01
## 6 50.28100 -102 -1.2245405 insignificant change 2.207484e-01
table(diff_income_1119$result)
##
## insignificant change significant decrease significant increase
## 79 9 127
acs_merge_income<-left_join(mdat_income, diff_income_1119, by=c("GEOID"="geoid"))
tmap_mode("plot")
## tmap mode set to plotting
p1_income<-tm_shape(acs_merge_income)+
tm_polygons(c("pincome_11"), title=c("Household income in 2011"),style="quantile", palette="Blues")+
#tm_format("World", legend.outside=T, title.size =4)+
tm_scale_bar()+
tm_layout(title="Travis County household income estimates 2011", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_compass()
p2_income<-tm_shape(acs_merge_income)+
tm_polygons(c("pincome_19"), title=c("household income 2019"),style="quantile", palette="Blues")+
#tm_format("World", title="Dallas County Vacancy CV", legend.outside=T)+
tm_layout(title="Travis County household income estimates 2019", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
p3_income<- tm_shape(acs_merge_income)+
tm_polygons(c("result"), title=c("Changes"), palette = "Dark2")+
#tm_format("World", title="San Antonio Poverty Rate CV", legend.outside=T)+
tm_layout(title="Travis County household income estimate changes", title.size =1.5, legend.frame = TRUE, title.position = c('right', 'top'))+
tm_scale_bar()+
tm_compass()
tmap_arrange(p1_income, p2_income, p3_income)