# tidyverse includes dplyr, ggplot2, and stringr
library(tidyverse)
library(plotly)Group 20 Project Milestone #4
Load required packages
Joined data created in Milestone 3
# Merge county-level CES measures, CES demographics, and asthma rates
CES_meas_demog <- merge(
CES_measures_sum, CES_demog_sum, by = "county")
final_merged_data <- merge(CES_meas_demog,
CHHS_asthma_final, by = "county")
# Write the final dataset to a new CSV file
write_csv(final_merged_data, "final_merged_data.csv")Import joined data
final_data <- read.csv("final_merged_data.csv")Goal 1: Assess correlation between county asthma ED rates with a county CES measure.
# Average asthma ED rate across demographic groups
asthma_columns <-names(final_data)[10:16]
final_data$avg_asthma_rate <- rowMeans(final_data[, asthma_columns], na.rm=T)
# Scatter plot and correlation for average asthma ED rates vs. CES score
p1 <- ggplot(final_data,
aes(x = CES_score_med, y = avg_asthma_rate,
text = paste("County:", county,
"\nCES Score:", round(CES_score_med, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. County CES Score") +
xlab("Median CES Score") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p1, tooltip = "text")cor1 <- cor.test(final_data$CES_score_med, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and median CES scores is 0.199.
Goal 2: Assess correlation between county asthma ED rates with county-level summaries for specific environmental measures to determine if those specific measures may be worth further investigation.
Mean ozone concentration
p2a <- ggplot(final_data,
aes(x = ozone_mean, y = avg_asthma_rate,
text = paste("County:", county,
"\nOzone Concentration:", round(ozone_mean, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. Mean Ozone Concentration") +
xlab("Mean Ozone Concentration") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p2a, tooltip = "text")cor2a <- cor.test(final_data$ozone_mean, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and mean ozone concentration is -0.149. This means that as the mean ozone concentration in a county increases, there is a slight tendency for the asthma ED rates to decrease as well, but the relationship is not strong.This is interesting as often higher ozone concentrations can be seen in the suburbs which may be more affluent counties that have more resources.
Mean PM 2.5 concentration
p2b <- ggplot(final_data,
aes(x = pm_mean, y = avg_asthma_rate,
text = paste("County:", county,
"\nPM 2.5 Concentration:", round(pm_mean, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. PM 2.5 Concentration") +
xlab("Mean PM 2.5 Concentration") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p2b, tooltip = "text")cor2b <- cor.test(final_data$pm_mean, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and mean PM 2.5 concentration is 0.225. This means that as the mean PM 2.5 concentration in a county increases, there is a slight tendency for the asthma ED rates to increase as well, but the relationship is not strong.
Mean diesel emissions
p2c <- ggplot(final_data,
aes(x = diesel_mean, y = avg_asthma_rate,
text = paste("County:", county,
"\nDiesel Emissions:", round(diesel_mean, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. Mean Diesel Emissions") +
xlab("Mean Diesel Emissions") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p2c, tooltip = "text")cor2c <- cor.test(final_data$diesel_mean, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and mean diesel emissions is 0.288. This means that as the mean diesel emissions index in a county increases, there is a slight tendency for the asthma ED rates to increase as well, but the relationship is not strong.
Mean drinking water contaminant index
p2d <- ggplot(final_data,
aes(x = drinkwat_mean, y = avg_asthma_rate,
text = paste("County:", county,
"\nDrinking Water Contaminant Index:",
round(drinkwat_mean, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. Mean Drinking Water Contaminant Index") +
xlab("Mean Drinking Water Contaminant Index") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p2d, tooltip = "text")cor2d <- cor.test(final_data$drinkwat_mean, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and mean drinking water contaminant index is 0.0166. This means that as the mean drinking water contaminant index in a county increases, there is a slight tendency for the asthma ED rates to increase as well, but the relationship is not strong.
Mean potential risk for lead exposure
p2e <- ggplot(final_data,
aes(x = lead_mean, y = avg_asthma_rate,
text = paste("County:", county,
"\nLead Exposure Risk:", round(lead_mean, 2),
"\nAsthma ED rate:", round(avg_asthma_rate, 2)))) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = F) +
ggtitle("Average Asthma ED Rates vs. Mean Potential Risk for Lead Exposure") +
xlab("Mean Potential Risk for Lead Exposure") +
ylab("Average Asthma ED Rate") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p2e, tooltip = "text")cor2e <- cor.test(final_data$lead_mean, final_data$avg_asthma_rate)$estimateThe correlation between county-level asthma ED rates and mean lead exposure risk is 0.209. This means that as the mean lead exposure risk in a county increases, there is a slight tendency for the asthma ED rates to increase as well, but the relationship is not strong.
#Table
names(final_data)[names(final_data) == "tot_pop"] <- "Total Population"
names(final_data)[names(final_data) == "ozone_mean"] <- "Mean Ozone Concentration"
names(final_data)[names(final_data) == "pm_mean"] <- "Mean PM 2.5 Concentration"
names(final_data)[names(final_data) == "diesel_mean"] <- "Mean Diesel Emissions"
names(final_data)[names(final_data) == "drinkwat_mean"] <- "Mean Drinking Water Contaminant Index"
names(final_data)[names(final_data) == "lead_mean"] <- "Mean Potential Risk for Lead Exposure"
names(final_data)[names(final_data) == "CES_score_med"] <- "Median CES Score"
names(final_data) [1] "county"
[2] "Mean Ozone Concentration"
[3] "Mean PM 2.5 Concentration"
[4] "Mean Diesel Emissions"
[5] "Mean Drinking Water Contaminant Index"
[6] "Mean Potential Risk for Lead Exposure"
[7] "Median CES Score"
[8] "Total Population"
[9] "year"
[10] "White"
[11] "Black"
[12] "Hispanic"
[13] "Asian.PI"
[14] "AI.AN"
[15] "NHPI"
[16] "Multi.race"
[17] "avg_asthma_rate"
str(final_data)'data.frame': 58 obs. of 17 variables:
$ county : chr "Alameda" "Alpine" "Amador" "Butte" ...
$ Mean Ozone Concentration : num 0.0339 0.0502 0.0523 0.0509 0.0548 ...
$ Mean PM 2.5 Concentration : num 8.87 3.05 8.01 8.22 8.12 ...
$ Mean Diesel Emissions : num 0.35007 0.00262 0.01102 0.10624 0.00797 ...
$ Mean Drinking Water Contaminant Index: num 176 646 528 327 389 ...
$ Mean Potential Risk for Lead Exposure: num 52.5 36.5 28.1 42.4 30.6 ...
$ Median CES Score : num 20.6 13.6 19.6 21.4 16.1 ...
$ Total Population : int 1656754 1039 38429 225817 45514 21454 1142251 27495 188563 984521 ...
$ year : int 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 ...
$ White : num 13.1 0 37.6 21.4 30 30.6 15 50.3 20.6 26.3 ...
$ Black : num 89.8 0 NA 134.4 NA ...
$ Hispanic : num 23.4 0 NA 19.7 30.2 15.2 28.9 34.1 19.8 34.7 ...
$ Asian.PI : num 11.7 0 0 15.6 NA 0 11.8 NA NA 12.9 ...
$ AI.AN : num NA 0 0 NA 0 0 NA NA NA NA ...
$ NHPI : num 59.8 0 0 NA NA 0 91.5 0 0 NA ...
$ Multi.race : num 20.7 0 NA NA NA 0 10.7 NA NA 19.4 ...
$ avg_asthma_rate : num 36.4 0 9.4 47.8 20.1 ...
my.vars = c("Total Population", "Mean Ozone Concentration",
"Mean PM 2.5 Concentration", "Mean Diesel Emissions",
"Mean Drinking Water Contaminant Index",
"Mean Potential Risk for Lead Exposure",
"Median CES Score")
library(tableone)
library(xtable)
library(knitr)
table.1 <- CreateTableOne(vars = my.vars,
data = final_data,
includeNA = FALSE,
test = FALSE, addOverall = TRUE)
table.1
Overall
n 58
Total Population (mean (SD)) 677301.67 (1469524.33)
Mean Ozone Concentration (mean (SD)) 0.05 (0.01)
Mean PM 2.5 Concentration (mean (SD)) 8.05 (2.61)
Mean Diesel Emissions (mean (SD)) 0.11 (0.11)
Mean Drinking Water Contaminant Index (mean (SD)) 436.37 (151.62)
Mean Potential Risk for Lead Exposure (mean (SD)) 42.62 (9.03)
Median CES Score (mean (SD)) 22.19 (9.82)
kable(print(table.1,
showAllLevels = FALSE,
printToggle = FALSE,
noSpaces = TRUE,
catDigits = 1,
contDigits = 1),
caption = paste("Overall Outcome Distriubtion across California"))| Overall | |
|---|---|
| n | 58 |
| Total Population (mean (SD)) | 677301.7 (1469524.3) |
| Mean Ozone Concentration (mean (SD)) | 0.0 (0.0) |
| Mean PM 2.5 Concentration (mean (SD)) | 8.1 (2.6) |
| Mean Diesel Emissions (mean (SD)) | 0.1 (0.1) |
| Mean Drinking Water Contaminant Index (mean (SD)) | 436.4 (151.6) |
| Mean Potential Risk for Lead Exposure (mean (SD)) | 42.6 (9.0) |
| Median CES Score (mean (SD)) | 22.2 (9.8) |
Interpretation: This serves as a summary table to determine the levels of our outcomes across the state of California. This will be useful in further analysis, as it will help portray deviations from this summary among the different counties and genetic ancestry groups.