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)
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
For this data dive, I will do hypothesis testing and create visualizations to investigate two separate aspects of our dataset. I’ll generate null hypotheses, specify alpha values, then perform Fisher’s type tests to see if each hypothesis is significant.
Null Hypothesis (H0): There is no significant
difference in the expected mean (expected.mean) between the
two types (type) of data.
To perform a Neyman-Pearson hypothesis test, I would need the following:
I will supply the Fisher’s style test for significance for this hypothesis; however, the Neyman-Pearson test would require additional data.
# Data subset for hypothesis 1
hypo_subset_one <- data
# Perform two-sample t-test for hypothesis 1 (assuming equal variances)
t_result <- t.test(expected.mean ~ type, data = hypo_subset_one)
# Interpretation of the t-test
if (t_result$p.value < 0.05) {
cat("Hypothesis 1: Null Hypothesis Rejected\n")
cat("There is a significant difference in expected mean between data types.\n")
} else {
cat("Hypothesis 1: Null Hypothesis Not Rejected\n")
cat("There is no significant difference in expected mean between data types.\n")
}
## Hypothesis 1: Null Hypothesis Rejected
## There is a significant difference in expected mean between data types.
# Visualization for hypothesis 1:
ggplot(hypo_subset_one, aes(x = type, y = expected.mean)) +
geom_boxplot() +
labs(x = "Type", y = "Expected Mean", title = "Expected Mean by Type")
The boxplot representation shows that the bulk of the data points are distributed on the expected side. Although the dataset’s expected mean values vary from 0 to 5,000,000, the predicted values range from 0 to 1,500,000.
This result demonstrates that the projected mean does not differ much among data types. According to the boxplot, the anticipated mean across the various data types is not statistically different. As a result, we don’t have enough evidence to rule out the null hypothesis.
To completely understand the factors affecting the anticipated mean, more research and analysis may be needed.
Null Hypothesis (H0): There is no significant
difference in population (pop) between data from the year
2020 and data from the year 2021.
A Neyman-Pearson hypothesis test necessitates the following:
To determine whether this assertion is accurate, I’ll apply the Fisher’s style test; a Neyman-Pearson test would require additional information.
# Data subset for hypothesis 2
hypo_subset_two <- data
# Perform two-sample t-test for hypothesis 2:
t_result <- t.test(pop ~ year, data = hypo_subset_two)
# Interpretation of the t-test
if (t_result$p.value < 0.05) {
cat("\nHypothesis 2: Null Hypothesis Rejected\n")
cat("There is a significant difference in population between the years 2020 and 2021.\n")
} else {
cat("\nHypothesis 2: Null Hypothesis Not Rejected\n")
cat("There is no significant difference in population between the years 2020 and 2021.\n")
}
##
## Hypothesis 2: Null Hypothesis Not Rejected
## There is no significant difference in population between the years 2020 and 2021.
ggplot(hypo_subset_two, aes(x = as.factor(year), y = pop)) +
geom_boxplot() +
labs(x = "Year", y = "Population", title = "Population by Year")
The boxplots used in the visualization show the population distributions for 2020 and 2021. The distributions for the two years are relatively comparable. In my opinion, the boxplots are spread rather evenly between the two years.
The population numbers in the boxplot for 2021 particularly vary from 0e+00 to 1e+08, but the population numbers in the boxplot for 2020 have a more confined dispersion. Despite this, there are some general patterns that are repeated.
This analysis predicts that there will be little population change between 2020 and 2021. The boxplots reveal similar distributions, and we don’t have enough data to rule out the null hypothesis.
More study and analysis may be required to find any minute differences in demographic trends between the two years.