Healthcare Equity Analysis

Kaiyu Zhou

2024-10-4

Library packages

Import the Yelp data

using st_read and ensure the data is tidy and ready for the analysis.

yelp_hospital <- st_read("https://raw.githubusercontent.com/ujhwang/urban-analytics-2024/main/Assignment/mini_3/yelp_hospital.geojson")
## Reading layer `yelp_hospital' from data source 
##   `https://raw.githubusercontent.com/ujhwang/urban-analytics-2024/main/Assignment/mini_3/yelp_hospital.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 129 features and 23 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -84.56242 ymin: 33.60009 xmax: -84.08677 ymax: 34.0701
## Geodetic CRS:  WGS 84

Check data

skim(yelp_hospital)
## Warning: Couldn't find skimmers for class: sfc_POINT, sfc; No user-defined
## `sfl` provided. Falling back to `character`.
Data summary
Name yelp_hospital
Number of rows 129
Number of columns 24
_______________________
Column type frequency:
character 18
logical 1
numeric 5
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
id 0 1.00 22 22 0 129 0
alias 0 1.00 17 73 0 129 0
name 0 1.00 8 64 0 115 0
image_url 0 1.00 0 68 86 44 0
url 0 1.00 174 230 0 129 0
categories 0 1.00 9 62 0 21 0
transactions 0 1.00 0 0 129 1 0
phone 0 1.00 0 12 5 107 0
display_phone 0 1.00 0 14 5 107 0
location.address1 2 0.98 0 34 14 87 0
location.address2 13 0.90 0 7 100 15 0
location.address3 23 0.82 0 52 104 3 0
location.city 0 1.00 6 14 0 13 0
location.zip_code 0 1.00 0 5 1 33 0
location.country 0 1.00 2 2 0 1 0
location.state 0 1.00 2 2 0 1 0
location.display_address 0 1.00 17 93 0 93 0
geometry 0 1.00 21 38 0 103 0

Variable type: logical

skim_variable n_missing complete_rate mean count
is_closed 0 1 0 FAL: 129

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
review_count 0 1 12.90 42.98 0.00 0.00 0.00 2.00 319.00 ▇▁▁▁▁
rating 0 1 1.05 1.47 0.00 0.00 0.00 2.00 5.00 ▇▁▂▁▁
distance 0 1 1188.10 735.72 204.09 564.81 1199.68 1647.70 4098.37 ▇▇▂▁▁
coordinates.latitude 0 1 33.86 0.12 33.60 33.77 33.81 33.92 34.07 ▁▇▅▅▅
coordinates.longitude 0 1 -84.34 0.06 -84.56 -84.39 -84.35 -84.32 -84.09 ▁▆▇▁▁

Census Data

Variable: Median Household Income (B19013), Percent of People Below Poverty Level (B17021), Percent of Population with Less than High School Education (B15002), Unemployment Rate (B23025), Percent of Population Without Health Insurance (B27010)

tidycensus::census_api_key(Sys.getenv("census_api"))
## To install your API key for use in future sessions, run this function with `install = TRUE`.
variables <- c(
  pop = "B02001_001",
  Med_hhinc = "B19013_001",
  bpoverty = "B17021_001",
  less_highschool = "B15002_002",
  unemp_rate = "B23025_005" ,
  no_insurance = "B27010_001"
)
tract_2019 <- suppressMessages(
  get_acs(geography = "tract",
          state = "GA",
          county = c("Fulton", "Dekalb"),
          variables = variables,
          year = 2019,
          survey = "acs5", 
          geometry = TRUE,
          output = "wide"))
##   |                                                                              |                                                                      |   0%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |==                                                                    |   4%  |                                                                              |===                                                                   |   4%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |==========                                                            |  14%  |                                                                              |===========                                                           |  15%  |                                                                              |============                                                          |  17%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |===============                                                       |  21%  |                                                                              |================                                                      |  22%  |                                                                              |==================                                                    |  26%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |========================                                              |  34%  |                                                                              |==========================                                            |  38%  |                                                                              |=================================                                     |  47%  |                                                                              |===================================                                   |  50%  |                                                                              |=====================================                                 |  53%  |                                                                              |========================================                              |  57%  |                                                                              |===========================================                           |  62%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===================================================                   |  73%  |                                                                              |==========================================================            |  82%  |                                                                              |==============================================================        |  88%  |                                                                              |==================================================================    |  94%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================| 100%

tract_2019 <- tract_2019 %>%
  mutate(less_high_percent = (less_highschoolE / popE) * 100)
head(tract_2019)
## Simple feature collection with 6 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -84.41692 ymin: 33.72043 xmax: -84.33426 ymax: 33.97001
## Geodetic CRS:  NAD83
##         GEOID                                        NAME popE popM Med_hhincE
## 1 13121001100     Census Tract 11, Fulton County, Georgia 5193  453     109426
## 2 13121009603  Census Tract 96.03, Fulton County, Georgia 4830  332      83243
## 3 13121005800     Census Tract 58, Fulton County, Georgia 1479  250      42679
## 4 13121010117 Census Tract 101.17, Fulton County, Georgia 4319  488      60731
## 5 13121009502  Census Tract 95.02, Fulton County, Georgia 3867  497      86053
## 6 13089021213 Census Tract 212.13, DeKalb County, Georgia 3526  204     154063
##   Med_hhincM bpovertyE bpovertyM less_highschoolE less_highschoolM unemp_rateE
## 1       7959      5193       453             2575              283          59
## 2      15103      4830       332             1873              274          51
## 3      16189      1430       222              550              109         113
## 4       5573      4319       488             1205              201          74
## 5      24545      3656       489             1413              247           0
## 6      19674      3526       204             1108               95          63
##   unemp_rateM no_insuranceE no_insuranceM                       geometry
## 1          54          5170           451 MULTIPOLYGON (((-84.38782 3...
## 2          49          4830           332 MULTIPOLYGON (((-84.38738 3...
## 3          76          1479           250 MULTIPOLYGON (((-84.41692 3...
## 4          48          4319           488 MULTIPOLYGON (((-84.36575 3...
## 5          13          3656           489 MULTIPOLYGON (((-84.39472 3...
## 6          49          3526           204 MULTIPOLYGON (((-84.34783 3...
##   less_high_percent
## 1          49.58598
## 2          38.77847
## 3          37.18729
## 4          27.89998
## 5          36.53995
## 6          31.42371

#Tidying Data

Missing values

yelp_data

yelp_hospital %>% 
  map_dbl(., function(x) sum(is.na(x))) 
##                       id                    alias                     name 
##                        0                        0                        0 
##                image_url                is_closed                      url 
##                        0                        0                        0 
##             review_count               categories                   rating 
##                        0                        0                        0 
##             transactions                    phone            display_phone 
##                        0                        0                        0 
##                 distance     coordinates.latitude    coordinates.longitude 
##                        0                        0                        0 
##        location.address1        location.address2        location.address3 
##                        2                       13                       23 
##            location.city        location.zip_code         location.country 
##                        0                        0                        0 
##           location.state location.display_address                 geometry 
##                        0                        0                        0

census data

tract_2019 %>% 
  map_dbl(., function(x) sum(is.na(x))) 
##             GEOID              NAME              popE              popM 
##                 0                 0                 0                 0 
##        Med_hhincE        Med_hhincM         bpovertyE         bpovertyM 
##                 4                 4                 0                 0 
##  less_highschoolE  less_highschoolM       unemp_rateE       unemp_rateM 
##                 0                 0                 0                 0 
##     no_insuranceE     no_insuranceM          geometry less_high_percent 
##                 0                 0                 0                 2

Drop missing

Yelp (coordinates)

identical(is.na(yelp_hospital$coordinates.latitude),
          is.na(yelp_hospital$coordinates.longitude))
## [1] TRUE
# Drop rows that have missing values in `coordinates.longitude` and 'coordinates.latitude' 
yelp_dropna <- yelp_hospital %>% 
  drop_na(coordinates.longitude, coordinates.latitude)

print(paste0("Before: ", nrow(yelp_hospital)))
## [1] "Before: 129"
print(paste0("After: ", nrow(yelp_dropna)))
## [1] "After: 129"

Census (variables: Med_hhincE)

# Drop rows that have missing values in `coordinates.longitude` and 'coordinates.latitude' 
tract_2019_dropna <- tract_2019 %>% 
  drop_na(Med_hhincE)

print(paste0("Before: ", nrow(tract_2019)))
## [1] "Before: 349"
print(paste0("After: ", nrow(tract_2019_dropna)))
## [1] "After: 345"

st to sf, and set crs

yelp_sf <- yelp_dropna %>% 
  st_as_sf(coords=c("coordinates.longitude", "coordinates.latitude"), 
           crs = 4326)

tract_variables <- tract_2019_dropna %>% 
  st_transform(4326)

Save yelp data

saveRDS(yelp_sf, here('yelp_hospital_sf.rds'))

Spatial join data

tract_variables <- tract_variables %>% 
  separate(col = NAME, into=c("tract","county","state"), sep=', ') %>% 
  # Spatial join
  st_join(yelp_sf %>%
            st_transform(crs = st_crs(tract_variables))) %>% 
  group_by(GEOID, county) %>% 
  ungroup() %>%
  # Drop 'E' from column names
  rename_with(function(x) str_sub(x,1,nchar(x)-1), str_c(names(variables), "E")) 

tract_variables %>% head()
## Simple feature collection with 6 features and 40 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -84.41692 ymin: 33.72043 xmax: -84.33426 ymax: 33.97001
## Geodetic CRS:  WGS 84
## # A tibble: 6 × 41
##   GEOID   tract county state   pop  popM Med_hhinc Med_hhincM bpoverty bpovertyM
##   <chr>   <chr> <chr>  <chr> <dbl> <dbl>     <dbl>      <dbl>    <dbl>     <dbl>
## 1 131210… Cens… Fulto… Geor…  5193   453    109426       7959     5193       453
## 2 131210… Cens… Fulto… Geor…  4830   332     83243      15103     4830       332
## 3 131210… Cens… Fulto… Geor…  1479   250     42679      16189     1430       222
## 4 131210… Cens… Fulto… Geor…  4319   488     60731       5573     4319       488
## 5 131210… Cens… Fulto… Geor…  3867   497     86053      24545     3656       489
## 6 130890… Cens… DeKal… Geor…  3526   204    154063      19674     3526       204
## # ℹ 31 more variables: less_highschool <dbl>, less_highschoolM <dbl>,
## #   unemp_rate <dbl>, unemp_rateM <dbl>, no_insurance <dbl>,
## #   no_insuranceM <dbl>, less_high_percent <dbl>, id <chr>, alias <chr>,
## #   name <chr>, image_url <chr>, is_closed <lgl>, url <chr>,
## #   review_count <int>, categories <chr>, rating <dbl>, transactions <chr>,
## #   phone <chr>, display_phone <chr>, distance <dbl>,
## #   coordinates.latitude <dbl>, coordinates.longitude <dbl>, …
yelp_census <- st_join(yelp_sf, tract_variables, join = st_intersects)
yelp_census
## Simple feature collection with 1057 features and 63 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -84.56242 ymin: 33.60009 xmax: -84.08677 ymax: 34.0701
## Geodetic CRS:  WGS 84
## First 10 features:
##                       id.x                                          alias.x
## 1   fiSgDb29cZO-MffxwrT_LA northside-alpharetta-medical-campus-alpharetta-2
## 1.1 fiSgDb29cZO-MffxwrT_LA northside-alpharetta-medical-campus-alpharetta-2
## 2   hWXJFx9zCVDmiO6eldgHBA                      regency-hospital-alpharetta
## 3   kuE7B_HLP57KnSIgn-jzpw northside-alpharetta-preventive-medicine-atlanta
## 3.1 kuE7B_HLP57KnSIgn-jzpw northside-alpharetta-preventive-medicine-atlanta
## 4   0B80Az6DXX8ZLXZXhU1bCQ                         health-direct-alpharetta
## 5   EaD2lKlKh4NpeSD25_vrHw                 ultimatemedicalhousecall-atlanta
## 6   O4DoAVRc6oTjUe9ufieTjA                          shepherd-center-atlanta
## 6.1 O4DoAVRc6oTjUe9ufieTjA                          shepherd-center-atlanta
## 6.2 O4DoAVRc6oTjUe9ufieTjA                          shepherd-center-atlanta
##                                       name.x
## 1        Northside Alpharetta Medical Campus
## 1.1      Northside Alpharetta Medical Campus
## 2                           Regency Hospital
## 3   Northside Alpharetta Preventive Medicine
## 3.1 Northside Alpharetta Preventive Medicine
## 4                              Health Direct
## 5                   Ultimatemedicalhousecall
## 6                            Shepherd Center
## 6.1                          Shepherd Center
## 6.2                          Shepherd Center
##                                                              image_url.x
## 1   https://s3-media4.fl.yelpcdn.com/bphoto/8Pe7ZlobOywD_CakTalTdg/o.jpg
## 1.1 https://s3-media4.fl.yelpcdn.com/bphoto/8Pe7ZlobOywD_CakTalTdg/o.jpg
## 2                                                                       
## 3                                                                       
## 3.1                                                                     
## 4                                                                       
## 5                                                                       
## 6   https://s3-media2.fl.yelpcdn.com/bphoto/7H4uUz1eDFV1a2fM-5-e2A/o.jpg
## 6.1 https://s3-media2.fl.yelpcdn.com/bphoto/7H4uUz1eDFV1a2fM-5-e2A/o.jpg
## 6.2 https://s3-media2.fl.yelpcdn.com/bphoto/7H4uUz1eDFV1a2fM-5-e2A/o.jpg
##     is_closed.x
## 1         FALSE
## 1.1       FALSE
## 2         FALSE
## 3         FALSE
## 3.1       FALSE
## 4         FALSE
## 5         FALSE
## 6         FALSE
## 6.1       FALSE
## 6.2       FALSE
##                                                                                                                                                                                                             url.x
## 1   https://www.yelp.com/biz/northside-alpharetta-medical-campus-alpharetta-2?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 1.1 https://www.yelp.com/biz/northside-alpharetta-medical-campus-alpharetta-2?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 2                        https://www.yelp.com/biz/regency-hospital-alpharetta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 3   https://www.yelp.com/biz/northside-alpharetta-preventive-medicine-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 3.1 https://www.yelp.com/biz/northside-alpharetta-preventive-medicine-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 4                           https://www.yelp.com/biz/health-direct-alpharetta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 5                   https://www.yelp.com/biz/ultimatemedicalhousecall-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6                            https://www.yelp.com/biz/shepherd-center-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6.1                          https://www.yelp.com/biz/shepherd-center-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6.2                          https://www.yelp.com/biz/shepherd-center-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
##     review_count.x
## 1                1
## 1.1              1
## 2                0
## 3                0
## 3.1              0
## 4                0
## 5                0
## 6               34
## 6.1             34
## 6.2             34
##                                                       categories.x rating.x
## 1                                                        Hospitals      4.0
## 1.1                                                      Hospitals      4.0
## 2                                                        Hospitals      0.0
## 3                                                        Hospitals      0.0
## 3.1                                                      Hospitals      0.0
## 4                                                        Hospitals      0.0
## 5                                                        Hospitals      0.0
## 6   Hospitals, Rehabilitation Center, Community Service/Non-Profit      3.2
## 6.1 Hospitals, Rehabilitation Center, Community Service/Non-Profit      3.2
## 6.2 Hospitals, Rehabilitation Center, Community Service/Non-Profit      3.2
##     transactions.x      phone.x display_phone.x distance.x
## 1                  +17706674000  (770) 667-4000  1496.5068
## 1.1                +17706674000  (770) 667-4000  1496.5068
## 2                  +16786940553  (678) 694-0553  2125.5366
## 3                  +17706674155  (770) 667-4155  1496.5068
## 3.1                +17706674155  (770) 667-4155  1496.5068
## 4                  +17708702500  (770) 870-2500  2460.2880
## 5                                                 595.1797
## 6                  +14043522020  (404) 352-2020   769.8365
## 6.1                +14043522020  (404) 352-2020   769.8365
## 6.2                +14043522020  (404) 352-2020   769.8365
##     coordinates.latitude.x coordinates.longitude.x        location.address1.x
## 1                 34.07010               -84.26324 3400 A & C Old Milton Pkwy
## 1.1               34.07010               -84.26324 3400 A & C Old Milton Pkwy
## 2                 34.05106               -84.27857            11175 Cicero Dr
## 3                 34.07010               -84.26324     3400 A Old Milton Pkwy
## 3.1               34.07010               -84.26324     3400 A Old Milton Pkwy
## 4                 34.06029               -84.28281       2550 Northwinds Pkwy
## 5                 33.84957               -84.37021        3495 Buckhead Lp NE
## 6                 33.81016               -84.39409       2020 Peachtree Rd NW
## 6.1               33.81016               -84.39409       2020 Peachtree Rd NW
## 6.2               33.81016               -84.39409       2020 Peachtree Rd NW
##     location.address2.x location.address3.x location.city.x location.zip_code.x
## 1                                                Alpharetta               30004
## 1.1                                              Alpharetta               30004
## 2               Ste 300                <NA>      Alpharetta               30022
## 3                                                   Atlanta               30303
## 3.1                                                 Atlanta               30303
## 4                                                Alpharetta               30004
## 5                                      <NA>         Atlanta               30305
## 6                                                   Atlanta               30309
## 6.1                                                 Atlanta               30309
## 6.2                                                 Atlanta               30309
##     location.country.x location.state.x
## 1                   US               GA
## 1.1                 US               GA
## 2                   US               GA
## 3                   US               GA
## 3.1                 US               GA
## 4                   US               GA
## 5                   US               GA
## 6                   US               GA
## 6.1                 US               GA
## 6.2                 US               GA
##                           location.display_address.x       GEOID
## 1   3400 A & C Old Milton Pkwy, Alpharetta, GA 30004 13121011619
## 1.1 3400 A & C Old Milton Pkwy, Alpharetta, GA 30004 13121011619
## 2     11175 Cicero Dr, Ste 300, Alpharetta, GA 30022 13121011617
## 3          3400 A Old Milton Pkwy, Atlanta, GA 30303 13121011619
## 3.1        3400 A Old Milton Pkwy, Atlanta, GA 30303 13121011619
## 4         2550 Northwinds Pkwy, Alpharetta, GA 30004 13121011616
## 5             3495 Buckhead Lp NE, Atlanta, GA 30305 13121010001
## 6            2020 Peachtree Rd NW, Atlanta, GA 30309 13121009101
## 6.1          2020 Peachtree Rd NW, Atlanta, GA 30309 13121009101
## 6.2          2020 Peachtree Rd NW, Atlanta, GA 30309 13121009101
##                   tract        county   state  pop popM Med_hhinc Med_hhincM
## 1   Census Tract 116.19 Fulton County Georgia 7869  686     93750       5251
## 1.1 Census Tract 116.19 Fulton County Georgia 7869  686     93750       5251
## 2   Census Tract 116.17 Fulton County Georgia 7891  491    144125      30367
## 3   Census Tract 116.19 Fulton County Georgia 7869  686     93750       5251
## 3.1 Census Tract 116.19 Fulton County Georgia 7869  686     93750       5251
## 4   Census Tract 116.16 Fulton County Georgia 6372  555    104176      10315
## 5   Census Tract 100.01 Fulton County Georgia 4923  490    108197      33166
## 6    Census Tract 91.01 Fulton County Georgia 5630  488     79489       4861
## 6.1  Census Tract 91.01 Fulton County Georgia 5630  488     79489       4861
## 6.2  Census Tract 91.01 Fulton County Georgia 5630  488     79489       4861
##     bpoverty bpovertyM less_highschool less_highschoolM unemp_rate unemp_rateM
## 1       7869       686            2755              348        116         100
## 1.1     7869       686            2755              348        116         100
## 2       7866       481            2709              211         63          54
## 3       7869       686            2755              348        116         100
## 3.1     7869       686            2755              348        116         100
## 4       6298       554            2458              353        218         168
## 5       4923       490            1819              243         47          46
## 6       5630       488            2007              282         90          80
## 6.1     5630       488            2007              282         90          80
## 6.2     5630       488            2007              282         90          80
##     no_insurance no_insuranceM less_high_percent                   id.y
## 1           7869           686          35.01080 fiSgDb29cZO-MffxwrT_LA
## 1.1         7869           686          35.01080 kuE7B_HLP57KnSIgn-jzpw
## 2           7891           491          34.33025 hWXJFx9zCVDmiO6eldgHBA
## 3           7869           686          35.01080 fiSgDb29cZO-MffxwrT_LA
## 3.1         7869           686          35.01080 kuE7B_HLP57KnSIgn-jzpw
## 4           6277           551          38.57502 0B80Az6DXX8ZLXZXhU1bCQ
## 5           4923           490          36.94901 EaD2lKlKh4NpeSD25_vrHw
## 6           5630           488          35.64831 O4DoAVRc6oTjUe9ufieTjA
## 6.1         5630           488          35.64831 RBdhggpKEymoXRBpMR6ebg
## 6.2         5630           488          35.64831 9vt27MZX76Rl7UJ6V0rIbg
##                                              alias.y
## 1   northside-alpharetta-medical-campus-alpharetta-2
## 1.1 northside-alpharetta-preventive-medicine-atlanta
## 2                        regency-hospital-alpharetta
## 3   northside-alpharetta-medical-campus-alpharetta-2
## 3.1 northside-alpharetta-preventive-medicine-atlanta
## 4                           health-direct-alpharetta
## 5                   ultimatemedicalhousecall-atlanta
## 6                            shepherd-center-atlanta
## 6.1                        mahan-thomas-p-md-atlanta
## 6.2                       sacks-leonard-l-md-atlanta
##                                       name.y
## 1        Northside Alpharetta Medical Campus
## 1.1 Northside Alpharetta Preventive Medicine
## 2                           Regency Hospital
## 3        Northside Alpharetta Medical Campus
## 3.1 Northside Alpharetta Preventive Medicine
## 4                              Health Direct
## 5                   Ultimatemedicalhousecall
## 6                            Shepherd Center
## 6.1                        Mahan Thomas P MD
## 6.2                       Sacks Leonard L MD
##                                                              image_url.y
## 1   https://s3-media4.fl.yelpcdn.com/bphoto/8Pe7ZlobOywD_CakTalTdg/o.jpg
## 1.1                                                                     
## 2                                                                       
## 3   https://s3-media4.fl.yelpcdn.com/bphoto/8Pe7ZlobOywD_CakTalTdg/o.jpg
## 3.1                                                                     
## 4                                                                       
## 5                                                                       
## 6   https://s3-media2.fl.yelpcdn.com/bphoto/7H4uUz1eDFV1a2fM-5-e2A/o.jpg
## 6.1                                                                     
## 6.2                                                                     
##     is_closed.y
## 1         FALSE
## 1.1       FALSE
## 2         FALSE
## 3         FALSE
## 3.1       FALSE
## 4         FALSE
## 5         FALSE
## 6         FALSE
## 6.1       FALSE
## 6.2       FALSE
##                                                                                                                                                                                                             url.y
## 1   https://www.yelp.com/biz/northside-alpharetta-medical-campus-alpharetta-2?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 1.1 https://www.yelp.com/biz/northside-alpharetta-preventive-medicine-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 2                        https://www.yelp.com/biz/regency-hospital-alpharetta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 3   https://www.yelp.com/biz/northside-alpharetta-medical-campus-alpharetta-2?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 3.1 https://www.yelp.com/biz/northside-alpharetta-preventive-medicine-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 4                           https://www.yelp.com/biz/health-direct-alpharetta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 5                   https://www.yelp.com/biz/ultimatemedicalhousecall-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6                            https://www.yelp.com/biz/shepherd-center-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6.1                        https://www.yelp.com/biz/mahan-thomas-p-md-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
## 6.2                       https://www.yelp.com/biz/sacks-leonard-l-md-atlanta?adjust_creative=kfv-AqbqsBxwk_npQxknWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=kfv-AqbqsBxwk_npQxknWQ
##     review_count.y
## 1                1
## 1.1              0
## 2                0
## 3                1
## 3.1              0
## 4                0
## 5                0
## 6               34
## 6.1              0
## 6.2              0
##                                                       categories.y rating.y
## 1                                                        Hospitals      4.0
## 1.1                                                      Hospitals      0.0
## 2                                                        Hospitals      0.0
## 3                                                        Hospitals      4.0
## 3.1                                                      Hospitals      0.0
## 4                                                        Hospitals      0.0
## 5                                                        Hospitals      0.0
## 6   Hospitals, Rehabilitation Center, Community Service/Non-Profit      3.2
## 6.1                                             Doctors, Hospitals      0.0
## 6.2                                             Doctors, Hospitals      0.0
##     transactions.y      phone.y display_phone.y distance.y
## 1                  +17706674000  (770) 667-4000  1496.5068
## 1.1                +17706674155  (770) 667-4155  1496.5068
## 2                  +16786940553  (678) 694-0553  2125.5366
## 3                  +17706674000  (770) 667-4000  1496.5068
## 3.1                +17706674155  (770) 667-4155  1496.5068
## 4                  +17708702500  (770) 870-2500  2460.2880
## 5                                                 595.1797
## 6                  +14043522020  (404) 352-2020   769.8365
## 6.1                +14046055000  (404) 605-5000   552.5971
## 6.2                +14046055000  (404) 605-5000   552.5971
##     coordinates.latitude.y coordinates.longitude.y        location.address1.y
## 1                 34.07010               -84.26324 3400 A & C Old Milton Pkwy
## 1.1               34.07010               -84.26324     3400 A Old Milton Pkwy
## 2                 34.05106               -84.27857            11175 Cicero Dr
## 3                 34.07010               -84.26324 3400 A & C Old Milton Pkwy
## 3.1               34.07010               -84.26324     3400 A Old Milton Pkwy
## 4                 34.06029               -84.28281       2550 Northwinds Pkwy
## 5                 33.84957               -84.37021        3495 Buckhead Lp NE
## 6                 33.81016               -84.39409       2020 Peachtree Rd NW
## 6.1               33.80885               -84.39554       1968 Peachtree Rd NW
## 6.2               33.80885               -84.39554       1968 Peachtree Rd NW
##     location.address2.y location.address3.y location.city.y location.zip_code.y
## 1                                                Alpharetta               30004
## 1.1                                                 Atlanta               30303
## 2               Ste 300                <NA>      Alpharetta               30022
## 3                                                Alpharetta               30004
## 3.1                                                 Atlanta               30303
## 4                                                Alpharetta               30004
## 5                                      <NA>         Atlanta               30305
## 6                                                   Atlanta               30309
## 6.1                                                 Atlanta               30309
## 6.2                                                 Atlanta               30309
##     location.country.y location.state.y
## 1                   US               GA
## 1.1                 US               GA
## 2                   US               GA
## 3                   US               GA
## 3.1                 US               GA
## 4                   US               GA
## 5                   US               GA
## 6                   US               GA
## 6.1                 US               GA
## 6.2                 US               GA
##                           location.display_address.y                   geometry
## 1   3400 A & C Old Milton Pkwy, Alpharetta, GA 30004  POINT (-84.26324 34.0701)
## 1.1        3400 A Old Milton Pkwy, Atlanta, GA 30303  POINT (-84.26324 34.0701)
## 2     11175 Cicero Dr, Ste 300, Alpharetta, GA 30022 POINT (-84.27857 34.05106)
## 3   3400 A & C Old Milton Pkwy, Alpharetta, GA 30004  POINT (-84.26324 34.0701)
## 3.1        3400 A Old Milton Pkwy, Atlanta, GA 30303  POINT (-84.26324 34.0701)
## 4         2550 Northwinds Pkwy, Alpharetta, GA 30004 POINT (-84.28281 34.06029)
## 5             3495 Buckhead Lp NE, Atlanta, GA 30305 POINT (-84.37021 33.84957)
## 6            2020 Peachtree Rd NW, Atlanta, GA 30309 POINT (-84.39409 33.81016)
## 6.1          1968 Peachtree Rd NW, Atlanta, GA 30309 POINT (-84.39409 33.81016)
## 6.2          1968 Peachtree Rd NW, Atlanta, GA 30309 POINT (-84.39409 33.81016)

Buffer

# Print Coordinate Reference System of tract_variables
print(st_crs(tract_variables))
## Coordinate Reference System:
##   User input: EPSG:4326 
##   wkt:
## GEOGCRS["WGS 84",
##     ENSEMBLE["World Geodetic System 1984 ensemble",
##         MEMBER["World Geodetic System 1984 (Transit)"],
##         MEMBER["World Geodetic System 1984 (G730)"],
##         MEMBER["World Geodetic System 1984 (G873)"],
##         MEMBER["World Geodetic System 1984 (G1150)"],
##         MEMBER["World Geodetic System 1984 (G1674)"],
##         MEMBER["World Geodetic System 1984 (G1762)"],
##         MEMBER["World Geodetic System 1984 (G2139)"],
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]],
##         ENSEMBLEACCURACY[2.0]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["geodetic latitude (Lat)",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["geodetic longitude (Lon)",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     USAGE[
##         SCOPE["Horizontal component of 3D system."],
##         AREA["World."],
##         BBOX[-90,-180,90,180]],
##     ID["EPSG",4326]]
# Print Coordinate Reference System of yelp_sf
print(st_crs(yelp_sf))
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["geodetic latitude (Lat)",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["geodetic longitude (Lon)",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]

Create a buffer

0.5 miles for each tract ## Tract centroids

tract_centroids <- st_centroid(tract_variables)
## Warning: st_centroid assumes attributes are constant over geometries
tract_buffer <- st_buffer(tract_centroids, dist = 0.5 * 1609.34) 

Spatial join buffer and yelp hospital data

tract_buffer_hospitals <- st_join(tract_buffer, yelp_sf, join = st_intersects)

Count the number of hospitals within each tract buffer

tract_hospital_count <- tract_buffer_hospitals %>%
  group_by(GEOID) %>% 
  summarize(hospital_count = n())

# Remove the outlier tract from the data
tract_hospital_count <- tract_hospital_count %>% 
  filter(hospital_count != 400)

tract_hospital_count
## Simple feature collection with 344 features and 2 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -84.73482 ymin: 33.54294 xmax: -84.06151 ymax: 34.16149
## Geodetic CRS:  WGS 84
## # A tibble: 344 × 3
##    GEOID       hospital_count                                           geometry
##  * <chr>                <int>                                      <POLYGON [°]>
##  1 13089020100              1 ((-84.34229 33.79189, -84.34204 33.79188, -84.341…
##  2 13089020200              1 ((-84.33317 33.77977, -84.33317 33.77982, -84.333…
##  3 13089020300              1 ((-84.32257 33.77037, -84.32257 33.77046, -84.322…
##  4 13089020400              1 ((-84.34369 33.77334, -84.34385 33.77335, -84.344…
##  5 13089020500              1 ((-84.33416 33.75638, -84.33416 33.75654, -84.334…
##  6 13089020600              1 ((-84.32692 33.75708, -84.32692 33.75743, -84.326…
##  7 13089020700              4 ((-84.31673 33.75622, -84.31673 33.75627, -84.316…
##  8 13089020801              1 ((-84.3095 33.76046, -84.3095 33.76055, -84.30958…
##  9 13089020802              1 ((-84.30654 33.74074, -84.30645 33.74074, -84.306…
## 10 13089020900              1 ((-84.33769 33.72929, -84.33761 33.72929, -84.337…
## # ℹ 334 more rows

Join the counts to tract layer

tract_hospital_count_df <- st_set_geometry(tract_hospital_count, NULL)

tract_variables <- left_join(tract_variables, tract_hospital_count_df, by = "GEOID")

Map of 0.5-mile buffer for each tract ad the location of hospital

tmap_mode("view");
## tmap mode set to interactive viewing
# Create the map
a <- tm_shape(tract_buffer) +
  tm_polygons(col = "lightblue", border.col = "blue", alpha = 0.3, title = "Tract Buffers") + 
  tm_shape(tract_variables) +
  tm_borders(lwd = 0.5, col = "black") +  # Census tract boundaries
  tm_shape(yelp_sf) +
  tm_dots(col = "red", size = 0.1, title = "Hospitals") +  # Hospital locations
  tm_layout(title = "Hospitals within 0.5 Mile of Census Tracts",
            legend.outside = TRUE, legend.title.size = 0.9,
            legend.text.size = 0.7)

# Print the map
a

Number of Hospitals within 0.5 Mile of Tract Centroids

#install.packages("shinyjs")
#library(shinyjs)
#tmaptools::palette_explorer()
# Create a thematic map using tmap to visualize the count of hospitals per tract
hospital_map <- tm_shape(tract_variables) +
  tm_polygons("hospital_count",  # Use the hospital count variable
              palette = "GnBu",  # Color palette for hospital count
              title = "Number of Hospitals",
              border.col = "black") +
  tm_shape(yelp_sf) +
  tm_dots(col = "red", size = 0.1, title = "Hospitals") +  # Plot hospital locations
  tm_layout(title = "Number of Hospitals within 0.5 Mile of Tract Centroids",
            legend.outside = TRUE, legend.title.size = 0.9,
            legend.text.size = 0.7)

# Print the map
hospital_map
# Load necessary libraries
ggplot(data = tract_variables) +
  geom_point(mapping = aes(x=less_high_percent, y=hospital_count, 
                           color="red")) +
  geom_smooth(mapping = aes(x=less_high_percent, y=hospital_count), method = lm) # + ylim(0, NA)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 20 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 20 rows containing missing values or values outside the scale range
## (`geom_point()`).

# Load ggplot2 library
library(ggplot2)

# Create a histogram of the percentage of population with less than high school education
histogram_less_highschool <- ggplot(tract_variables, aes(x = less_high_percent)) +
  geom_histogram(binwidth = 5, fill = "skyblue", color = "black") +
  labs(title = "Distribution of Population with Less Than High School Education",
       x = "Percentage of Population with Less Than High School Education",
       y = "Number of Census Tracts") +
  theme_minimal()

# Print the histogram
print(histogram_less_highschool)

histogram_hospital_count <- ggplot(tract_variables, aes(x = hospital_count)) +
  geom_histogram(binwidth = 2, fill = "skyblue", color = "black") +
  labs(title = "Histogram of hospital count",
       x = "hospital count",
       y = "Number of Census Tracts") +
  theme_minimal()

# Print the histogram
print(histogram_hospital_count)
## Warning: Removed 20 rows containing non-finite outside the scale range
## (`stat_bin()`).

Due to the highly skewed nature of the hospital count, it is challenging to observe a clear spatial pattern or correlation between the availability of hospitals and socioeconomic variables like education. This skewness indicates that a small number of tracts have a concentration of hospitals, while many tracts have very limited or no access.

Distance to the nearest hospital from a Tract

distance_matrix <- st_distance(tract_centroids, yelp_sf)
min_distance_to_hospital <- apply(distance_matrix, 1, min)

tract_variables <- tract_variables %>%
  mutate(min_distance_to_hospital = as.numeric(min_distance_to_hospital))
ggplot(data = tract_variables) +
  geom_point(mapping = aes(x=less_high_percent, y=min_distance_to_hospital, color= county)) +
  geom_smooth(mapping = aes(x=less_high_percent, y=min_distance_to_hospital, color= county), method = lm)
## `geom_smooth()` using formula = 'y ~ x'

The scatter plot visualizes the relationship between the percentage of the population with less than a high school education (less_high_percent) and the minimum distance to the nearest hospital (min_distance_to_hospital).

In Fulton County (represented by the green regression line), there is a negative relationship, suggesting that as the percentage of less-educated population increases, the distance to the nearest hospital tends to decrease. This indicates that tracts with a higher percentage of less-educated residents in Fulton County are generally closer to hospitals.

In DeKalb County (represented by the red regression line), there is a positive relationship, which is opposite to the result observed in Fulton County.

Map visualization

Minimum distance to hospital

tm_shape(tract_variables) +
  tm_polygons("min_distance_to_hospital",   # Variable for color gradient
              style = "quantile",           # Use quantiles to divide into bins
              palette = "YlGnBu",           # Yellow-Orange-Red color gradient
              title = "Min Distance to Hospital (meters)") +
  tm_facets(by = "county",                  # Separate facets by county
            free.coords = FALSE) +          # Use consistent coordinates across counties
  tm_layout(main.title = "Minimum Distance to Hospital by Census Tract and County",
            legend.outside = TRUE) +
  tm_borders("black", lwd = 0.5)            # Add tract borders
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).

Percentage of less than high school education

tm_shape(tract_variables) +
  tm_polygons("less_high_percent",          
              style = "quantile",           
              palette = "-RdYlBu",           
              title = "% Less Than High School") +
  tm_facets(by = "county",                 
            free.coords = FALSE) +          
  tm_layout(main.title = "Percentage of Population with Less Than High School by Census Tract and County",
            legend.outside = TRUE) +
  tm_borders("black", lwd = 0.5)            
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).