In this analysis I will try to investigate and map percentages of Obesity. This data was gathered from Social Explorer Health Data 2016 using all 50 states and Counties.
I will be using two different methods: the first is County Level Spatial Mapping looking only at Obesity and the second is non-spatial (ecological regression and plotting).
Data Used and Variable Explanation:
A data frame consisting of:
*state : All 50 States
*Drinking Adults : Excessive Drinking is the percentage of adults that report either binge drinking, defined as consuming more than 4 (women) or 5 (men) alcoholic beverages on a single occasion in the past 30 days, or heavy drinking, defined as drinking more than one (women) or 2 (men) drinks per day on average.
*Obese Persons : This will be the continuous dependent variable. Adult Obesity is the percentage of the adult population (age 20 and older) that reports a body mass index (BMI) greater than or equal to 30 kg/m2.
*Persons with Limited Access to Healthy Foods : This will be an independent variable used to see if there is an interaction between limited access to healthy foods and alcohol usage and if it has any influence on obesity.
library(sf)
ct_map <- st_read("tl_2016_us_county.shp", stringsAsFactors = FALSE)
Reading layer `tl_2016_us_county' from data source `C:\Users\cngon\Documents\R\tl_2016_us_county.shp' using driver `ESRI Shapefile'
Simple feature collection with 3233 features and 17 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.44106
epsg (SRID): 4269
proj4string: +proj=longlat +datum=NAD83 +no_defs
names(ct_map)
[1] "STATEFP" "COUNTYFP" "COUNTYNS" "GEOID" "NAME" "NAMELSAD" "LSAD" "CLASSFP" "MTFCC" "CSAFP" "CBSAFP"
[12] "METDIVFP" "FUNCSTAT" "ALAND" "AWATER" "INTPTLAT" "INTPTLON" "geometry"
head(AlcoObesity)
library(dplyr)
AlcoObesity <- rename (AlcoObesity,
"County" = Geo_QNAME,
"STATEFP" = Geo_STATE,
"Fair_to_Poor_Health" = SE_T002_001,
"Current_Smokers" = SE_T011_001,
"Drinking_Adults" = SE_T011_002,
"Persons_with_Limited_Access_to _Healthy_Foods" = SE_T012_001,
"Access_to_Exercise" = SE_T012_002,
"Obese_Persons" = SE_T012_003,
"Physically_Inactive" = SE_T012_004,
"Free_Lunch" = SE_T012_005)
AlOb <- AlcoObesity
select(AlOb, STATEFP, County, Obese_Persons, Drinking_Adults, Persons_with_Limited_Access_to_Healthy_Foods)
head(AlOb)
head(AlOb)
AlcObEco<- AlOb %>%
group_by(STATEFP) %>%
summarise(mean_p = mean(Obese_Persons, na.rm = TRUE), mean_s = mean(Drinking_Adults, na.rm = TRUE))
head(AlcObEco)
ecoalcobe<-lm(mean_p ~ mean_s, data = AlcObEco)
summary(ecoalcobe)
Call:
lm(formula = mean_p ~ mean_s, data = AlcObEco)
Residuals:
Min 1Q Median 3Q Max
-8.4287 -2.1042 0.2516 2.4969 7.0014
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 40.3962 2.6574 15.201 < 2e-16 ***
mean_s -0.6261 0.1511 -4.145 0.000134 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.376 on 49 degrees of freedom
Multiple R-squared: 0.2596, Adjusted R-squared: 0.2445
F-statistic: 17.18 on 1 and 49 DF, p-value: 0.0001344
package <U+393C><U+3E31>tmap<U+393C><U+3E32> was built under R version 3.4.4
obesitymap1 <- Obesitymap %>%
filter(STATEFP.x != "02") %>%
filter(STATEFP.x != "15") %>%
filter(STATEFP.x != "60") %>%
filter(STATEFP.x != "66") %>%
filter(STATEFP.x != "69") %>%
filter(STATEFP.x != "72") %>%
filter(STATEFP.x != "78")
##**Excluding Hawaii and Alaska**
tm_shape(obesitymap1, projection = 2163) + tm_polygons("Obese_Persons")
library(tmaptools)
tm_shape(obesitymap1, projection = 2163) + tm_polygons("Obese_Persons", palette = "-RdBu")
tm_shape(obesitymap1, projection = 2163) + tm_polygons("Obese_Persons", palette = "-RdBu") +
tm_shape(us_states) + tm_borders(lwd = .36, col = "black", alpha = 1)
tm_shape(obesitymap1, projection = 2163) + tm_polygons("Obese_Persons", palette = "-RdBu", border.col = "grey", border.alpha = .4) +
tm_shape(us_states) + tm_borders(lwd = .36, col = "black", alpha = 1)
package <U+393C><U+3E31>tigris<U+393C><U+3E32> was built under R version 3.4.4To enable
caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
Attaching package: <U+393C><U+3E31>tigris<U+393C><U+3E32>
The following object is masked from <U+393C><U+3E31>package:graphics<U+393C><U+3E32>:
plot
|
| | 0%
|
|= | 0%
|
|= | 1%
|
|== | 1%
|
|== | 2%
|
|=== | 2%
|
|=== | 3%
|
|==== | 3%
|
|==== | 4%
|
|===== | 4%
|
|====== | 4%
|
|====== | 5%
|
|======= | 5%
|
|======= | 6%
|
|======== | 6%
|
|======== | 7%
|
|========= | 7%
|
|========= | 8%
|
|========== | 8%
|
|=========== | 9%
|
|============ | 9%
|
|============ | 10%
|
|============= | 10%
|
|============= | 11%
|
|============== | 11%
|
|============== | 12%
|
|=============== | 12%
|
|================ | 13%
|
|================= | 13%
|
|================= | 14%
|
|================== | 14%
|
|================== | 15%
|
|=================== | 15%
|
|=================== | 16%
|
|==================== | 16%
|
|==================== | 17%
|
|===================== | 17%
|
|====================== | 17%
|
|====================== | 18%
|
|======================= | 18%
|
|======================= | 19%
|
|======================== | 19%
|
|======================== | 20%
|
|========================= | 20%
|
|========================== | 21%
|
|=========================== | 21%
|
|=========================== | 22%
|
|============================ | 22%
|
|============================ | 23%
|
|============================= | 23%
|
|============================= | 24%
|
|============================== | 24%
|
|=============================== | 25%
|
|================================ | 25%
|
|================================ | 26%
|
|================================= | 26%
|
|================================= | 27%
|
|================================== | 27%
|
|================================== | 28%
|
|=================================== | 28%
|
|==================================== | 29%
|
|===================================== | 29%
|
|===================================== | 30%
|
|====================================== | 30%
|
|====================================== | 31%
|
|======================================= | 31%
|
|======================================= | 32%
|
|======================================== | 32%
|
|========================================= | 33%
|
|========================================== | 34%
|
|=========================================== | 34%
|
|=========================================== | 35%
|
|============================================ | 35%
|
|============================================ | 36%
|
|============================================= | 36%
|
|============================================= | 37%
|
|============================================== | 37%
|
|=============================================== | 38%
|
|================================================ | 38%
|
|================================================ | 39%
|
|================================================= | 39%
|
|================================================= | 40%
|
|================================================== | 40%
|
|================================================== | 41%
|
|=================================================== | 41%
|
|==================================================== | 42%
|
|===================================================== | 42%
|
|===================================================== | 43%
|
|====================================================== | 43%
|
|====================================================== | 44%
|
|======================================================= | 44%
|
|======================================================= | 45%
|
|======================================================== | 45%
|
|======================================================== | 46%
|
|========================================================= | 46%
|
|========================================================== | 47%
|
|=========================================================== | 47%
|
|=========================================================== | 48%
|
|============================================================ | 48%
|
|============================================================ | 49%
|
|============================================================= | 49%
|
|============================================================== | 50%
|
|=============================================================== | 51%
|
|================================================================ | 51%
|
|================================================================ | 52%
|
|================================================================= | 52%
|
|================================================================= | 53%
|
|================================================================== | 53%
|
|================================================================== | 54%
|
|=================================================================== | 54%
|
|==================================================================== | 55%
|
|===================================================================== | 55%
|
|===================================================================== | 56%
|
|====================================================================== | 56%
|
|====================================================================== | 57%
|
|======================================================================= | 57%
|
|======================================================================= | 58%
|
|======================================================================== | 58%
|
|========================================================================= | 59%
|
|========================================================================== | 59%
|
|========================================================================== | 60%
|
|=========================================================================== | 60%
|
|=========================================================================== | 61%
|
|============================================================================ | 61%
|
|============================================================================ | 62%
|
|============================================================================= | 62%
|
|============================================================================== | 63%
|
|=============================================================================== | 64%
|
|================================================================================ | 64%
|
|================================================================================ | 65%
|
|================================================================================= | 65%
|
|================================================================================= | 66%
|
|================================================================================== | 66%
|
|================================================================================== | 67%
|
|=================================================================================== | 67%
|
|==================================================================================== | 68%
|
|===================================================================================== | 68%
|
|===================================================================================== | 69%
|
|====================================================================================== | 69%
|
|====================================================================================== | 70%
|
|======================================================================================= | 70%
|
|======================================================================================== | 71%
|
|========================================================================================= | 71%
|
|========================================================================================= | 72%
|
|========================================================================================== | 72%
|
|========================================================================================== | 73%
|
|=========================================================================================== | 73%
|
|=========================================================================================== | 74%
|
|============================================================================================ | 74%
|
|============================================================================================= | 75%
|
|============================================================================================== | 75%
|
|============================================================================================== | 76%
|
|=============================================================================================== | 76%
|
|=============================================================================================== | 77%
|
|================================================================================================ | 77%
|
|================================================================================================ | 78%
|
|================================================================================================= | 78%
|
|================================================================================================== | 79%
|
|=================================================================================================== | 79%
|
|=================================================================================================== | 80%
|
|==================================================================================================== | 80%
|
|==================================================================================================== | 81%
|
|===================================================================================================== | 81%
|
|===================================================================================================== | 82%
|
|====================================================================================================== | 82%
|
|======================================================================================================= | 83%
|
|======================================================================================================== | 84%
|
|========================================================================================================= | 84%
|
|========================================================================================================= | 85%
|
|========================================================================================================== | 85%
|
|========================================================================================================== | 86%
|
|=========================================================================================================== | 86%
|
|=========================================================================================================== | 87%
|
|============================================================================================================ | 87%
|
|============================================================================================================= | 88%
|
|============================================================================================================== | 88%
|
|============================================================================================================== | 89%
|
|=============================================================================================================== | 89%
|
|=============================================================================================================== | 90%
|
|================================================================================================================ | 90%
|
|================================================================================================================ | 91%
|
|================================================================================================================= | 91%
|
|================================================================================================================== | 92%
|
|=================================================================================================================== | 92%
|
|=================================================================================================================== | 93%
|
|==================================================================================================================== | 93%
|
|==================================================================================================================== | 94%
|
|===================================================================================================================== | 94%
|
|===================================================================================================================== | 95%
|
|====================================================================================================================== | 95%
|
|======================================================================================================================= | 96%
|
|======================================================================================================================== | 96%
|
|======================================================================================================================== | 97%
|
|========================================================================================================================= | 97%
|
|========================================================================================================================= | 98%
|
|========================================================================================================================== | 98%
|
|========================================================================================================================== | 99%
|
|=========================================================================================================================== | 99%
|
|=========================================================================================================================== | 100%
|
|============================================================================================================================| 100%
[1] "STATEFP" "COUNTYFP" "COUNTYNS" "AFFGEOID" "GEOID" "NAME" "LSAD" "ALAND" "AWATER" "geometry"
Looking at the map we get an overall sense of the percentage of Obesity accross the US while also applying border lines to specifically see obesity in each state.
According to the Tigris document: If cb is set to TRUE, it will download a generalized (1:500k) file. Defaults to FALSE (the most detailed TIGER/Line file)
I also noticed that when we use False we get 18 Variable names instead of 10 as seen below
library(tigris)
options(tigris_class = "sf")
t_county <- counties(cb = TRUE)
names(t_county)
[1] "STATEFP" "COUNTYFP" "COUNTYNS" "AFFGEOID" "GEOID" "NAME" "LSAD" "ALAND" "AWATER" "geometry"
library(tigris)
options(tigris_class = "sf")
t_county <- counties(cb = FALSE)
names(t_county)
[1] "STATEFP" "COUNTYFP" "COUNTYNS" "GEOID" "NAME" "NAMELSAD" "LSAD" "CLASSFP" "MTFCC" "CSAFP" "CBSAFP"
[12] "METDIVFP" "FUNCSTAT" "ALAND" "AWATER" "INTPTLAT" "INTPTLON" "geometry"
*Obviously Spatial shows us in this particular analysis Obesity overall in the country and it’s relationship in each state. It gives us a better and physical view of the data we are looking at and a visual understanding. The data defines a location
*Non-spatial data relates to a specific, precisely defined location. The data are often statistical.
The two main differences are:
*spatial data are generally multi-dimensional and auto correlated.
*non-spatial data are generally one-dimensional and independent.
Combining both spatial and non-spatial analysis to view and analyze data sets can be very helpful in determining and understanding the data. Using both can be very beneficial in explaining and supporting our hypothesis. I personally like using a spatial approach to understand my data and to help me interpret and explain it.
Although we are only getting familiar with mapping, I would like to later run this looking at all the variables combined into one map(Drinking_Adults and Persons_with_Access_to_Healthy_Foods). I did have a hard time running it that’s why I took it out.