Breakdown of the Data - Dive:

Set-up:

# Load the tidyerse lib
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.2.1     ✔ dplyr   1.1.1
## ✔ tidyr   1.2.0     ✔ stringr 1.4.0
## ✔ readr   2.1.2     ✔ forcats 0.5.1
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
# Load the ggplot2 lib for visuals :D 
library(ggplot2)
# Include dplyr for Part 2.
library(dplyr)

# use read_delim to grab the COVID_country, data.
COVID = read_delim("../data/COVID_country.csv",delim = ",")
## New names:
## • `` -> `...11`
## Rows: 6208 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): country, iso3, sex, age_group, type
## dbl (5): year, pop, expected.mean, acm.mean, excess.mean*
## lgl (1): ...11
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# run a quick 'summary()' to verify we are reading the dataset correctly. 
summary(COVID)
##    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*        ...11        
##  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
str(COVID$age_group)
##  chr [1:6208] "0-24" "25-34" "35-44" "45-54" "55-64" "65-74" "75-84" ">85" ...
str(COVID$sex)
##  chr [1:6208] "Female" "Female" "Female" "Female" "Female" "Female" ...

Part 1: Gender, Age and Country ‘Group By’ Investigations:

The 3 Groups:

Procedure:

  1. Calculate expected probability within each group
  2. Identify and tag anomalies based on the lowest expected probability
  3. Merge the anomaly tags back into the original data frame
  4. Discovery and Results.

Testable Hypothesis:

A statistical hypothesis test to assess the mean increased mortality between males and females is one hypothesis I’m considering looking into. Although I did not conduct a t-test or other non-parametric test to ascertain this, I did make hints to the various categories below as possibly supporting data for my hypothesis. Tell me what you think about this being a possible idea that I look into.

Group 1: Gender-Based

# Group 1 => Gender-Based
group1 <- COVID %>%
  group_by(sex) %>%
  summarize(
    Mean_Population = mean(pop),
    Mean_Excess = mean(`excess.mean*`)
  ) %>%
  mutate(Expected_Prob = Mean_Population / sum(Mean_Population)) %>%
  mutate(Anomaly_Tag = ifelse(Expected_Prob == min(Expected_Prob), "Anomaly", "Normal"))
print(group1)
## # A tibble: 2 × 5
##   sex    Mean_Population Mean_Excess Expected_Prob Anomaly_Tag
##   <chr>            <dbl>       <dbl>         <dbl> <chr>      
## 1 Female        2504809.       2130.         0.497 Anomaly    
## 2 Male          2535726.       2659.         0.503 Normal

Insights:

  • The “Male” group is classified as normal, but the “Female” group is marked as an anomaly. This shows that, in comparison to the male group, the female group deviates significantly from the expected pattern based on the estimated expected probabilities.
  • Despite the fact that the average population of females is slightly lower than that of males, as indicated by the “Mean_Population” characteristic, this disparity is insufficient to account for the anomaly tag.
  • Indicating that, on average, females experience less excess mortality than males, the “Mean_Excess” attribute shows that the average excess mean for females is significantly lower than for males.

Significance:

The finding of anomalies, in particular the lower excess mean in the female group, is what is significant. This shows that generally speaking, female excess mortality has been lower during the period in question.

Questions-Sparked!

  • Why is the Female Group an Anomaly?
  • What are the potential factors behind the lower excess mean mortality in females?
  • Are there gender-specific health behaviors, healthcare access, or other variables that explain this difference?

Visuals!

bar-chart:

# create a bar chart
ggplot(group1, aes(x=sex, y = Mean_Excess, fill=sex))+
  geom_bar(stat="identity", position="dodge")+
  labs(x="Gender", y="Excess Mean Mortality", title = "Gender-Based Excess Mean Mortality")

Pie Chart:

# Pie-chart for Gender-Based (group1)
ggplot(group1, aes(x="", y=Expected_Prob, fill = sex))+
  geom_bar(stat="identity", width = 1)+
  coord_polar(theta = "y")+
  labs(x = NULL, y = NULL, fill="Gender")+
  theme_void()+
  ggtitle("Gender-Based Expected Probabilities")

Group 2: Age-Based

# Group 2 => Age-Based
group2 <- COVID %>%
  group_by(age_group) %>%
  summarize(
    Mean_Population = mean(pop),
    Mean_Excess = mean(`excess.mean*`)
  ) %>%
  mutate(Expected_Prob = Mean_Population / sum(Mean_Population)) %>%
  mutate(Anomaly_Tag = ifelse(Expected_Prob == min(Expected_Prob), "Anomaly", "Normal"))
print(group2)
## # A tibble: 8 × 5
##   age_group Mean_Population Mean_Excess Expected_Prob Anomaly_Tag
##   <chr>               <dbl>       <dbl>         <dbl> <chr>      
## 1 0-24             8302765.       -30.1       0.412   Normal     
## 2 25-34            3075741.       105.        0.153   Normal     
## 3 35-44            2689074.       844.        0.133   Normal     
## 4 45-54            2363641.      2149.        0.117   Normal     
## 5 55-64            1828228.      3810.        0.0907  Normal     
## 6 65-74            1200196.      5096.        0.0595  Normal     
## 7 75-84             543952.      3689.        0.0270  Normal     
## 8 >85               158540.      3491.        0.00786 Anomaly

Insights:

  • The age group “>85” is tagged as an anomaly, while all other age groups are labeled as normal.
  • The average population for each age group is displayed in the “Mean_Population” attribute, and it differs dramatically between age groups. The lowest average population is found in the age bracket “>85”.
  • The average excess mean for each age group is shown in the “Mean_Excess” column. The “>85” age group stands out for having the second-highest average excess mean, which denotes higher excess mortality.

Significance:

Due to its unusually large excess mortality as compared to other groups, the “>85” age group was identified as an outlier, which is where the relevance resides. This raises the possibility of a health differential caused by age.

Questions-Sparked!

  • Why is the “>85” Age Group an Anomaly?
  • Does the “>85” age group anomaly reflect specific health concerns, access to healthcare, or environmental factors?
  • What is the standard of living in the “>85” age group? Look into elements including social support, housing, and mental health.

Visuals!

Bar-Chart:

# create bar chart for Age-Based (group2)
ggplot(group2, aes(x=age_group, y = Mean_Excess, fill = age_group))+
  geom_bar(stat="identity")+
  labs(x="Age Group", y = "Excess Mean Mortality", title = "Age-Based Excess Mean Mortality")

Grouped Dot Plot:

# create a grouped dot plot for age-based (group2)
ggplot(group2, aes(x = age_group, y = Mean_Population))+
  geom_point(position = position_dodge(width = 0.5), size = 3, shape = 21, color = "orange", fill = "orange") +
  labs(x = "Age Group", y = "Mean Population", title = "Age-Based Grouped Dot Plot")+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Group 3: Country-Based

# Group 3 => Country-Based
group3 <- COVID %>%
  group_by(country) %>%
  summarize(
    Total_Population = sum(pop),
    Mean_Excess = mean(`excess.mean*`)
  ) %>%
  # Note: different way to calculate the Expected Prob since, dividing the total_population / sum(total_population) = 1. 
  mutate(Expected_Prob = (Total_Population - min(Total_Population)) / (max(Total_Population) - min(Total_Population))
 ) %>%
  mutate(Anomaly_Tag = ifelse(Expected_Prob == min(Expected_Prob), "Anomaly", "Normal"))
print(group3)
## # A tibble: 194 × 5
##    country             Total_Population Mean_Excess Expected_Prob Anomaly_Tag
##    <chr>                          <dbl>       <dbl>         <dbl> <chr>      
##  1 Afghanistan                 79068023     2054.       0.0278    Normal     
##  2 Albania                      5716076      472.       0.00201   Normal     
##  3 Algeria                     87605741     2426        0.0308    Normal     
##  4 Andorra                       156489        8.22     0.0000536 Normal     
##  5 Angola                      67928023      344.       0.0238    Normal     
##  6 Antigua and Barbuda           185750       -2.09     0.0000638 Normal     
##  7 Argentina                   90211253     3958.       0.0317    Normal     
##  8 Armenia                      5590980      625.       0.00196   Normal     
##  9 Australia                   51502034       43.9      0.0181    Normal     
## 10 Austria                     17791185      499.       0.00624   Normal     
## # ℹ 184 more rows

Insights:

  • “Niue” is tagged as an anomaly.
  • “Niue” has a small total population of 3,884 people!
  • There was no excess mortality detected between 2020 and 2021, as indicated by the “Mean_Excess” value provided for “Niue” being 0.00.
  • The population of “Niue” is incredibly small in comparison to the total population of all countries, as indicated by the “Expected_Prob” value of 0.000000e+00, which equals an expected probability of zero. This might imply that the value for “Niue” in this data set is an outlier.

Significance:

The discovery of “Niue” as an anomaly because of its incredibly low anticipated frequency and lack of excess mortality is what makes this finding significant. Overall, the data set’s “Niue” case stands out as a singular instance.

Questions-Sparked!

  • How trustworthy are the data for “Niue”? If there was a problem with the quality of the data that was given, this could explain the anomaly.
  • See why “Niue” has such a distinctive status by looking at the demographic characteristics, healthcare infrastructure, and external influences.

Visuals!

Bar-Chart:

ggplot(group3, aes(x = country, y = Total_Population, fill = Anomaly_Tag))+
  geom_bar(stat="identity", position="dodge")+
  labs(x = "Country", y = "Total Population", title = "Country-Based Grouped Bar Chart")+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  scale_fill_manual(values = c("Normal" = "lightblue", "Anomaly" = "orange"))

Scatter Plot:

# create a scatter-plot for Country-Based (group3)
ggplot(group3, aes(x = Total_Population, y = Mean_Excess, color = Anomaly_Tag))+
  geom_point(size = 3)+
  labs(x = "Total Population", y = "Excess Mean Mortality", title = "Country-Based Scatter Plot")+
  scale_color_manual(values = c("Normal" = "lightblue", "Anomaly" = "orange"))+
  guides(color = guide_legend(title = "Anomaly Tag"))

Take note that “Niue” is not even visible in this depiction! Given that it is buried behind the points at (0, 0).

Part 2: Age Group and Sex Combinations, Huh?

I’m going to look into the categorical variables “age_group” and “sex” and identify all potential combinations for them. I shall then respond to or address the following claims:

  • Which combinations never show up? Why might that be?
  • Which combinations are the most/least common, and why might that be?
  • Try to find a way to visualize these combinations.
# Find all combinations of age_group and sex
combo_cnts <- COVID %>%
  group_by(age_group,sex, .drop = TRUE) %>%
  summarise(Count = n())
## `summarise()` has grouped output by 'age_group'. You can override using the
## `.groups` argument.
# combo_cnts

all_combos_df <- data.frame(
  age_group = rep(COVID$age_group, length(COVID$sex)),
  sex = rep(COVID$sex, each = length(COVID$age_group))
)
# all_combos_df

# Identify the combo's that never show up. 
mia_combos <- anti_join(all_combos_df, combo_cnts, by = c("age_group", "sex"))
# Find the most common combos
most_combos <- combo_cnts %>%
  arrange(desc(Count)) %>%
  head()

least_combos <- combo_cnts %>%
  arrange(Count) %>%
  head()

print("Combinations that never show up: ")
## [1] "Combinations that never show up: "
print(mia_combos)
## [1] age_group sex      
## <0 rows> (or 0-length row.names)
print("Most common combinations: ")
## [1] "Most common combinations: "
print(most_combos)
## # A tibble: 6 × 3
## # Groups:   age_group [3]
##   age_group sex    Count
##   <chr>     <chr>  <int>
## 1 0-24      Female   388
## 2 0-24      Male     388
## 3 25-34     Female   388
## 4 25-34     Male     388
## 5 35-44     Female   388
## 6 35-44     Male     388
print("Least common Combinations: ")
## [1] "Least common Combinations: "
print(least_combos)
## # A tibble: 6 × 3
## # Groups:   age_group [3]
##   age_group sex    Count
##   <chr>     <chr>  <int>
## 1 0-24      Female   388
## 2 0-24      Male     388
## 3 25-34     Female   388
## 4 25-34     Male     388
## 5 35-44     Female   388
## 6 35-44     Male     388

Insights:

Which combinations never show up? Why might that be?

  • There are no ‘combinations that never show up’ in my situation. This question is not relevant because all groups have an equal distribution of combinations. How could this be? Later on, this question is ‘answered’.

Which combinations are the most/least common, and why might that be?

  • The most frequent and least frequent combinations are same, as can be seen! I really opened Excel and performed COUNTIFS() procedures for each group to determine the combinations in order to validate this.

Other Insights:

  • Due to the equal amount of records for each ‘age_group’ and ’ sex’ combination, my dataset is balanced. A balanced dataset can make certain analyses and modeling easier because it removes any potential bias.

  • The fact that there are equal counts for each combination suggests that the sampling procedure was conducted evenly and without bias. Once more, this can increase the generalizability of my dataset.

Concerns:

  • If all of the numbers are equal, the data may be “synthetic,” “artificial,” or simulated, synthetic in nature, or intentionally manufactured. This is bad because, if the data has been generated, it does not accurately represent distributions in the real world. I would need to look into how the WHO recorded and published the data more thoroughly.
  • The equal counts can point to some restrictions. For instance, a perfectly balanced dataset might not adequately reflect the true distribution of age groups and sexes in the population if my dataset is meant to represent the real-world population.

Let’s try graphing the combos!

# Let's just make a simple bar chart:
ggplot(combo_cnts, aes(x = age_group, y = Count, fill = sex))+
  geom_bar(stat ="identity", position="stack")+
  theme_dark()+
  labs(x = "Age Groups", y = "Frequency (Cnt)", fill = "Sex", title = "Combination Cnts by Age Group and Sex")

Well… As we can see from the graph… not very exciting, LOL!

End of Data-Dive Week 3 - Probabilities and Anomalies