Breakdown of the Final Project
# Load libs
library(tidyverse)
library(broom)
library(car)
library(MASS)
# Make alsis 'data' for the COVID dataset
data <- read.csv("../data/COVID_country.csv")
# head(data)
# summary(data)
glimpse to view the dataset:glimpse(data)
## Rows: 6,208
## Columns: 11
## $ country <chr> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanista…
## $ iso3 <chr> "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", …
## $ year <int> 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 20…
## $ sex <chr> "Female", "Female", "Female", "Female", "Female", "Femal…
## $ age_group <chr> "0-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75…
## $ pop <int> 12485568, 2734917, 1684126, 1141134, 699319, 379159, 137…
## $ type <chr> "predicted", "predicted", "predicted", "predicted", "pre…
## $ expected.mean <int> 49084, 6453, 6118, 7712, 10062, 13955, 12752, 3695, 6768…
## $ acm.mean <int> 49103, 6691, 6977, 9330, 12458, 17144, 14639, 4614, 6771…
## $ excess.mean. <int> 0, 237, 860, 1622, 2401, 3195, 1889, 922, 0, 249, 1280, …
## $ X <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
Breakdown of each Attribute:
country: CHAR vector representing the name of the
country.iso3: CHAR vector representing the ISO 3166-1-alpha-3
code of the country.year: INT vector representing the year of the
data.sex: CHAR vector representing the gender (Male or
Female).age_group: CHAR vector representing the age group.
These categories are grouped into ranges.pop: INT vector presenting the population.type: CHAR vector indicating the type of data
(“predicted” or not).expected.mean.: INT vector representing the expected
mean of COVID-19 cases.acm.mean: INT vector representing the actual mean.excess.mean.: INT vector representing the excess
mean.X: Logical vector with NA values.The COVID-19 country dataset includes 6,208 rows and 11 columns (only 10 will be used during the analysis). The dataset provides a detailed breakdown of COVID-19 related metrics based on demographic factors such as age, gender and population.
Let’s start with some basic descriptive stats to get a sense of the data we are working with. While I did do a breakdown of each attribute (including the data type and info collected in the attribute), it is still good to unveil certain trends or patterns.
# Descriptive Stats:
summary(data)
## country iso3 year sex
## Length:6208 Length:6208 Min. :2020 Length:6208
## Class :character Class :character 1st Qu.:2020 Class :character
## Mode :character Mode :character Median :2020 Mode :character
## Mean :2020
## 3rd Qu.:2021
## Max. :2021
## age_group pop type expected.mean
## Length:6208 Min. : 0 Length:6208 Min. : 0.0
## Class :character 1st Qu.: 35177 Class :character 1st Qu.: 370.8
## Mode :character Median : 267600 Mode :character Median : 2438.0
## Mean : 2520267 Mean : 17998.0
## 3rd Qu.: 1194828 3rd Qu.: 9056.5
## Max. :324033981 Max. :1578937.0
## acm.mean excess.mean. X
## Min. : 0 Min. :-100092.0 Mode:logical
## 1st Qu.: 411 1st Qu.: 0.0 NA's:6208
## Median : 2720 Median : 84.0
## Mean : 20403 Mean : 2394.2
## 3rd Qu.: 10440 3rd Qu.: 799.2
## Max. :1733563 Max. : 588931.0
Findings From the Summary():
Population Distribution:
The minimal population is 0, indicating that data is absent or incomplete.
The greatest population is 324,033,981, demonstrating that the nations in the dataset have a broad variety of population sizes.
Expected Mean Distribution:
COVID-19 cases are estimated to range from 0 to 1,578,937, with a mean of 17,998.
The distribution is biased to the right, indicating that most nations have significantly lower predicted means.
Actual Mean (acm) Mean Distribution:
The ACM mean varies between 0 and 1,733,563, with a mean of 20,403.
The distribution is right-skewed, as predicted, showing that most nations have lower ACM means.
Excess Mean Distribution:
With a mean of 2,394.2, the excess mean ranges from -100,092 to 588,931.
The distribution demonstrates variability, and negative values indicate occasions when the observed mean is less than the projected mean.
Temporal Trends:
The data spans the years 2020 and 2021, with no major differences observed in the summary statistics.
Further investigation may be required to investigate temporal patterns in greater depth.
Sex and Age Group Distribution:
The collection provides information on both male and female populations of various ages.
Age categories are divided into ranges (for example, “0-24”, “25-34”) to provide a demographic breakdown.
Visual 1: Distribution of COVID-19 Cases:
# I'm going to plot the distribution of the expected mean.
ggplot(data = data, aes(x = expected.mean))+
geom_histogram(binwidth = 5000, fill = "blue", color = "black")+
labs(title = "Distribution of Expected Mean Covid-19 Cases",
x = "Expected Mean",
y = "Frequency")
The histogram above provides an overview of the distribution of expected mean COVID-19 cases.
Using a correlation analysis, I hope to investigate the connections between the various variables in this dataset. I’ll make the following graphic to show the correlations:
Correlation Analysis:
# First, I'm going to set up my correlation matrix and set teh relevant attributes:
correlation_matrix <- cor(data[, c("pop", "expected.mean", "acm.mean", "excess.mean." )])
correlation_matrix
## pop expected.mean acm.mean excess.mean.
## pop 1.0000000 0.4288725 0.4091939 0.1369463
## expected.mean 0.4288725 1.0000000 0.9854867 0.4801834
## acm.mean 0.4091939 0.9854867 1.0000000 0.6220689
## excess.mean. 0.1369463 0.4801834 0.6220689 1.0000000
Findings from the Correlation Matrix:
CC is short for ‘correlation coefficient’
pop and expected.mean:
CC: 0.4289.
The population and the predicted mean have a somewhat positive association (0.43). This implies that nations with higher population densities typically have higher expected means.
expected.mean and acm.mean:
CC: 0.9855.
A robust positive correlation (r = 0.99) exists between the actual mean and the expected mean. The nearly perfect correlation between these two variables suggests that the actual mean is a reliable predictor of the expected mean.
pop and acm.mean:
CC: 0.4092.
The population and actual mean have a somewhat favorable association (0.41). This suggests that, while the association between actual mean and expected mean is stronger, nations with bigger populations may have higher actual means.
excess.mean and other Attributes:
In comparison, the excess mean’s correlation coefficients with the other variables are lower.
The excess mean shows a somewhat larger positive correlation (0.62) with the actual mean and a somewhat positive correlation (0.48) with the anticipated mean.
These findings suggest that there is only a little link between population size and actual and expected means. Furthermore, the dataset shows a strong positive correlation between the anticipated and actual means, indicating a close relationship between them. The correlation matrix provides a foundation for understanding how diverse aspects interact and guides further study and interpretation.
Visual for Correlation Matrix:
# heatmap
heatmap(correlation_matrix,
col = colorRampPalette(c("blue","white","red"))(20),
main = "Correlation Heatmap",
margins = c(12, 9),
cex.main = 1.2)
Since assessing the validity of specific assumptions about the {pop} through hypothesis testing is an essential step in statistical analysis. Based on the COVID-19 dataset examples, I will develop (build on Week 7 - data dive) and test two distinct hypotheses.
H0: There is no significant difference in the expected mean between the two sexes (Male and Female).
H1: There is significant difference in the expected mean between the two sexes.
In order to test this hypothesis, I will perform a t-test for independ samples between the expected.mean for males and females.
# subset the data into the groups (male or female)
data_male <- data[data$sex == "Male", ]
data_female <- data[data$sex == "Female", ]
# Perform t-test
t_test_gender <- t.test(data_male$expected.mean, data_female$expected.mean)
# print
t_test_gender
##
## Welch Two Sample t-test
##
## data: data_male$expected.mean and data_female$expected.mean
## t = 1.4018, df = 6059.8, p-value = 0.161
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1151.887 6934.141
## sample estimates:
## mean of x mean of y
## 19443.60 16552.47
Discovery:
It is evident that the purpose of the Welch Two Sample t-test was to see if there is a statistically significant difference in the predicted mean between the genders. These are the results:
Findings:
P-value: The p-value is higher than the usually accepted significance level of 0.05, at 0.161. Therefore, there is insufficient data to rule out the null hypothesis.
The 95% confidence interval (CI) for the mean difference spans from -1151.887 to 6934.141. This suggests that it is not very important.
Visual:
boxplot(expected.mean ~ sex, data = data, col = c("blue", "pink"), main = "Expected Mean by Sex", ylab = "Expected Mean")
H0: There is no association between age groups and excess mean.
H1: There is a significant association between age groups and the excess mean.
In order to test this hypothesis, I will use a chi-square test to evaluate the independence between age group and excess mean..
# Create a contingency table
cont_table <- table(data$age_group, data$excess.mean.)
# Perform a chi-square test
chi_sq_test <- chisq.test(cont_table)
## Warning in chisq.test(cont_table): Chi-squared approximation may be incorrect
# print
chi_sq_test
##
## Pearson's Chi-squared test
##
## data: cont_table
## X-squared = 19649, df = 17542, p-value < 2.2e-16
Discovery:
Findings:
P-value: There is substantial evidence to reject the null hypothesis when the p-value is significantly less than 0.05. Therefore, there is a strong correlation between the variables “age_group” and “sex”.
Visual:
# Take the contingency table and transform it into a data frame.
cont_df <- as.data.frame(as.table(cont_table))
# Using ggplot2, make the mosaic plot:
ggplot(cont_df, aes(x = Var2, y = Freq, fill = Var1))+
geom_bar(stat="identity", position = "stack")+
labs(title = "Association Between Sex and Age Group",
x = "Age Group",
y = "Frequency")+
scale_fill_manual(values = c("Male" = "blue", "Female" = "pink"))+
theme_minimal()
Descriptive Statistics unveiled a diverse range in population sizes, expected mean, and the actual mean across the countries.
Correlation analysis highlighted strong positive associations, notably between expected mean and actual mean.
Hypothesis testing revealed no significant gender-based (Male or Female) differences in expected mean but established a substantial association between age groups and excess mean.
In conclusion, my data analysis expedition successfully navigated the treacherous terrain of COVID-19 measurements, showing patterns, correlations, and variations among demographic factors. The findings open the path for future study while also expanding our sophisticated understanding of the dataset. Prospective study approaches include looking at temporal trends, looking into variables that influence excess mean, and developing prediction models. This work provides critical insights for developing public health policies and directing future research, making it an important cornerstone in the ongoing discourse at the intersection of infectious diseases and demography.