The data source used is owid.covid.data provided by Our World in Data, it is open sourced and are completely open access under the Creative Commons By liscense.
Install the tidyverse package if not already installed.
if (!require("tidyverse")) {
install.packages("tidyverse", repos = "http://cran.rstudio.com/")
}
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
Cleaning, Transforming, Vizualizations
library(tidyr)
library(readr)
library(dplyr)
library(ggplot2)
Remeber to load with Headers
owid.covid.data <- read.csv("~/Desktop/owid-covid-data.csv")
In this project I worked with just a subset for the United States
print(names(owid.covid.data))
## [1] "iso_code"
## [2] "continent"
## [3] "location"
## [4] "date"
## [5] "total_cases"
## [6] "new_cases"
## [7] "new_cases_smoothed"
## [8] "total_deaths"
## [9] "new_deaths"
## [10] "new_deaths_smoothed"
## [11] "total_cases_per_million"
## [12] "new_cases_per_million"
## [13] "new_cases_smoothed_per_million"
## [14] "total_deaths_per_million"
## [15] "new_deaths_per_million"
## [16] "new_deaths_smoothed_per_million"
## [17] "reproduction_rate"
## [18] "icu_patients"
## [19] "icu_patients_per_million"
## [20] "hosp_patients"
## [21] "hosp_patients_per_million"
## [22] "weekly_icu_admissions"
## [23] "weekly_icu_admissions_per_million"
## [24] "weekly_hosp_admissions"
## [25] "weekly_hosp_admissions_per_million"
## [26] "total_tests"
## [27] "new_tests"
## [28] "total_tests_per_thousand"
## [29] "new_tests_per_thousand"
## [30] "new_tests_smoothed"
## [31] "new_tests_smoothed_per_thousand"
## [32] "positive_rate"
## [33] "tests_per_case"
## [34] "tests_units"
## [35] "total_vaccinations"
## [36] "people_vaccinated"
## [37] "people_fully_vaccinated"
## [38] "total_boosters"
## [39] "new_vaccinations"
## [40] "new_vaccinations_smoothed"
## [41] "total_vaccinations_per_hundred"
## [42] "people_vaccinated_per_hundred"
## [43] "people_fully_vaccinated_per_hundred"
## [44] "total_boosters_per_hundred"
## [45] "new_vaccinations_smoothed_per_million"
## [46] "new_people_vaccinated_smoothed"
## [47] "new_people_vaccinated_smoothed_per_hundred"
## [48] "stringency_index"
## [49] "population_density"
## [50] "median_age"
## [51] "aged_65_older"
## [52] "aged_70_older"
## [53] "gdp_per_capita"
## [54] "extreme_poverty"
## [55] "cardiovasc_death_rate"
## [56] "diabetes_prevalence"
## [57] "female_smokers"
## [58] "male_smokers"
## [59] "handwashing_facilities"
## [60] "hospital_beds_per_thousand"
## [61] "life_expectancy"
## [62] "human_development_index"
## [63] "population"
## [64] "excess_mortality_cumulative_absolute"
## [65] "excess_mortality_cumulative"
## [66] "excess_mortality"
## [67] "excess_mortality_cumulative_per_million"
## now filtering for US data
us_data <- owid.covid.data %>%
filter(location == "United States")
latest_date <- max(us_data$date, na.rm = TRUE)
total_cases_latest_date <- max(us_data$total_cases[us_data$date == latest_date], na.rm = TRUE)
print(paste("Total cases as of", latest_date, ":", total_cases_latest_date))
## [1] "Total cases as of 2024-06-16 : 103436829"
print(class(us_data$date))
## [1] "character"
us_data$date <- as.Date(us_data$date, format = "%Y-%m-%d")
print(class(us_data$date))
## [1] "Date"
weekly_data <- us_data %>%
mutate(week = floor_date(date, unit = "week")) %>% # Round down date to the nearest week
group_by(week) %>%
summarize(
weekly_deaths = sum(total_deaths, na.rm = TRUE),
weekly_hosp = sum(hosp_patients, na.rm = TRUE),
weekly_vaccinations = sum(total_vaccinations, na.rm = TRUE),
.groups = 'drop'
)
ggplot(weekly_data, aes(x = week))+
geom_line(aes(y = weekly_deaths, color = "deaths"))+
geom_line(aes(y = weekly_hosp, color = "Hospitalizations"))+
geom_line(aes(y = weekly_vaccinations, color = "Vaccinations"))+
scale_color_manual(values = c("Deaths" = "red", "Hopitalizations" = "blue", "Vaccinations" = "green"))+
labs(title = "Weekly COVID-19 Deaths, Hoispitalizations, and Vaccinations",
x = "Week",
y = "Count",
color = "Indicator")+
theme_minimal()
Note: Not a great vizualization going to explore through another vizualization
correlation_matrix <- cor(weekly_data[, c("weekly_deaths", "weekly_hosp", "weekly_vaccinations")], use = "complete.obs")
print(correlation_matrix)
## weekly_deaths weekly_hosp weekly_vaccinations
## weekly_deaths 1.0000000 -0.1301442 0.3935970
## weekly_hosp -0.1301442 1.0000000 0.1838125
## weekly_vaccinations 0.3935970 0.1838125 1.0000000
if (!require("corrplot")) {
install.packages("corrplot", repos = "http://cran.rstudio.com/")
}
## Loading required package: corrplot
## corrplot 0.92 loaded
library(corrplot)
corrplot(correlation_matrix, method = "circle", type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
## creating a summary statistic for the weekly data
summary_stats <- summary(weekly_data)
print(summary_stats)
## week weekly_deaths weekly_hosp weekly_vaccinations
## Min. :2020-01-05 Min. : 0 Min. : 0 Min. :0.000e+00
## 1st Qu.:2021-02-14 1st Qu.:3305561 1st Qu.: 72287 1st Qu.:0.000e+00
## Median :2022-03-27 Median :6780837 Median : 155686 Median :4.737e+08
## Mean :2022-03-27 Mean :5338367 Mean : 217561 Mean :1.778e+09
## 3rd Qu.:2023-05-07 3rd Qu.:7868441 3rd Qu.: 273292 3rd Qu.:3.965e+09
## Max. :2024-06-16 Max. :8322545 Max. :1057383 Max. :4.735e+09
Limitations of this dataset are that there are too many other variables that can factor into the results. With this dataset variables that could not be accounted for were: the scale of the pandemic at any given time, initial high death rates, pandemic waves, or distribution of the vaccine.
Discussion: The correlation between deaths and hospitalizations -0.1301442): There is a very weak negative correlation between deaths and hospitalizations which means that as one goes up the other goes down. Almost no correlation exist in this data set.
The correlation between vaccines and death (0.3935970):This is moderate positive correlation suggesting that as one goes up so does the other. This seems counter intuitive, as is common knowledge vaccines should cause the rate of death to decrease, but as discussed it does not account for many other variables such as initial high death rate, pandemic waves, accelerating vaccine efforts or both metrics increasing due to the scale of the pandemic.
The correlation between hospitalizations and vaccines (0.1838125):This represents a weak positive correlation where as vaccines increased so did hospitalizations. As stated above that could have included many other variables.
Correlation does not imply Causation: The relationships in these correlations does not mean that one caused the other. The data must be examined in context.
Causation vs. Correlation: It is crucial to note that correlation does not imply causation. The relationships indicated by these correlation coefficients do not mean that one variable causes changes in another. For instance, while vaccinations are designed to reduce the severity and frequency of illness, their correlation with deaths and hospitalizations can be influenced by various factors including timing, vaccine distribution, and pandemic waves.
Contextual Factors: Consider the context in which data was collected. High correlations during specific periods might coincide with particular events, such as the start of vaccination campaigns, public health policy changes, or variants of concern.
While we calculated some correlation between these factors, there were severe limitations to using this dataset for a correlation. More information would be needed to understand the context of these correlations. Further studies could include regression models, time series models or stratified studies to explore causation links.