Breakdown of the Data - Dive:

Set-up:

# Load the typical libs
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse) 
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.2.1     ✔ stringr 1.4.0
## ✔ tidyr   1.2.0     ✔ forcats 0.5.1
## ✔ readr   2.1.2
## Warning: package 'tibble' was built under R version 4.2.3
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggplot2) 

# For this data dive we are adding the stats library
library(stats)

Init the link to the dataset:

# Re-instance the COVID data set: 
COVID = read_delim("../data/COVID_country.csv",delim = ",")
## New names:
## 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.
## • `` -> `...11`
# Alias the COVID data set name :D 
data <- COVID 
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*        ...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

Part 1: ANOVA Test

Response Variable:

Explanatory Variable:

Null Hypothesis: There is no significant difference in the excess mean among different sexes.

# Perform an ANOVA Test
anova_test_result <- aov(`excess.mean*` ~ `sex`, data = data)

# Summarize ANOVA results:
summary(anova_test_result)
##               Df    Sum Sq   Mean Sq F value Pr(>F)
## sex            1 4.339e+08 433914458   1.382   0.24
## Residuals   6206 1.949e+12 313976475

Findings:

Here is a breakdown of the results:

Insight:

The F-value compares the variance of the sex categories to the variance of the residual groupings. The F-value in this example is 1.382, and the accompanying p-value of 0.24 is more than the conventional significance threshold of 0.05. This means that there is insufficient data to establish that there is a substantial difference in excess mean between the sexes.

Significance:

The results indicate that the sex attribute has no effect on the excess.mean. Based on this study, it is reasonable to say that sex has no significant influence on the excess mean, as noted in the insight portion of this breakdown.

Further Questions:

Part 2: Linear Regression Model

The pop attribute, or population, might be a continuous variable that influences the excess mean.The pop and excess.mean* attributes should have an approximately linear relationship.

Null Hypothesis: There is no linear relationship between pop and excess.mean*.

# Build a linear regression model:
model <- lm(`excess.mean*` ~ `pop`, data = data)

# Evaluate the model:
summary(model)
## 
## Call:
## lm(formula = `excess.mean*` ~ pop, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -106152   -1974   -1886   -1253  580870 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.910e+03  2.272e+02   8.406   <2e-16 ***
## pop         1.922e-04  1.764e-05  10.891   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17550 on 6206 degrees of freedom
## Multiple R-squared:  0.01875,    Adjusted R-squared:  0.0186 
## F-statistic: 118.6 on 1 and 6206 DF,  p-value: < 2.2e-16

Plot the Model:

plot(model)

Findings:

Here is a breakdown of the results:

Insight:

Because the R-square is just 0.01875, the linear regression model explains a very little percentage of the variance in excess.mean. The coefficient for pop suggests that a one-unit increase in pop is predicted to raise excess.mean by 1.922e-04, although this effect is rather insignificant.

Significance:

The p-value for the pop attribute is 2.2e-16, showing that there is a statistically significant link between pop and excess.mean. This link, however, has little practical value.

Further Questions:

Part 3: Include Additional Variables

Include at least on other variable into the model. I’m going to choose the sex attribute from the ANOVA test earlier.

# Include additional vars
model_plus <- lm(`excess.mean*` ~ `pop` + `sex`, data = data)

# Eval the model:
summary(model_plus)
## 
## Call:
## lm(formula = `excess.mean*` ~ pop + sex, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -106413   -2171   -1679   -1232  580609 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.649e+03  3.182e+02   5.181 2.27e-07 ***
## pop         1.921e-04  1.764e-05  10.890  < 2e-16 ***
## sexMale     5.228e+02  4.456e+02   1.173    0.241    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17550 on 6205 degrees of freedom
## Multiple R-squared:  0.01897,    Adjusted R-squared:  0.01866 
## F-statistic:    60 on 2 and 6205 DF,  p-value: < 2.2e-16

Findings:

Here is a breakdown of the results:

Insight:

With an R-squared of 0.01897, the model’s explanatory power remains poor. Adding sex as a variable did not enhance the model’s performance appreciably.

Significance:

The p-value for pop is still extremely significant, but the p-value for sexMale is 0.241, which indicates that it is not statistically significant.

Further Questions:

Just for Fun, Let’s see the plot with additional vars!

plot(model_plus)

Conclusion:

While statistical significance was found, the practical importance of the correlations between factors and excess.mean is limited. additional research may be required to uncover additional significant predictors or interactions that can better explain the changes in excess.mean as described in the various tasks.