Milestone 4

Milestone 3 (Milestone 4 below)

Loading in the datasets and clean names.

#| message: false
#| warning: false
#| 
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 4.0.3     ✔ purrr   1.2.2
✔ tibble  3.3.1     ✔ dplyr   1.2.1
✔ tidyr   1.3.2     ✔ stringr 1.6.0
✔ readr   2.2.0     ✔ forcats 1.0.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(janitor)

Attaching package: 'janitor'
The following objects are masked from 'package:stats':

    chisq.test, fisher.test
enviro_measures <- read.csv("https://raw.githubusercontent.com/PHW290/phw251_projectdata/main/scenario_3/calenviroscreen_measures_2021.csv")
enviro_scores_demog <- read.csv("https://raw.githubusercontent.com/PHW290/phw251_projectdata/main/scenario_3/calenviroscreen_scores_demog_2021.csv")
chhs_asthma <- read.csv("https://raw.githubusercontent.com/PHW290/phw251_projectdata/main/scenario_3/chhs_asthma_ed.csv", fileEncoding = "windows-1252")

chhs_asthma <- clean_names(chhs_asthma)
enviro_measures <- clean_names(enviro_measures)
enviro_scores_demog <- clean_names(enviro_scores_demog)

Merge the two Cal Enviro Screen datasets and select/clean data that will be used. We will focus on 0-4 year age group strata.

enviro_merged <- left_join(enviro_measures, enviro_scores_demog, by = "census_tract")

enviro_working_df <- enviro_merged %>% select(ces_4_0_score, pm2_5, california_county) %>% drop_na()

chhs_working_df <- chhs_asthma %>% rename(california_county = county)

Created new variables needed for analysis (minimum 2). We created “mean_pm25” which is the average pm2.5 for each county. We also created the median_ces_score, which is the median CalEnviroScreen score for each county.

enviro_county <- enviro_working_df %>% group_by(california_county) %>% summarize( mean_pm25 = mean(pm2_5, na.rm = TRUE), median_ces_score = median(ces_4_0_score, na.rm = TRUE), .groups = "drop" )

Filtered the asthma dataset to 2020, children ages 0–4, and California’s 58 counties (excluding the statewide total). Checked for duplicate counties and confirmed that each county appeared only once. Examined missing data, identifying 19 counties with missing asthma ED visit counts and 58 with missing age-adjusted ED visit rates. Selected and renamed variables, retaining county and ED visit rate and renaming the latter asthma_ed_rate_0_4. Standardized county names by converting uppercase names to title case (e.g., ALAMEDA to Alameda) so they matched the environmental dataset. Merged the datasets using county as the common identifier, creating final_df with 58 counties and four variables. Checked the merged dataset for missing environmental and asthma values.

asthma_2020 <- chhs_working_df %>%
  filter(
    year == 2020,
    age_group == "0–4 years",
    california_county != "CALIFORNIA"
  )



asthma_2020 %>%
  count(california_county) %>%
  filter(n > 1)
[1] california_county n                
<0 rows> (or 0-length row.names)
asthma_2020 %>%
  summarise(
    missing_visits = sum(is.na(number_of_ed_visits)),
    missing_rate = sum(is.na(age_adjusted_ed_visit_rate)),
    total_counties = n()
  )
  missing_visits missing_rate total_counties
1             19           19             58
asthma_2020 %>%
  filter(is.na(age_adjusted_ed_visit_rate)) %>%
  select(california_county, age_adjusted_ed_visit_rate)
   california_county age_adjusted_ed_visit_rate
1             AMADOR                         NA
2          CALAVERAS                         NA
3             COLUSA                         NA
4          DEL NORTE                         NA
5          EL DORADO                         NA
6               INYO                         NA
7             LASSEN                         NA
8           MARIPOSA                         NA
9          MENDOCINO                         NA
10             MODOC                         NA
11              MONO                         NA
12            NEVADA                         NA
13            PLUMAS                         NA
14        SAN BENITO                         NA
15          SISKIYOU                         NA
16            SUTTER                         NA
17            TEHAMA                         NA
18           TRINITY                         NA
19          TUOLUMNE                         NA
asthma_clean <- asthma_2020 %>%
  select(
    california_county,
    age_adjusted_ed_visit_rate
  ) %>%
  rename(
    asthma_ed_rate_0_4 = age_adjusted_ed_visit_rate
  )

final_df <- enviro_county %>%
  left_join(asthma_clean, by = "california_county")

glimpse(final_df)
Rows: 58
Columns: 4
$ california_county  <chr> "Alameda", "Alpine", "Amador", "Butte", "Calaveras"…
$ mean_pm25          <dbl> 8.866272, 3.054073, 8.007424, 8.216264, 8.385371, 7…
$ median_ces_score   <dbl> 20.634822, 13.615164, 19.633592, 21.442463, 16.1393…
$ asthma_ed_rate_0_4 <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
library(stringr)

asthma_clean <- asthma_clean %>%
  mutate(
    california_county = str_to_title(california_county)
  )

final_df <- enviro_county %>%
  left_join(asthma_clean, by = "california_county")

final_df %>%
  summarise(
    total_counties = n(),
    missing_pm25 = sum(is.na(mean_pm25)),
    missing_ces = sum(is.na(median_ces_score)),
    missing_asthma = sum(is.na(asthma_ed_rate_0_4))
  )
# A tibble: 1 × 4
  total_counties missing_pm25 missing_ces missing_asthma
           <int>        <int>       <int>          <int>
1             58            0           0             19

Milestone 4

Visualizations complete.

library(tidyverse)
library(knitr)

# Verify final merged dataset
glimpse(final_df)
Rows: 58
Columns: 4
$ california_county  <chr> "Alameda", "Alpine", "Amador", "Butte", "Calaveras"…
$ mean_pm25          <dbl> 8.866272, 3.054073, 8.007424, 8.216264, 8.385371, 7…
$ median_ces_score   <dbl> 20.634822, 13.615164, 19.633592, 21.442463, 16.1393…
$ asthma_ed_rate_0_4 <dbl> 25.1, 0.0, NA, 25.2, NA, NA, 28.0, NA, NA, 70.6, 0.…
final_df %>%
  summarise(
    total_counties = n(),
    available_asthma_rates = sum(!is.na(asthma_ed_rate_0_4)),
    missing_asthma_rates = sum(is.na(asthma_ed_rate_0_4)),
    missing_pm25 = sum(is.na(mean_pm25)),
    missing_ces = sum(is.na(median_ces_score))
  )
# A tibble: 1 × 5
  total_counties available_asthma_rates missing_asthma_rates missing_pm25
           <int>                  <int>                <int>        <int>
1             58                     39                   19            0
# ℹ 1 more variable: missing_ces <int>
#| echo: true
#| message: false
#| warning: false

library(dplyr)
library(knitr)

top_counties <- final_df %>%
  filter(!is.na(asthma_ed_rate_0_4)) %>%
  arrange(desc(asthma_ed_rate_0_4)) %>%
  slice_head(n = 10) %>%
  transmute(
    County = california_county,
    `Asthma ED Visit Rate` = round(asthma_ed_rate_0_4, 1),
    `Mean PM2.5` = round(mean_pm25, 2),
    `Median CES Score` = round(median_ces_score, 1)
  )

knitr::kable(
  top_counties,
  caption = "Top 10 California Counties by Asthma Emergency Department Visit Rate, Ages 0–4, 2020",
  align = c("l", "r", "r", "r")
)
Top 10 California Counties by Asthma Emergency Department Visit Rate, Ages 0–4, 2020
County Asthma ED Visit Rate Mean PM2.5 Median CES Score
Fresno 70.6 13.18 42.8
Madera 67.5 11.40 41.3
Merced 53.4 11.70 43.7
Kings 50.0 13.65 40.7
San Joaquin 41.1 10.66 36.1
Lake 40.9 3.76 19.9
Solano 38.3 8.52 22.1
Stanislaus 32.7 11.30 37.1
Sacramento 32.4 8.76 23.3
Kern 32.0 13.46 39.6
#| echo: true
#| message: false
#| warning: false

library(dplyr)
library(knitr)
library(kableExtra)

Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':

    group_rows
top_counties <- final_df %>%
  filter(!is.na(asthma_ed_rate_0_4)) %>%
  arrange(desc(asthma_ed_rate_0_4)) %>%
  slice_head(n = 10) %>%
  transmute(
    County = california_county,
    `Asthma ED Rate` = round(asthma_ed_rate_0_4, 1),
    `Mean PM2.5` = round(mean_pm25, 2),
    `Median CES Score` = round(median_ces_score, 1)
  )

knitr::kable(
  top_counties,
  format = "html",
  caption = "Top 10 California Counties by Pediatric Asthma ED Visit Rate, 2020",
  align = c("l", "r", "r", "r")
) %>%
  kable_styling(
    bootstrap_options = c("striped", "hover"),
    full_width = FALSE,
    position = "center"
  ) %>%
  column_spec(1, bold = TRUE) %>%
  row_spec(0, bold = TRUE)
Top 10 California Counties by Pediatric Asthma ED Visit Rate, 2020
County Asthma ED Rate Mean PM2.5 Median CES Score
Fresno 70.6 13.18 42.8
Madera 67.5 11.40 41.3
Merced 53.4 11.70 43.7
Kings 50.0 13.65 40.7
San Joaquin 41.1 10.66 36.1
Lake 40.9 3.76 19.9
Solano 38.3 8.52 22.1
Stanislaus 32.7 11.30 37.1
Sacramento 32.4 8.76 23.3
Kern 32.0 13.46 39.6

Interpretation: Fresno, Madera, and Merced counties had the highest reported asthma emergency department visit rates among children ages 0–4 in 2020. Several counties with elevated asthma ED visit rates also had relatively high PM2.5 concentrations and CalEnviroScreen (CES) scores. There were some exceptions. Lake County, for example, has a high ED rate but low PM2.5 concentration and CES score, suggesting that factors beyond these environmental measures may be at play.

Correlation plots

library(ggplot2)

Pearson_r <- cor(final_df$median_ces_score, final_df$asthma_ed_rate_0_4, use= "complete.obs")
ggplot(final_df, aes(x = median_ces_score, y = asthma_ed_rate_0_4)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(
    title = "Median CES Score vs Adjusted Asthma Rates by County",
    x = "Median CES Score",
    y = "Adjusted Asthma Rate per 10,000"
  )
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 19 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 19 rows containing missing values or values outside the scale range
(`geom_point()`).

The scatter plot shows the correlation between adjusted asthma rates per county and median CES scores per county. The plot shows a correlation coefficient of 0.67 between the two variables, with most larger residuals present with higher median CES scores.