Milestone #4

First, discordant column names, values, and formats were recoded, then the morbidity datasets were combined into a single dataset. County was the selected geographic stratum of interest.

Data was then aggregated into a new dataframe which only included one row per county. The population dataset was also recoded in order to be consistent with the morbidity datasets, allowing them to then be joined.

Using the county stratum, a rate metric of cases per 100k population members was calculated and then summarized to show one row per strata of interest.

Morbidity and population datasets were first aggregated by county in order to calculate the number of reported infections relative to the 2023 county population.

County-level morbidity and population estimates were then combined using county as the common feature. Then, reported infections per 100,000 residents was calculated as follows:

# Check for morbidity counties without matching population data
unmatched_morbidity <- anti_join(
  morbidity_by_county,
  population_by_county,
  by = "county"
)

if (nrow(unmatched_morbidity) > 0) {
  stop(
    "No population match for: ",
    paste(unmatched_morbidity$county, collapse = ", ")
  )
}

# Join population and morbidity datasets
county_rates <- population_by_county %>%
  left_join(morbidity_by_county, by = "county") %>%
  mutate(
    cases_per_100k = (total_cases / population_2023) * 100000,
    percent_of_total_cases = (total_cases / sum(total_cases, na.rm = TRUE)) * 100
  ) %>%
  arrange(desc(cases_per_100k))

# Number of counties without matching morbidity data
unmatched_counties <- sum(is.na(county_rates$total_cases))

# Retain complete cases for descriptive summaries
county_rates_complete <- county_rates %>%
  filter(!is.na(cases_per_100k))

if (nrow(county_rates_complete) == 0) {
  stop("No counties have complete morbidity and population data.")
}

# Export final dataset
write.xlsx(county_rates, "County-Level Analysis.xlsx")

\[\text{Cases per 100,000} = \frac{\text{Total Reported Cases in County}}{\text{2023 County Population}} * 100,000\]

County-Level Dataset

The following variables were included in the final version of the county-level dataset:

Table 1. Data Dictionary for County-Level Analysis
Variable Data Type Description
county Character Name of County
total_cases Numeric Total reported new infections in the county during the observation period.
population_2023 Numeric Estimated county population in 2023.
cases_per_100k Numeric Reported new infections per 100,000 residents over the observation period.
percent_of_total_cases Numeric Percentage of all reported cases in the dataset that occurred in the county.

The final dataset contains five variables describing reported infections and population characteristics across counties. County serves as the geographic stratum, while the remaining variables quantify reported infections, population, population-adjusted case measures, and each county’s contribution to statewide totals.

Descriptive Statistics

A summary of the distribution of reported cases, population estimates, and cases per 100,000 across California counties follows.

Table 2. Descriptive Statistics Across Counties
Variable Minimum Median Mean Maximum
Total reported cases 128.0 21,655.5 78,441.1 886,156.0
Population (2023) 1,165.0 183,462.0 674,294.3 9,825,708.0
Cases per 100,000 7,832.4 10,185.5 13,193.1 43,767.2
Share of California Cases (%) 0.0 0.5 1.7 19.5

Descriptive statistics were calculated across all 58 California counties to characterize geographic variance in reported infections and disease burden. The median number of reported cases per county was approximately 21,655.5, compared with a mean of approximately 78,441.1. This data indicates a right-skewed distribution in which a relatively small number of counties contributed significantly more cases than others. This pattern is consistent with the large differences in county population sizes; ranging from 1,165 to 9,825,708 individuals.

After adjusting for population, the median number of reported cases was 10,185.5 per 100,000 residents, with county-level values ranging from 7,832.4 to 43,767.2. Individual counties contributed between approximately 0 and 19.5% of all reported cases (in the dataset).

The ten counties found with the highest number of reported cases per 100,000 residents are as follows:

top_counties <- county_rates_complete %>%
  arrange(desc(cases_per_100k)) %>%
  slice_head(n = 10) %>%
  mutate(
    total_cases = scales::comma(total_cases),
    population_2023 = scales::comma(population_2023),
    cases_per_100k = round(cases_per_100k, 1)
  ) %>%
  rename(
    County = county,
    `Total Cases` = total_cases,
    `2023 Population` = population_2023,
    `Cases per 100,000` = cases_per_100k,
    `Percent of Total Cases` = percent_of_total_cases
  )

knitr::kable(
  top_counties,
  caption = "Table 3. Ten Counties With the Highest Reported Case Measures",
  align = c("l", "r", "r", "r")
) %>%
  kable_styling(
    bootstrap_options = c("striped", "condensed"),
    latex_options = "striped",
    full_width = FALSE,
    position = "center"
  ) %>%
  column_spec(1, bold = TRUE)
Table 3. Ten Counties With the Highest Reported Case Measures
County 2023 Population Total Cases Cases per 100,000 Percent of Total Cases
Imperial 179,639 78,623 43767.2 1.7281364
Inyo 18,731 5,037 26891.2 0.1107134
Kern 903,372 218,554 24193.1 4.8038249
Tulare 474,792 112,499 23694.4 2.4727321
Kings 152,405 34,815 22843.7 0.7652350
Merced 285,600 64,591 22615.9 1.4197125
San Bernardino 2,170,593 487,857 22475.7 10.7231146
Colusa 21,905 4,627 21123.0 0.1017016
Stanislaus 545,704 108,872 19950.7 2.3930105
Tehama 64,677 12,645 19551.0 0.2779376

Data Quality

Table 4. Data Cleaning and Completeness Summary
Measure Value
Morbidity rows excluded during cleaning 0
Counties in population dataset 58
Counties with complete population and morbidity data 58
Counties without matching morbidity records 0

No morbidity records were excluded during the specified cleaning procedures, and all 58 counties in the population dataset had corresponding morbidity records. As such, no counties were excluded from the final analysis because of unsuccessful matching between morbidity and population data.

Visualizations

Reported Cases Over Time

Across the ten counties with the highest reported case rates, weekly reported cases generally increased through the summer and peaked during late summer or early fall before declining toward the end of the observation period. San Bernardino County had higher weekly case counts than the other counties, but several counties showed similar patterns over time.

top_10_counties <- county_rates %>%
  slice_max(cases_per_100k, n = 10) %>%
  pull(county)

top10_weekly <- combined_morbidity %>%
  mutate(county = str_remove(county, " County$")) %>%
  filter(county %in% top_10_counties) %>%
  group_by(county, dt_diagnosis) %>%
  summarise(
    weekly_cases = sum(new_infections, na.rm = TRUE),
    .groups = "drop")

ggplot(top10_weekly, aes(
  x = dt_diagnosis,
  y = weekly_cases)) +
  geom_line(color = "steelblue") +
  geom_point(color = "steelblue") +
  facet_wrap(~ county, ncol = 5) +
  labs(
  title = "Weekly Reported Cases Among the 10 Counties With the Highest Case Rates",
  subtitle = "California, 2023",
  x = "Diagnosis Date",
  y = "Weekly Reported Cases",
  caption = "Counties were selected based on the highest overall reported cases per 100,000 residents during the 2023 observation period.") +
  theme_minimal()

Percentage of Total Reported Cases by County

This bar chart illustrates the distribution of reported infections among the 10 counties in California with the highest percentage of total reported cases in 2023. Los Angeles County contributed the largest share of reported infections among these counties.

top_10_percent <- county_rates_complete %>%
  arrange(desc(percent_of_total_cases)) %>%
  slice_head(n = 10)

ggplot(top_10_percent,
       aes(x = reorder(county, percent_of_total_cases),
           y = percent_of_total_cases)) +
  geom_col(fill = "mediumpurple") +
  coord_flip() +
  labs(
    title = "Counties With the Largest Proportion of Reported Infection",
    subtitle = "Percentage of total reported cases in California (2023)",
    x = "County (in California)",
    y = "Percentage of Total Cases (%)"
  ) +
  theme_light()