|
@@ -35,15 +35,14 @@ glimpse(covid_df)
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
-The dataset contains `13` columns and `10,903` rows. This database provides information on the numbers (per day and cumulatively) of COVID19 positive cases, deaths, tests performed and hospitalizations for each country through the column's names store in the variable `vector_cols`.
|
|
|
|
|
|
+The dataset contains `14` columns and `10,903` rows. This database provides information on the numbers (per day and cumulatively) of COVID-19 positive cases, deaths, tests performed and hospitalizations for each country through the column's names store in the variable `vector_cols`.
|
|
|
|
|
|
1. This variable contains a character vector.
|
|
1. This variable contains a character vector.
|
|
|
|
|
|
2. The use of the function `glimpse()` is the very first operation to do because we don't only learn about the dimensions of the database but also about the names of the first columns and their types and content. It can replace the three previous operations: `dim()`, `colnames()`, and `head()`.
|
|
2. The use of the function `glimpse()` is the very first operation to do because we don't only learn about the dimensions of the database but also about the names of the first columns and their types and content. It can replace the three previous operations: `dim()`, `colnames()`, and `head()`.
|
|
|
|
|
|
-# Isolating the Data We Need
|
|
|
|
-
|
|
|
|
-## Selecting only the rows related to `"All States"` and removing the `Province_State`.
|
|
|
|
|
|
+# Isolating the Rows We Need
|
|
|
|
+- Selecting only the rows related to `"All States"` and removing the `Province_State`.
|
|
|
|
|
|
```{r}
|
|
```{r}
|
|
library(dplyr)
|
|
library(dplyr)
|
|
@@ -55,8 +54,10 @@ covid_df_all_states <- covid_df %>%
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
|
+- We can remove `Province_State` without loosing information because after the filtering step this column only contains the value `"All States"`.
|
|
|
|
|
|
-## Creating a dataset for the cumulative columns and another for the daily columns from `covid_df_all_states` dataframe
|
|
|
|
|
|
+# Isolating the Columns We Need
|
|
|
|
+- Creating a dataset for the daily columns from `covid_df_all_states` dataframe
|
|
|
|
|
|
Let's recall the description of the dataset's columns.
|
|
Let's recall the description of the dataset's columns.
|
|
|
|
|
|
@@ -77,54 +78,17 @@ Let's recall the description of the dataset's columns.
|
|
|
|
|
|
|
|
|
|
```{r}
|
|
```{r}
|
|
-
|
|
|
|
-# Selecting the columns with cumulative numbers
|
|
|
|
-covid_df_all_states_cum <- covid_df_all_states %>%
|
|
|
|
- select(Date, Continent_Name, Two_Letter_Country_Code, positive, hospitalized, recovered, death, total_tested)
|
|
|
|
-
|
|
|
|
# Selecting the columns with cumulative numbers
|
|
# Selecting the columns with cumulative numbers
|
|
covid_df_all_states_daily <- covid_df_all_states %>%
|
|
covid_df_all_states_daily <- covid_df_all_states %>%
|
|
select(Date, Country_Region, active, hospitalizedCurr, daily_tested, daily_positive)
|
|
select(Date, Country_Region, active, hospitalizedCurr, daily_tested, daily_positive)
|
|
|
|
|
|
-##print(xtable::xtable(head(covid_df_all_states_daily)), type = "html")
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-1. We can remove `Province_State` without loosing information because after the filtering step this column only contains the value `"All States"`.
|
|
|
|
-
|
|
|
|
-# Identifying the Highest Fatality Rates Countries
|
|
|
|
-
|
|
|
|
-## Summarizing the data based on the `Continent_Name` and `Two_Letter_Country_Code` columns.
|
|
|
|
-```{r}
|
|
|
|
-covid_df_all_states_cum_max <- covid_df_all_states_cum %>%
|
|
|
|
- group_by(Continent_Name, Two_Letter_Country_Code) %>%
|
|
|
|
- summarise(max = max(death)) %>%
|
|
|
|
- filter(max > 0)
|
|
|
|
-
|
|
|
|
-covid_df_all_states_cum_max
|
|
|
|
-
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-## Displaying the maximum number of death by country, colored by continent
|
|
|
|
-
|
|
|
|
-```{r}
|
|
|
|
-library(ggplot2)
|
|
|
|
-
|
|
|
|
-qplot(x = Two_Letter_Country_Code,
|
|
|
|
- y = max,
|
|
|
|
- col = Continent_Name,
|
|
|
|
- data = covid_df_all_states_cum_max)
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-## Conclusion: Answering the question: Which countries have had the highest fatality (mortality) rates?
|
|
|
|
-```{r}
|
|
|
|
-death_top_3 <- c("US", "IT", "GB")
|
|
|
|
|
|
+head(covid_df_all_states_daily)
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
# Extracting the Top Ten countries in the number of tested cases
|
|
# Extracting the Top Ten countries in the number of tested cases
|
|
|
|
|
|
-## Summarizing the data based on the `Continent_Name` column.
|
|
|
|
|
|
+## Summarizing the data based on the `Country_Region` column.
|
|
```{r}
|
|
```{r}
|
|
covid_df_all_states_daily_sum <- covid_df_all_states_daily %>%
|
|
covid_df_all_states_daily_sum <- covid_df_all_states_daily %>%
|
|
group_by(Country_Region) %>%
|
|
group_by(Country_Region) %>%
|
|
@@ -143,7 +107,7 @@ covid_df_all_states_daily_sum
|
|
```{r}
|
|
```{r}
|
|
covid_top_10 <- head(covid_df_all_states_daily_sum, 10)
|
|
covid_top_10 <- head(covid_df_all_states_daily_sum, 10)
|
|
|
|
|
|
-#print(xtable::xtable(covid_top_10), type = "html")
|
|
|
|
|
|
+covid_top_10
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
@@ -185,80 +149,44 @@ positive_tested_top_3 <- c("United Kingdom" = 0.11, "United States" = 0.10, "Tur
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
-# Identifying Affected Countries Related to their Population
|
|
|
|
|
|
+# Keeping relevant information
|
|
|
|
|
|
```{r}
|
|
```{r}
|
|
-# Creating the matrix covid_mat
|
|
|
|
-covid_mat <- cbind(tested_cases, positive_cases, active_cases, hospitalized_cases)
|
|
|
|
|
|
+# Creating vectors
|
|
|
|
+united_kingdom <- c(0.11, 1473672, 166909, 0, 0)
|
|
|
|
+united_states <- c(0.10, 17282363, 1877179, 0, 0)
|
|
|
|
+turkey <- c(0.08, 2031192, 163941, 2980960, 0)
|
|
|
|
|
|
-# Creating the population vector https://www.worldometers.info/world-population/population-by-country/
|
|
|
|
-population <- c(331002651, 145934462, 60461826, 1380004385, 84339067, 37742154, 67886011, 25499884, 32971854, 37846611)
|
|
|
|
|
|
+# Creating the matrix covid_mat
|
|
|
|
+covid_mat <- rbind(united_kingdom, united_states, turkey)
|
|
|
|
|
|
-# Dividing the matrix by the population vector
|
|
|
|
-covid_mat <- covid_mat * 100/population
|
|
|
|
|
|
+# Naming columns
|
|
|
|
+colnames(covid_mat) <- c("Ratio", "tested", "positive", "active", "hospitalized")
|
|
|
|
|
|
|
|
+#d Displaying the matrix
|
|
covid_mat
|
|
covid_mat
|
|
```
|
|
```
|
|
|
|
|
|
-## Ranking the matrix
|
|
|
|
-
|
|
|
|
-```{r}
|
|
|
|
-tested_cases_rank <- rank(covid_mat[,"tested_cases"])
|
|
|
|
-positive_cases_rank <- rank(covid_mat[,"positive_cases"])
|
|
|
|
-active_cases_rank <- rank(covid_mat[,"active_cases"])
|
|
|
|
-hospitalized_cases_rank <- rank(covid_mat[,"hospitalized_cases"])
|
|
|
|
-
|
|
|
|
-covid_mat_rank <- rbind(tested_cases_rank, positive_cases_rank, active_cases_rank, hospitalized_cases_rank)
|
|
|
|
-
|
|
|
|
-covid_mat_rank
|
|
|
|
-
|
|
|
|
-covid_mat_rank[1,]
|
|
|
|
-
|
|
|
|
-covid_mat_rank[-1, ]
|
|
|
|
-
|
|
|
|
-colSums(covid_mat_rank[-1, ])
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-## Conclusion
|
|
|
|
-```{r}
|
|
|
|
-best_effort_tested_cased_top_3 <- c("India", "United Kingdom", "Turkey")
|
|
|
|
-
|
|
|
|
-most_affected_country <- "Italy"
|
|
|
|
-
|
|
|
|
-least_affected_country <- "India"
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
# Putting all together
|
|
# Putting all together
|
|
```{r}
|
|
```{r}
|
|
|
|
|
|
-question_list <- list(
|
|
|
|
- "Which countries have had the highest fatality (mortality) rates?",
|
|
|
|
- "Which countries have had the highest number of positive cases against the number of tests?",
|
|
|
|
- "Which countries have made the best effort in terms of the number of tests conducted related to their population?",
|
|
|
|
- "Which countries were ultimately the most and least affected related to their population?"
|
|
|
|
-)
|
|
|
|
|
|
+question <- "Which countries have had the highest number of positive cases against the number of tests?"
|
|
|
|
|
|
-answer_list <- list(
|
|
|
|
- "Death" = death_top_3,
|
|
|
|
- "Positive tested cases" = positive_tested_top_3,
|
|
|
|
- "The Best effort in test related to the population" = best_effort_tested_cased_top_3,
|
|
|
|
- "The most affected country related to its population" = most_affected_country,
|
|
|
|
- "The least affected country related to its population" = least_affected_country
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-answer_list
|
|
|
|
|
|
+answer <- c("Positive tested cases" = positive_tested_top_3)
|
|
|
|
|
|
datasets <- list(
|
|
datasets <- list(
|
|
original = covid_df,
|
|
original = covid_df,
|
|
allstates = covid_df_all_states,
|
|
allstates = covid_df_all_states,
|
|
- cumulative = covid_df_all_states_cum,
|
|
|
|
- daily = covid_df_all_states_daily
|
|
|
|
|
|
+ daily = covid_df_all_states_daily,
|
|
|
|
+ top_10 = covid_top_10
|
|
)
|
|
)
|
|
-matrices <- list(covid_mat, covid_mat_rank)
|
|
|
|
-vectors <- list(vector_cols, population, countries)
|
|
|
|
|
|
|
|
-data_structure_list <- list("data frame" = datasets, "matrix" = matrices, "vector" = vectors)
|
|
|
|
|
|
+matrices <- list(covid_mat)
|
|
|
|
+vectors <- list(vector_cols, countries)
|
|
|
|
+
|
|
|
|
+data_structure_list <- list("dataframe" = datasets, "matrix" = matrices, "vector" = vectors)
|
|
|
|
|
|
-covid_analysis_list <- list(question_list, answer_list, data_structure_list)
|
|
|
|
|
|
+covid_analysis_list <- list(question, answer, data_structure_list)
|
|
|
|
|
|
|
|
+covid_analysis_list[[2]]
|
|
```
|
|
```
|