Description of Data Within the csv provided, the data shows counties within California. It contains data such as age, sex, race/ethnicity, infectious disease surveillance in specific counties in 2023.

Relevance to the problem: As Epidemiologists working for the California Department of Public Health, our tasks is to evaluate the course of this outbreak. First, we will identify populations disproportionately impacted across demographic and geographic locations, then see which areas need more treatment resources and prevention strategies.

Standardize and clean morbidity fields

Prepare population groups

Combine, join, and summarize

morbidity_all <- bind_rows(ca_morbidity, la_morbidity) %>%
  filter(!is.na(date)) %>%
  mutate(
    epi_year = as.integer(lubridate::epiyear(date)),
    epi_week = as.integer(lubridate::epiweek(date))
  )

population_by_stratum <- population_clean %>%
  group_by(county, age_cat, sex, race_ethnicity) %>%
  summarise(
    health_officer_region = first(health_officer_region),
    population = sum(population, na.rm = TRUE),
    .groups = "drop"
  )

sum_or_na <- function(x) {
  if (all(is.na(x))) NA_real_ else sum(x, na.rm = TRUE)
}

weekly_morbidity <- morbidity_all %>%
  group_by(date, epi_year, epi_week, county, age_cat, sex, race_ethnicity) %>%
  summarise(
    new_cases = sum_or_na(new_cases),
    new_severe = sum_or_na(new_severe),
    .groups = "drop"
  )

weekly_analysis <- weekly_morbidity %>%
 left_join(
    population_by_stratum,
    by = c("county", "age_cat", "sex", "race_ethnicity")
  ) %>%
  mutate(
    weekly_case_rate = if_else(
      !is.na(population) & population > 0 & !is.na(new_cases),
      new_cases / population * 100000,
      NA_real_
    ),
    weekly_severe_rate = if_else(
      !is.na(population) & population > 0 & !is.na(new_severe),
      new_severe / population * 100000,
      NA_real_
    )
  )

period_summary <- weekly_analysis %>%
  group_by(county, health_officer_region, age_cat, sex, race_ethnicity) %>%
  summarise(
    population = first(population),
    total_cases = sum_or_na(new_cases),
    total_severe = sum_or_na(new_severe),
    .groups = "drop"
  ) %>%
  mutate(
    case_rate_per_100k = if_else(
      !is.na(population) & population > 0 & !is.na(total_cases),
      total_cases / population * 100000,
      NA_real_
    )
  )

readr::write_csv(weekly_analysis, "milestone4_weekly_data.csv", na = "")
readr::write_csv(period_summary, "milestone4_period_summary.csv", na = "")

Seven reported cases occurred in demographic groups with population estimates of zero. These cases were included in the overall reported case counts but excluded from population-based rate calculations.

Visualizations

Weekly outbreak trend

weekly_totals <- weekly_analysis %>%
  group_by(date) %>%
  summarise(
    cases = sum_or_na(new_cases),
    severe_cases = sum_or_na(new_severe),
    .groups = "drop"
  )

weekly_long <- weekly_totals %>%
  pivot_longer(
    cols = c(cases, severe_cases),
    names_to = "measure",
    values_to = "weekly_count"
  ) %>%
  mutate(
    measure = recode(
      measure,
      cases = "New cases",
      severe_cases = "New severe cases"
    )
  )

ggplot(weekly_long, aes(x = date, y = weekly_count)) +
  geom_line(color = "#246A8D", linewidth = 0.9, na.rm = TRUE) +
  facet_wrap(vars(measure), ncol = 1, scales = "free_y") +
  scale_x_date(date_breaks = "1 month", date_labels = "%b") +
  scale_y_continuous(labels = scales::label_comma()) +
  labs(
    title = "Weekly cases during the simulated California outbreak",
    subtitle = "California, including Los Angeles County, May 29–December 25, 2023",
    x = "Diagnosis week",
    y = "Reported count",
    caption = "Source: Simulated California and Los Angeles County morbidity files. Panels use separate scales."
  ) +
  theme_minimal(base_size = 12) +
  theme(
  plot.title = element_text(face = "bold"),
  strip.text = element_text(face = "bold"),
  panel.grid.minor = element_blank(),
  plot.caption = element_text(
    size = 10,
    hjust = 0,
    margin = margin(t = 15)
  )
)

This graph shows how reported cases and severe cases changed over the observed weeks. Comparing the panels helps identify when the highest case and severe-case counts occurred. Weekly reported new cases peaked in September 2023 at approximately 400,000 cases, while new severe cases peaked slightly later in early October at approximately 11,000 cases. Both remained relatively stable for approximately one month before declining substantially toward the end of the year.

Top counties by observed-period case rate

The rate is calculated from cases and population groups that have a valid, positive population denominator. The table also shows total reported cases and severe cases across all recorded groups.

county_summary <- period_summary %>%
  mutate(
    use_for_rate =
      !is.na(population) & population > 0 & !is.na(total_cases),
    cases_for_rate = if_else(use_for_rate, total_cases, NA_real_),
    population_for_rate = if_else(use_for_rate, population, NA_real_)
  ) %>%
  group_by(county) %>%
  summarise(
    reported_cases = sum_or_na(total_cases),
    reported_severe = sum_or_na(total_severe),
    cases_for_rate = sum_or_na(cases_for_rate),
    population_for_rate = sum_or_na(population_for_rate),
    .groups = "drop"
  ) %>%
  mutate(
    case_rate_per_100k = if_else(
      population_for_rate > 0,
      cases_for_rate / population_for_rate * 100000,
      NA_real_
    )
  )

top_counties <- county_summary %>%
  filter(!is.na(case_rate_per_100k)) %>%
  arrange(desc(case_rate_per_100k)) %>%
  slice_head(n = 10) %>%
  select(
    county, reported_cases, reported_severe,
    cases_for_rate, population_for_rate, case_rate_per_100k
  )

knitr::kable(
  top_counties,
  col.names = c(
    "County",
    "Reported cases",
    "Reported severe cases",
    "Cases used in rate",
    "Population used",
    "Rate per 100,000"
  ),
  digits = c(NA, 0, 0, 0, 0, 1),
  format.args = list(big.mark = ","),
caption = "<span style='color: black; font-weight: bold; font-size: 18px;'>Ten California counties with the highest crude case rates, May 29–December 25, 2023</span>") %>%
kable_styling(full_width = FALSE) %>%
  footnote(
    general = "Source: Simulated morbidity data and 2023 California population estimates. Rates were calculated using demographic groups with positive population estimates and nonmissing case counts.",
    general_title = "Note: "
  )
Ten California counties with the highest crude case rates, May 29–December 25, 2023
County Reported cases Reported severe cases Cases used in rate Population used Rate per 100,000
Imperial 78,623 1,959 78,623 179,639 43,767.2
Inyo 5,037 207 5,036 18,731 26,885.9
Kern 218,554 5,028 218,554 903,372 24,193.1
Tulare 112,499 2,664 112,499 474,792 23,694.4
Kings 34,815 803 34,815 152,405 22,843.7
Merced 64,591 1,536 64,591 285,600 22,615.9
San Bernardino 487,857 12,044 487,857 2,170,593 22,475.7
Colusa 4,627 135 4,627 21,905 21,123.0
Stanislaus 108,872 2,882 108,872 545,704 19,950.7
Tehama 12,645 407 12,645 64,677 19,551.0
Note:
Source: Simulated morbidity data and 2023 California population estimates. Rates were calculated using demographic groups with positive population estimates and nonmissing case counts.

The table highlights counties with the highest observed-period rates while also showing their reported burden. Imperial County had the highest crude case rate at 43,767.2 cases per 100,000 people, followed by Inyo and Kern counties. However, San Bernardino had the highest number of reported cases and severe cases among the ten counties presented.

Case rates by age, race/ethnicity, and sex

demo_rates <- period_summary %>%
  filter(
    !is.na(population),
    population > 0,
    !is.na(total_cases),
    sex %in% c("FEMALE", "MALE"),
    !race_ethnicity %in% c("Unknown", "Unmapped")
  ) %>%
  group_by(age_cat, sex, race_ethnicity) %>%
  summarise(
    cases = sum(total_cases, na.rm = TRUE),
    population = sum(population, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  mutate(
    rate_per_100k = cases / population * 100000,
    age_cat = factor(
      age_cat,
      levels = c("0-17", "18-49", "50-64", "65+"),
      ordered = TRUE
    )
  )

ggplot(
  demo_rates,
  aes(x = age_cat, y = rate_per_100k, fill = race_ethnicity)
) +
  geom_col(position = position_dodge(width = 0.85), width = 0.75) +
  facet_wrap(vars(sex), ncol = 2) +
  scale_fill_brewer(palette = "Set2") +
  scale_y_continuous(labels = scales::label_comma()) +
  labs(
    title = "Observed-period case rates by demographic group in California, May 29–December 25, 2023",
    subtitle = "Crude rates per 100,000; counties combined",
    x = "Age group",
    y = "Cases per 100,000 people",
    fill = "Race/ethnicity",
    caption = "Source: Simulated morbidity files and 2023 population estimates. Unknown or unmapped categories without denominators are not shown."
  ) +
  guides(fill = guide_legend(ncol = 2)) +
theme_minimal(base_size = 12) +
theme(
  plot.title = element_text(face = "bold"),
  axis.text.x = element_text(angle = 0, hjust = 0.5),
  legend.position = "bottom",
  legend.title = element_text(face = "bold"),
  legend.text = element_text(size = 9),
  plot.caption = element_text(size = 9, hjust = 0),
  panel.grid.minor = element_blank()

  )

The chart compares observed-period case rates across age and race/ethnicity groups within each sex. Higher bars identify demographic groups for further review, while the crude rates and denominator limitations should be considered. Across both sexes and all racial and ethnic groups presented, adults aged 65 and older had the highest case rates, while individuals aged 0–17 had the lowest. Notably high rates were observed among older non-Hispanic American Indian or Alaska Native and Hispanic populations, suggesting a need for targeted prevention efforts.