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
Created Columns Breakdown:
I generated two attributes: the first is a ‘high_mean’ attribute that signals whether the ‘expected.mean’ parameter exceeds a particular limit, in my case, 2400. This is due to the ‘2438.0’ Median value for the ‘expected.mean’ property. A base 10 logarithm of the population’s corresponding value (referring to the “pop” attribute) will also be used by me since having it as a converted variable might be helpful when used as an explanatory variable in sets of variable combinations.
Creation of the high_mean and
log_population Attributes:
# Create an attribute for 'data' that is for the high mean.
data$high_mean <- ifelse(data$expected.mean > 2400, "High", "Low")
# Create an attribute for 'data' that is for the log population.
data$log_population <- log10(data$pop)
# Create if attributes were created:
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 high_mean
## Min. : 0 Min. :-100092.0 Mode:logical Length:6208
## 1st Qu.: 411 1st Qu.: 0.0 NA's:6208 Class :character
## Median : 2720 Median : 84.0 Mode :character
## Mean : 20403 Mean : 2394.2
## 3rd Qu.: 10440 3rd Qu.: 799.2
## Max. :1733563 Max. : 588931.0
## log_population
## Min. : -Inf
## 1st Qu.:4.546
## Median :5.427
## Mean : -Inf
## 3rd Qu.:6.077
## Max. :8.511
expected.meanlog_populationPlot:
# Let's make a scatter plot for these variables
plot(data$log_population, data$expected.mean, xlab="Population (Log-base 10)", ylab="Expected Mean", main="Correlation between Expected Mean and the Population")
Findings:
The scatter plot shows how the population’s logarithm (base 10) and expected mean (expected.mean) relate to one another. The figure shows a general tendency of higher values than expected.mean as log_population rises, indicating a positive link between the two variables. The variety in expected.mean for each level of log_population should be noted, though, since this suggests that additional factors might possibly be involved in the change in expected.mean.
Calculate Correlation Coefficient:
# Calculate the coefficient.
correlation_combo_one <- cor(data$log_population, data$expected.mean)
# print the result:
cat("Correlation Coefficient between the Population and Expected Mean is: ", correlation_combo_one, "\n")
## Correlation Coefficient between the Population and Expected Mean is: NaN
Findings:
Log_population and expected.mean have a determined correlation coefficient of NaN (Not a Number). This may be the case in this instance if there are rows with zero or negative values in either log_population or expected.mean. This can happen when there is no fluctuation in one of the variables. To solve this problem, it is crucial to conduct an investigation and clear the data. Log_population and expected.mean don’t appear to be linearly related, according to the NaN correlation.
Confidence Interval:
# Build a C.I. for expected.mean
C_I_combo_one <- t.test(data$expected.mean, conf.level = 0.95)$conf.int
# Print the result:
cat("Confidence Interval for Expected Mean: ", C_I_combo_one, "\n")
## Confidence Interval for Expected Mean: 15976.38 20019.69
Findings:
The calculated range of the predicted mean’s 95% confidence interval is 15,976.38 to 20,019.69. This indicates that we have a 95% confidence interval around the real population mean of expected.mean. It offers a range that we may predict the population mean to fall inside.
Conclusion for Combination 1:
Log_population and expected.mean appear to be trending upward in the scatter plot, but the NaN correlation coefficient shows that this relationship may not be linear or that it may be affected by problems with the data.
The confidence interval for expected.mean gives a 95% confidence level estimate of the population mean and identifies a range of values in which the real mean is most likely to fall.
Further investigation is needed to address the NaN correlation coefficient and explore potential data quality issues.
excess.mean*age_groupPlot:
# Create numeric age groups:
data$numeric_ages <- as.numeric(factor(data$age_group))
# Let's make a scatter plot for these variables
plot(data$numeric_ages, data$pop , xlab="Age Group", ylab="Population", main="Correlation between Population and Age Groups")
Findings:
The scatter plot clearly confirms the negative relationship shown by the correlation coefficient. The scatter plot’s points slope left to right, indicating that age groups tend to shrink as the population expands, and that population tends to grow as age groups rise. This agreement with the negative correlation coefficient supports the assumption that there is a minor inverse relationship between age groups and population size.
Calculate Correlation Coefficient:
# Calculate the coefficient.
correlation_combo_two <- cor(data$numeric_ages, data$pop)
# print the result:
cat("Correlation Coefficient between the Age Groups and Population is: ", correlation_combo_two, "\n")
## Correlation Coefficient between the Age Groups and Population is: -0.07967502
Findings:
The correlation between age groups (numeric_ages) and the population (pop) is around -0.0797. This negative figure indicates a modest, unfavorable association between age groups and the population. In other words, as age groups increase, the population tends to fall slightly. However, the correlation is not particularly strong, suggesting that age groups may not be a good indication of population increase.
Confidence Interval:
# Build a C.I. for numeric ages (age_group)
C_I_combo_two <- t.test(data$numeric_ages, conf.level = 0.95)$conf.int
# Print the result:
cat("Confidence Interval for the Age Groups is: ", C_I_combo_two, "\n")
## Confidence Interval for the Age Groups is: 4.442987 4.557013
Findings:
The 95% confidence interval for the numerical ages (age_groups) is predicted to be between 4.443 and 4.557. This range denotes a 95% confidence interval that the actual population mean for the given age group falls within. The relatively short time suggests a fair judgement because of its size.
Conclusion for Combination 2:
The scatter plot and correlation coefficient both suggest a fragile, negative relationship between age groups and population size. The population does have a little tendency to drop as it ages, albeit the relationship is not especially linear.
The confidence interval for the anticipated mean provides a relatively accurate approximation of the population mean within the stated confidence level.
The findings suggest that, while there is a minor inverse link between age groups and population size, other variables are most likely more essential in driving population increase. More research into the underlying reasons of these demographic tendencies may be required.
acm.meanhigh_meanPlot:
# factor high_mean
data$factor_highMean <- factor(data$high_mean, levels=c("Low", "High"))
boxplot(data$acm.mean ~ data$factor_highMean,
xlab = "High Mean (Low or High)",
ylab = "Actual Mean",
main = "Boxplot of High Mean and Actual Mean")
Findings:
The boxplot depicts a distribution of data points for the high_mean and acm.mean combination. The majority of the data points in this plot fall between 0 and 10,000 for the real mean (acm.mean), with a majority of the data points concentrated on the right side of the graph. The lack of data points on the left side of the graph indicates that the data is significantly and positively biased towards greater values of acm.mean.
Calculate Correlation Coefficient:
# Turn this attribute that took me from getting this done in 30 minutes to 2 hours....
data$factor_high_mean <- factor(data$high_mean)
data$numeric_high_mean <- as.numeric(data$factor_high_mean)
# Calculate the coefficient.
correlation_combo_three <- cor(data$numeric_high_mean, data$acm.mean)
# print the result:
cat("Correlation Coefficient between High Mean and Actual Mean is: ", correlation_combo_three, "\n")
## Correlation Coefficient between High Mean and Actual Mean is: -0.2151597
Findings:
The correlation coefficient between high_mean and acm.mean is -0.2151597. This negative figure indicates a modest, unfavorable association between the marking of a high or low mean and the actual population. In other words, as the high mean increases, the actual mean tends to fall slightly. However, the correlation is not particularly strong, suggesting that labeling of high or low mean may not be a good indication of the actual means increase.
Confidence Interval:
# Build a C.I. for acm.mean
C_I_combo_three <- t.test(data$acm.mean, conf.level = 0.95)$conf.int
# Print the result:
cat("Confidence Interval for the Actual Mean is: ", C_I_combo_three, "\n")
## Confidence Interval for the Actual Mean is: 18136.57 22670.32
Findings:
The 95% confidence interval for the actual mean (acm.mean) is believed to be between 18,136.57 and 22,670.32. This range provides a 95% confidence interval for the true population mean of the actual mean. It’s fairly narrow, indicating a rather accurate judgement.
Conclusion for Combination 3:
The boxplot shows that the distribution of acm.mean values are positively skewed, with the bulk of data points clustered in the 0 to 10,000 range and no data points on the high side.
Because there is minimal fluctuation in the connection between high_mean and acm.mean, it is probable that other factors or data quality issues are at work.
The confidence interval for the actual mean (acm.mean) provides a relatively accurate estimate of the population mean within the stated confidence level.
Understanding the origins of the skewed distribution as well as the nature of the relationship between high_mean and acm.mean may necessitate more investigation. Concerns around data quality need also be addressed in order to accomplish reliable analysis.
The variable combinations’ varying degrees of correlation reflect the dataset’s complexity. One recurring theme is the belief that data quality is critical. I have encountered issues with missing data, outliers, and cases where the data appeared to fluctuate little throughout the investigation (this week’s data dive). These concerns with data quality not only bring the credibility of my findings into doubt but also highlight the need for proper data treatment and cleaning (Yay! The things we are learning!). It is critical to resolve these issues before proceeding to a more in-depth analysis.
While some variable combinations indicated logical relationships, others revealed that the data did not completely support the expected findings. This emphasizes the significance of a more comprehensive research that takes into account other factors and goes deeper into the material’s intricacies. To acquire a greater grasp of the underlying patterns and correlations in the dataset, future study should go beyond simple exploratory analysis. Data from advanced statistical models and techniques may be beneficial (we are getting to this!). Furthermore, broadening the focus to include a larger variety of components and studying potential links between them may help expose the subtle dynamics at work.
Overall, this week’s data dive provided me with a better knowledge of the data. Major insights are still sought, and achieving strong and reliable results will be dependent on overcoming data quality challenges and exploring more research possibilities.