Breakdown of the Data - Dive:

Part 1: Data Loading and Prep

# 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)
##       country iso3 year    sex age_group      pop      type expected.mean
## 1 Afghanistan  AFG 2020 Female      0-24 12485568 predicted         49084
## 2 Afghanistan  AFG 2020 Female     25-34  2734917 predicted          6453
## 3 Afghanistan  AFG 2020 Female     35-44  1684126 predicted          6118
## 4 Afghanistan  AFG 2020 Female     45-54  1141134 predicted          7712
## 5 Afghanistan  AFG 2020 Female     55-64   699319 predicted         10062
## 6 Afghanistan  AFG 2020 Female     65-74   379159 predicted         13955
##   acm.mean excess.mean.  X
## 1    49103            0 NA
## 2     6691          237 NA
## 3     6977          860 NA
## 4     9330         1622 NA
## 5    12458         2401 NA
## 6    17144         3195 NA
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

Part 2: Model Selection and Creation

# Building the linear model 
model <- lm(expected.mean ~ year + pop + acm.mean + `excess.mean.`, data = data)

# View coefficients
summary(model)
## 
## Call:
## lm(formula = expected.mean ~ year + pop + acm.mean + excess.mean., 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12583.4      6.6      9.4     12.0  22910.8 
## 
## Coefficients:
##                Estimate Std. Error   t value Pr(>|t|)    
## (Intercept)   8.625e+03  1.998e+04     0.432   0.6659    
## year         -4.273e+00  9.886e+00    -0.432   0.6656    
## pop           1.040e-06  4.341e-07     2.396   0.0166 *  
## acm.mean      9.990e-01  7.616e-05 13117.671   <2e-16 ***
## excess.mean. -9.936e-01  3.612e-04 -2750.742   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 388.7 on 6203 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 6.78e+07 on 4 and 6203 DF,  p-value: < 2.2e-16

Findings:

Part 3: Variance Inflation Factor [VIF] To Indicate Multi-collinearity Issues

# Checking for multi-collinearity using VIF
vif(model)
##         year          pop     acm.mean excess.mean. 
##     1.003847     1.234611     1.977745     1.682883

Findings:

# Plotting residuals to assess the normal distribution of errors
par(mfrow=c(2,2))
plot(model)

Part 4: ANOVA Test to Compare Model with Null Model (No Predictors)

null_model <- lm(expected.mean ~ 1, data=data)
# Perform Anova Test:
anova(null_model, model)
## Analysis of Variance Table
## 
## Model 1: expected.mean ~ 1
## Model 2: expected.mean ~ year + pop + acm.mean + excess.mean.
##   Res.Df        RSS Df Sum of Sq        F    Pr(>F)    
## 1   6207 4.0981e+13                                    
## 2   6203 9.3735e+08  4 4.098e+13 67796941 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Findings:

Part 5: Coefficient Interpretation Test

# Interpret the coefficients (focusing on `pop`)
coef(summary(model))
##                   Estimate   Std. Error       t value   Pr(>|t|)
## (Intercept)   8.624516e+03 1.997549e+04     0.4317549 0.66593455
## year         -4.273189e+00 9.886415e+00    -0.4322283 0.66559050
## pop           1.040008e-06 4.341468e-07     2.3955211 0.01662622
## acm.mean      9.990362e-01 7.615958e-05 13117.6707970 0.00000000
## excess.mean. -9.936306e-01 3.612227e-04 -2750.7421968 0.00000000

Findings:

Part 6: Model Diagnostics and Issues

Part 7: Conclusion

The model appears to it the data exceptionally well according to the R-squared values, yet, the large residuals and perfect fit raise concerns regarding overfitting and data quality issues. With acm.mean and excess.mean. are highly significant predictors of expected.mean. This are practical significance of these findings, but require careful consideration. Hopefully in the next week’s data dives, I might be able to discover the outliers or extreme values that may be influencing the model. My future investigations need to include a deeper dive into data quality, outliers, and additional validation of the model’s predictive power on new or held-out data.