Milestone 1__________________________________________________________________________________

What is the data source?

The source data: From the California department of public health. date data collected: Jan 1, 2020 - July 1, 2023 Files used are csv files: sim_flu_CA.csv, sim_flu_LACounty.csv, and ca_vax_rates_quarter.csv

This data contains vaccine update rates. Give number of new infections, cumulative frequency, number of COVID infections, demographic data, and, quarterly COVID vaccination rates by county and age category. Link to path: https://github.com/PHW290/phw251_projectdata.git and https://data.chhs.ca.gov/dataset/covid-19-hospital-data and https://data.chhs.ca.gov/organization/california-department-of-public-health

How does the dataset relate to the group problem statement and question?

Any correlation between COVID vaccination rates and flu rates or severity. Data give information on the number of incidence, the vaccination uptake rates and the severity rates.

Milestone 2______________________________________________________________________________________

Importing flu_CA, flu_LA and flu_ca_vax datasets

flu_ca <- readr::read_csv(
  "~/PHW251_Fall2023/problem_sets/Milestone_2/sim_flu_CA.csv", 
                col_names = TRUE,
                col_types = NULL,
                skip = 0,
                n_max = Inf,
                guess_max = min(5000, na.rm = FALSE),
                skip_empty_rows = TRUE
                )

flu_la <- readr::read_csv(
  "~/PHW251_Fall2023/problem_sets/Milestone_2/sim_flu_LACounty.csv", 
                col_names = TRUE,
                col_types = NULL,
                skip = 0,
                n_max = Inf,
                guess_max = min(5000, na.rm = FALSE),
                skip_empty_rows = TRUE
                )

flu_la <- rename_with(
  flu_la, ~tolower(
    gsub(" ", "_", .x, fixed = TRUE)))



flu_ca_vax <- readr::read_csv(
  "~/PHW251_Fall2023/problem_sets/Milestone_2/ca_vax_rates_quarter.csv", 
                col_names = TRUE,
                col_types = NULL,
                skip = 0,
                n_max = Inf,
                guess_max = min(5000, na.rm = FALSE),
                skip_empty_rows = TRUE
                )

flu_ca_vax <- rename_with(
  flu_ca_vax, ~tolower(
    gsub(" ", "_",
         .x, fixed = TRUE)))

Milestone 3______________________________________________________________________________________

Reordering and renaming datasets

#restructuring
flu_ca_restruct <- flu_ca[, c(1, 15, 14, 13, 17, 16, 2, 3, 11, 4, 9, 6, 7, 12, 8, 10, 5, 18)]
flu_la_restruct <- flu_la[, c( 4, 3, 2, 1, 5, 6, 12, 7, 8, 9, 13, 10, 11)]
flu_ca_vax_restruct <- flu_ca_vax[, c(1, 2, 3, 4, 13, 6, 7, 10, 9, 8, 12, 11, 5)]

# renaming flu 1
flu_ca_restruct <- rename(flu_ca_restruct, dt_dx = dt_diagnosis, dt_report = report_date, 
                         susceptible_count = count_susceptible, new_dx = new_infections)

# flu 2 renaming columns
flu_la_restruct <- rename(flu_la_restruct, age_cat = age_category, new_severe = severe_new,
                         new_recovered = recovered_new, current_infected = infected_current,
                         cumulative_infected = infected_cumulative, new_dx = dx_new, 
                         cumulative_severe = severe_cumulative,cumulative_recovered = recovered_cumulative,
                         susceptible_count = susceptible)


# renaming flu 3

flu_ca_vax_restruct <- rename(flu_ca_vax_restruct, county = county_name, tot_part_vax = total_partial_vaccinated,
                         cumulative_unvax = cumulative_unvaccinated,
                         cumulative_fulvax =cumulative_fully_vaccinated,est_pop = estimated_population,
                         cumulative_up2date = cumulative_up_to_date_vax,
                         )

Subseting data

subset_ca <- subset(flu_ca_restruct, 
                       select = c("county", "age_cat", "sex", "new_dx", 
                                  "new_severe", "cumulative_severe", "susceptible_count", "pop",
                                  "dt_dx","dt_report", "race_ethnicity"))
head(subset_ca)
## # A tibble: 6 × 11
##   county     age_cat sex   new_dx new_severe cumulative_severe susceptible_count
##   <chr>      <chr>   <chr>  <dbl>      <dbl>             <dbl>             <dbl>
## 1 Alameda C… 0-17    FEMA…    121          0                 0             46000
## 2 Alameda C… 0-17    FEMA…     75          0                 0             45925
## 3 Alameda C… 0-17    FEMA…     76          0                 0             45849
## 4 Alameda C… 0-17    FEMA…     89          0                 0             45760
## 5 Alameda C… 0-17    FEMA…     54          0                 0             45706
## 6 Alameda C… 0-17    FEMA…     68          1                 1             45638
## # ℹ 4 more variables: pop <dbl>, dt_dx <date>, dt_report <date>,
## #   race_ethnicity <dbl>
subset_la <- subset(flu_la_restruct, 
                       select = c("age_cat", "sex", "dt_dx", "race_eth",
                                  "new_dx", "new_severe", "cumulative_severe", "susceptible_count"))
head(subset_la)
## # A tibble: 6 × 8
##   age_cat sex    dt_dx     race_eth          new_dx new_severe cumulative_severe
##   <chr>   <chr>  <chr>     <chr>              <dbl>      <dbl>             <dbl>
## 1 0-17    FEMALE 03OCT2022 White, Non-Hispa…    513          0                 0
## 2 0-17    FEMALE 09OCT2022 White, Non-Hispa…    343          0                 0
## 3 0-17    FEMALE 19OCT2022 White, Non-Hispa…    340          0                 0
## 4 0-17    FEMALE 26OCT2022 White, Non-Hispa…    422          1                 1
## 5 0-17    FEMALE 01NOV2022 White, Non-Hispa…    321          1                 2
## 6 0-17    FEMALE 05NOV2022 White, Non-Hispa…    366          0                 2
## # ℹ 1 more variable: susceptible_count <dbl>
subset_ca_vax <- subset(flu_ca_vax_restruct,
                       select = c("county", "demographic_category", "demographic_value", "tot_part_vax",
                                  "cumulative_unvax", "cumulative_fulvax",
                                  "est_pop", "cumulative_up2date"))

head(subset_ca_vax)
## # A tibble: 6 × 8
##   county  demographic_category demographic_value tot_part_vax cumulative_unvax
##   <chr>   <chr>                <chr>                    <dbl>            <dbl>
## 1 Alameda Age Group            12-17                     6246            11988
## 2 Alameda Age Group            12-17                     6145            12090
## 3 Alameda Age Group            12-17                     6004            12255
## 4 Alameda Age Group            12-17                     5921            12473
## 5 Alameda Age Group            12-17                     5630            12990
## 6 Alameda Age Group            12-17                     5466            13923
## # ℹ 3 more variables: cumulative_fulvax <dbl>, est_pop <dbl>,
## #   cumulative_up2date <dbl>

Cleaning flu_ca

# renaming rows in sex column
subset_ca$sex <- tolower(subset_ca$sex)
subset_ca$sex <- gsub("^f", "F", subset_ca$sex)
subset_ca$sex <- gsub("^m", "M", subset_ca$sex)

# splitting up the dt_dx column to get Year into one variable

subset_ca <- subset_ca %>% 
  mutate(
    dt_dx = as.Date(dt_dx),
    yr_dt_dx = year(dt_dx),
    mo_dt_dx = month(dt_dx),
    day_dt_dx = day(dt_dx)
  )

# splitting up the dt_report column to get Year into one variable

subset_ca <- subset_ca %>% 
  mutate(
    dt_report = as.Date(dt_report),
    yr_dt_report = year(dt_report),
    mo_dt_report = month(dt_report),
    day_dt_report = day(dt_report)
  )

# rename race ethnicity column

subset_ca <- subset_ca %>% 
  rename(
       race_eth = race_ethnicity)


subset_la %>% 
  group_by(age_cat) %>% 
  summarise(count = n())
## # A tibble: 4 × 2
##   age_cat count
##   <chr>   <int>
## 1 0-17      504
## 2 18-49     504
## 3 50-64     504
## 4 65+       504
sum(is.na(subset_ca))
## [1] 0

Cleaning flu_la

# lower case rows for the sex column
subset_la$sex <- tolower(subset_la$sex)
subset_la$sex <- gsub("^f", "F", subset_la$sex)
subset_la$sex <- gsub("^m", "M", subset_la$sex)

# splitting up the dt_dx column to get Year into one variable

subset_la$dt_dx <- as.Date(subset_la$dt_dx, format = "%d%b%Y")

subset_la <- subset_la %>%
  mutate(
    yr_dt_dx = format(dt_dx, "%Y"),
    mo_dt_dx = format(dt_dx, "%m"),
    day_dt_dx = format(dt_dx, "%d")
  )

class(subset_la$dt_dx)
## [1] "Date"
# renaming rows in the race_eth column

subset_la %>% 
  group_by(race_eth) %>% 
  summarise(count = n())
## # A tibble: 7 × 2
##   race_eth                                               count
##   <chr>                                                  <int>
## 1 American Indian or Alaska Native, Non-Hispanic           288
## 2 Asian, Non-Hispanic                                      288
## 3 Black, Non-Hispanic                                      288
## 4 Hispanic (any race)                                      288
## 5 Multiracial (two or more of above races), Non-Hispanic   288
## 6 Native Hawaiian or Pacific Islander, Non-Hispanic        288
## 7 White, Non-Hispanic                                      288
subset_la<- subset_la %>% 
  mutate(race_eth = recode(race_eth,
                           "American Indian or Alaska Native, Non-Hispanic" = "AI/AN-NH",
                           "Asian, Non-Hispanic" = "Asian-NH",
                           "Black, Non-Hispanic" = "AA/Black-NH",
                           "Hispanic (any race)" = "Latinx-Any Race",
                           "Multiracial (two or more of above races), Non-Hispanic" = "Multi_Race-NH",
                           "Native Hawaiian or Pacific Islander, Non-Hispanic" = "NatH/PI",
                           "White, Non-Hispanic" = "White-NH"
))
sum(is.na(subset_la))
## [1] 0

Cleaning flu_ca_vax data

# using pivot wider to separate Age_group, race ethnicity, and gender into three columns
subset_ca_vax <- subset_ca_vax %>% 
  pivot_wider(names_from = demographic_category,
              values_from = demographic_value, values_fn = list)

# renaming new columns
subset_ca_vax <- subset_ca_vax %>% 
  rename(
       sex = Gender,
    age_cat = "Age Group",
    race_eth = "Race/Ethnicity",
    pop = "est_pop" )

Adding a demographic variable (county) to subset_la

subset_la_county <- subset_la %>% mutate(county = "Los Angeles County")

Subsetting subset_ca by demographics for flu_CA dataset

#age_cat, new_dx, susceptible count, dt_dx
subset_ca_age_gp <- subset_ca %>%
  select("age_cat", "new_dx", "dt_dx", "susceptible_count")

subset_ca_sex <- subset_ca %>%
  select("sex", "new_dx", "dt_dx", "susceptible_count")

subset_ca_county <- subset_ca %>%
  select("county", "new_dx", "dt_dx", "susceptible_count")

Subsetting subset_la by demographics for flu_LA dataset

#age_cat, new_dx, susceptible count, dt_dx
subset_la_age_gp <- subset_la %>%
  select("age_cat", "new_dx", "dt_dx", "susceptible_count")

subset_la_sex <- subset_la %>%
  select("sex", "new_dx", "dt_dx", "susceptible_count")

subset_la_county <- subset_la_county %>%
  select("county","new_dx", "dt_dx", "susceptible_count")

Merging the CA and LA by age_cat, sex and county

merge_by_age_gp <- full_join(
  subset_ca_age_gp, subset_la_age_gp, by = c("age_cat" = "age_cat","new_dx" = "new_dx","susceptible_count" = "susceptible_count","dt_dx"="dt_dx"))

merge_by_sex <- full_join(
  subset_ca_sex, subset_la_sex, by = c("sex" = "sex","new_dx" = "new_dx","susceptible_count" = "susceptible_count","dt_dx"="dt_dx"))

merge_by_county <- full_join(
  subset_ca_county, subset_la_county, by = c("county" = "county","new_dx" = "new_dx","susceptible_count" = "susceptible_count","dt_dx"="dt_dx"))

Creating new variables needed for analysis

# variables (rates for subset_ca)
flu_ca_la_age_gp <- merge_by_age_gp %>%
  mutate(flu_inc_by_age = (new_dx/susceptible_count)* 100000) 
flu_ca_la_sex <- merge_by_sex %>%
  mutate(flu_inc_by_sex = (new_dx/susceptible_count)* 100000)
flu_ca_la_county <- merge_by_county %>%
  mutate(flu_inc_by_county = (new_dx/susceptible_count)* 100000)

subset_ca_vax <- subset_ca_vax %>%
  mutate(tot_part_vax_rate = (tot_part_vax/pop)* 100000) %>%
  mutate(cum__unvax_rate = (cumulative_unvax/pop) * 100000) %>%
  mutate(cum_fulvax_rate = (cumulative_fulvax/pop)* 100000) %>%
  mutate(cum_up2date_rate = (tot_part_vax/pop)* 100000)

Data dictionary based on clean dataset (minimum 4 data elements)

# data dictionary
library(Hmisc)
data_dictionary_1 <- read.csv(
  "~/PHW251_Fall2023/problem_sets/Milestone_2/Dataset Dictionary.csv")
describe(data_dictionary_1)
## data_dictionary_1 
## 
##  5  Variables      9  Observations
## --------------------------------------------------------------------------------
## Type 
##        n  missing distinct    value 
##        9        0        1  Dataset 
##                   
## Value      Dataset
## Frequency        9
## Proportion       1
## --------------------------------------------------------------------------------
## Dataset.Name 
##        n  missing distinct 
##        9        0        9 
## 
## flu_1_restruct (1, 0.111), flu_2_restruct (1, 0.111), flu_3_restruct (1,
## 0.111), flu_data_1 (1, 0.111), flu_data_2 (1, 0.111), flu_data_3 (1, 0.111),
## subset_flu_1 (1, 0.111), subset_flu_2 (1, 0.111), subset_flu_3 (1, 0.111)
## --------------------------------------------------------------------------------
## Description 
##        n  missing distinct 
##        9        0        9 
## 
## lowest : flu_data_1 restructured              flu_data_2 restructured              flu_data_3 restructured              Original ca_vax_rtes_quarter dataset original sim_flu_CA dataset         
## highest: original sim_flu_CA dataset          original sim_flu_LACounty dataset    subset of restructured flu 1         subset of restructured flu 2         subset of restructured flu 3        
## --------------------------------------------------------------------------------
## Number.of.variables 
##        n  missing distinct     Info     Mean      Gmd 
##        9        0        4    0.925    43143    56620 
##                                       
## Value        2016  10434  13533 114912
## Frequency       3      1      2      3
## Proportion  0.333  0.111  0.222  0.333
## 
## For the frequency table, variable is rounded to the nearest 0
## --------------------------------------------------------------------------------
## X..of.observations 
##        n  missing distinct     Info     Mean      Gmd 
##        9        0        4    0.825       15    4.056 
##                                   
## Value         11    13    18    23
## Frequency      1     5     2     1
## Proportion 0.111 0.556 0.222 0.111
## 
## For the frequency table, variable is rounded to the nearest 0
## --------------------------------------------------------------------------------
data_dictionary_2 <- read.csv(
  "~/PHW251_Fall2023/problem_sets/Milestone_2/Flu_data_Dictionary.csv")
describe(data_dictionary_2)
## data_dictionary_2 
## 
##  4  Variables      47  Observations
## --------------------------------------------------------------------------------
## Dataset.Name 
##        n  missing distinct 
##       47        0        3 
##                                                  
## Value      subset_flu_1 subset_flu_2 subset_flu_3
## Frequency            23           11           13
## Proportion        0.489        0.234        0.277
## --------------------------------------------------------------------------------
## Column.Name 
##        n  missing distinct 
##       47        0       34 
## 
## lowest :  flu_inc_at_risk      flu_new_sev_at_risk  flu_new_sev_tot_pop  yr_dt_dx            age_cat             
## highest: susceptible_count    tot_part_vax         tot_part_vax_rate    yr_dt_dx             yr_dt_report        
## --------------------------------------------------------------------------------
## Description 
##        n  missing distinct 
##       47        0       44 
## 
## lowest : Age category                         Age grouping 0-17, 18-49, 50-64, 65+ CA county name                       Cumulative fully vaccinated rate     Cumulative severe flu cases         
## highest: Sex (Female, Male)                   Total population                     Year date diagnosis                  Year date report                     Year diagnosis date                 
## --------------------------------------------------------------------------------
## Type 
##        n  missing distinct 
##       47        0        4 
##                                                   
## Value      Character      Date   Integer   Numeric
## Frequency         13         3         2        29
## Proportion     0.277     0.064     0.043     0.617
## --------------------------------------------------------------------------------

One or more tables with descriptive statistics for 4 data elements

result_ca_la_age <- aggregate(new_dx ~ age_cat, data = merge_by_age_gp,
      FUN = function(x) round(c(mean = mean(x), sd = sd(x)), digits = 1))
tibble(result_ca_la_age)
## # A tibble: 4 × 2
##   age_cat new_dx[,"mean"] [,"sd"]
##   <chr>             <dbl>   <dbl>
## 1 0-17               132.    688.
## 2 18-49              252    1345.
## 3 50-64              110     566.
## 4 65+                100.    506.
result_ca_la_sex <- aggregate(new_dx ~ sex, data = merge_by_sex,
   FUN = function(x) round(c(mean = mean(x),sd = sd(x)), digits = 1))
     
tibble(result_ca_la_sex)  
## # A tibble: 2 × 2
##   sex    new_dx[,"mean"] [,"sd"]
##   <chr>            <dbl>   <dbl>
## 1 Female            149.    837.
## 2 Male              148.    858.
result_ca_la_county <- aggregate(new_dx ~ county, data = merge_by_county,
                FUN = function(x) round(c(mean = mean(x), sd = sd(x)), digits = 1))

tibble(result_ca_la_county)
## # A tibble: 58 × 2
##    county              new_dx[,"mean"] [,"sd"]
##    <chr>                         <dbl>   <dbl>
##  1 Alameda County                362.    663. 
##  2 Alpine County                   0.2     0.9
##  3 Amador County                   8.1    24.6
##  4 Butte County                   48.9   142. 
##  5 Calaveras County                9.4    29.4
##  6 Colusa County                   4.9    13.7
##  7 Contra Costa County           250.    495. 
##  8 Del Norte County                5.8    14.7
##  9 El Dorado County               40.7   119  
## 10 Fresno County                 221.    544. 
## # ℹ 48 more rows
result_ca_vax <- aggregate(cumulative_fulvax ~ county, data = subset_ca_vax, 
                    FUN = function(x) round(c(mean = mean(x), sd = sd(x)), digits = 1))

tibble(result_ca_vax)
## # A tibble: 59 × 2
##    county       cumulative_fulvax[,"mean"] [,"sd"]
##    <chr>                             <dbl>   <dbl>
##  1 Alameda                         178668. 226128.
##  2 Alpine                             190.    112.
##  3 Amador                            3292    4699.
##  4 Butte                            15908.  22992.
##  5 Calaveras                         3873.   5290.
##  6 Colusa                            2191.   2508.
##  7 Contra Costa                    123453. 156056.
##  8 Del Norte                         2025.   2625.
##  9 El Dorado                        16106.  23894.
## 10 Fresno                           79315. 104963.
## # ℹ 49 more rows

Milestone 4_______________________________________________________________________________________

Structure of Joined Data

str(flu_ca_la_vax_join)
## tibble [222,061 × 14] (S3: tbl_df/tbl/data.frame)
##  $ county            : chr [1:222061] "Alameda" "Alameda" "Alameda" "Alameda" ...
##  $ new_dx            : num [1:222061] 121 75 76 89 54 68 66 195 339 160 ...
##  $ new_severe        : num [1:222061] 0 0 0 0 0 1 0 1 0 0 ...
##  $ cumulative_severe : num [1:222061] 0 0 0 0 0 1 1 2 2 2 ...
##  $ susceptible_count : num [1:222061] 46000 45925 45849 45760 45706 ...
##  $ pop               : num [1:222061] 46000 46000 46000 46000 46000 46000 46000 46000 46000 46000 ...
##  $ dt_dx             : Date[1:222061], format: "2022-10-02" "2022-10-10" ...
##  $ yr_dt_dx          : num [1:222061] 2022 2022 2022 2022 2022 ...
##  $ mo_dt_dx          : num [1:222061] 10 10 10 10 10 11 11 11 11 11 ...
##  $ day_dt_dx         : num [1:222061] 2 10 16 24 27 10 15 19 29 29 ...
##  $ tot_part_vax      : num [1:222061] NA NA NA NA NA NA NA NA NA NA ...
##  $ cumulative_unvax  : num [1:222061] NA NA NA NA NA NA NA NA NA NA ...
##  $ cumulative_fulvax : num [1:222061] NA NA NA NA NA NA NA NA NA NA ...
##  $ cumulative_up2date: num [1:222061] NA NA NA NA NA NA NA NA NA NA ...

Tables: Newly diagnosed, County, Average number newly diagnosed, County with highest number of newly diagnosed Flu cases

avg_inc_rate <- mean(!is.na(flu_ca_la_vax_join$incidence_at_risk))

table_join_df<- flu_ca_la_vax_join %>%
  select(county, incidence_at_risk, yr_dt_dx) %>%
 filter(county==c("Los Angeles", "Riverside", "Orange", "Alameda", "Yolo") & incidence_at_risk>= avg_inc_rate) %>%
  distinct(county, .keep_all = TRUE) 
 
datatable(table_join_df)
  ave_num_disease <- mean(!is.na(flu_ca_la_vax_join$new_dx))
  
 # Orange county recorded the highest number of newly diagnosed cases 
high_new_dx_county<- flu_ca_la_vax_join %>%
  group_by(yr_dt_dx == 2022:2023) %>%
  filter(county =="Orange", new_dx >= 10000)%>%
  select(county,new_dx, incidence_at_risk)
datatable(high_new_dx_county)
#Most populated county with highest number of fully vaccinated individuals.
county_yr <- flu_ca_la_vax_join %>%
  group_by(cumulative_fulvax) %>%
  filter(incidence_at_risk >= 5100 & new_severe == 4) %>%
  select(county, new_dx, incidence_at_risk, yr_dt_dx) %>%
  drop_na()

datatable(county_yr)

New severe cases over time in 5 populated counties

library(ggplot2)
library(ggthemes)

ggplot(flu_ca_la_vax_join , aes(x = yr_dt_dx, y = new_severe, fill = county)) +
  geom_bar(stat = "identity", position = "dodge") +
  theme(panel.background = element_rect(fill = "white")) +
  xlim(2021,2024) +
  scale_fill_manual(values = c("Riverside" = "cyan3", "San Diego" = "orange", 
  "San Bernardino" = "blue", "Los Angeles" = "black", "Orange" = "green"),
    name = "County") + labs(
    title = "Number of New Severe Cases by Years and Counties; 
    highlighting 5 most populated counties in California",
    caption =
    "This represents the number of newly diagnosed 
    Flu cases that were severe in the 5 most populated counties",
    x = "Year Diagnosis",
    y = "# of New Severe Cases",
    fill = "County")

Number of newly diagnosed per population over time

ggplot(flu_ca_la_vax_join , aes(x = yr_dt_dx, y = incidence_tot_pop, fill = county)) +
  geom_bar(stat = "identity", position = "dodge") +
  theme(panel.background = element_rect(fill = "white")) +
  xlim(2021,2024) +
  scale_fill_manual(values = c("Riverside" = "cyan3", "San Diego" = "orange", 
  "San Bernardino" = "blue", "Alameda" = "red", "Orange" = "green"),
    name = "County") + labs(
    title = "Total number of persons with up to date vaccination status by counties; 
    highlighting 5 counties in California",
    x = "Year Diagnosis",
    y = "Flu Rate per 100,000 population",
    fill = "County"
  )

Modeling and assessing relationship between newly diagnosed flu cases to vaccination status: up to date vaccination to number of newly diagnosed Flu cases

filter_df <- flu_ca_la_vax_join %>%
  group_by(cumulative_up2date) %>%
  mutate(count = n()) %>% filter(yr_dt_dx!=2023) %>% drop_na()

correlation_test <- cor.test(filter_df$cumulative_up2date,filter_df$new_dx)

scatter_model <- ggplot(filter_df, aes(x = cumulative_up2date, y = new_dx)) + 
  geom_point() + 
  geom_smooth(method = "lm", lwd = 1, col = "red") + 
  annotate("text", x = 22, y = 10 , 
           label = paste("Correlation:",round(correlation_test$estimate, digits=3))) +
  ggtitle("Newly diagnosed Flu cases compared
          to up to date vaccination status from 2020 to 2024") +  ylim(0,NA) +
  xlab("Vaccination up to date") + 
  ylab("Newly Diagnosed") + 
  theme_bw() + 
  theme(plot.title = element_text(hjust = 0.5, size = 10)) +
  scale_x_log10()

# Annotating the scatter plot with the p-value and CI to test if the correlation between newly diagnosed flu cases is significantly associated with up to date vaccination 
p_value_text <- paste0("p-value: ", correlation_test$p.value)
confidence_interval <- paste0("confidence interval: ", round(correlation_test$conf.int, digits =3))
scatter_with_annotations <- scatter_model +
  annotate("text", x = 22, y = 12, label = p_value_text) +labs(caption ="There is a positive weak correlation between having flu and vaccination status. This correlation is significant;
implying that those who are up to date with their vaccination status are less likely to have Flu")
  
print(scatter_with_annotations)

Histogram of number of newly diagnosed and rate of new disease to susceptible population; that is number of newly diagnosed per susceptible count per 100,000 population

filtered_df<- flu_ca_la_vax_join %>%
  group_by(cumulative_severe) %>%
  mutate(count = n()) %>% filter(yr_dt_dx!=2023) %>% drop_na()

gg_hist2 <- ggplot(data = flu_ca_la_vax_join, aes(x = incidence_tot_pop)) + 
  geom_histogram(fill = "blue", color = "black", bins = 20) + 
  scale_y_continuous(limits=c(0,1000)) + 
  scale_x_continuous(limits = c(5000, 50000)) +
  ggtitle("Incidence rate of flu in LA and CA") + 
  ylim(0, NA) +
  xlab("Incidence") + 
  ylab("Frequency") + 
    theme_classic() 
 print(gg_hist2) 

 library(ggplot2)
gg_hist <- ggplot(data = flu_ca_la_vax_join, aes(x = new_dx)) + 
  geom_histogram(fill = "cyan3", color = "black", bins = 20) + 
  scale_y_continuous(limits=c(0,2000)) + 
  scale_x_continuous(limits = c(5000, 50000)) +
  ggtitle("Newly Diagnosed Flu cases in LA and CA") + 
  xlab("Newly Diagnosed") + 
  ylab("Frequency") + 
    theme_classic() 
  
print(gg_hist)

Questions for teaching team:

  1. Should we round rates in the tables that we created?

  2. Is it allowed to compare the rate of the newly diagnosed per susceptible count to the cumulative fully vaccinated rate?

  3. Do we need more cleaning and is the flu_ca_la_vax_join dataset undestandable?

Rpub link: http://rpubs.com/Frida31/mile_st_4