Break-down 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()
# 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
I first intended to start by creating a summary of the COVID-19 dataset’s categorical and numerical columns. The summary aims to give a quick overview of the most important statistics and distinctive values in the data.
# First assign the columns to the correct summary var based on if they are categorical or numeric.
numeric_attributes <- COVID[, c("year", "pop", "expected.mean", "acm.mean", "excess.mean*")]
# have a basic summary of the numeric attributes:
summary(numeric_attributes)
## year pop expected.mean acm.mean
## Min. :2020 Min. : 0 Min. : 0.0 Min. : 0
## 1st Qu.:2020 1st Qu.: 35177 1st Qu.: 370.8 1st Qu.: 411
## Median :2020 Median : 267600 Median : 2438.0 Median : 2720
## Mean :2020 Mean : 2520267 Mean : 17998.0 Mean : 20403
## 3rd Qu.:2021 3rd Qu.: 1194828 3rd Qu.: 9056.5 3rd Qu.: 10440
## Max. :2021 Max. :324033981 Max. :1578937.0 Max. :1733563
## excess.mean*
## Min. :-100092.0
## 1st Qu.: 0.0
## Median : 84.0
## Mean : 2394.2
## 3rd Qu.: 799.2
## Max. : 588931.0
# This summary will supply us with the basic stats such as min, max, mean, median and the quartiles for these attributes.
numerical_summary <- summary(numeric_attributes)
# For the categorical columns, we can generate a summary that includes unique values and counts using lapply().
categorical_summary <- lapply(COVID[, c("country", "iso3", "sex", "age_group", "type")], function(x) {
# find the unique values
unique_values <- unique(x)
counts <- table(x)
data.frame(Unique_Values = unique_values, Counts = counts)
})
# Now we combine the numeric and categorical summaries into one output. As stated in the assignment ("These summaries can be combined")
combined_output <- list(Numbers = numerical_summary, Categories = categorical_summary)
# call the output:
combined_output
## $Numbers
## year pop expected.mean acm.mean
## Min. :2020 Min. : 0 Min. : 0.0 Min. : 0
## 1st Qu.:2020 1st Qu.: 35177 1st Qu.: 370.8 1st Qu.: 411
## Median :2020 Median : 267600 Median : 2438.0 Median : 2720
## Mean :2020 Mean : 2520267 Mean : 17998.0 Mean : 20403
## 3rd Qu.:2021 3rd Qu.: 1194828 3rd Qu.: 9056.5 3rd Qu.: 10440
## Max. :2021 Max. :324033981 Max. :1578937.0 Max. :1733563
## excess.mean*
## Min. :-100092.0
## 1st Qu.: 0.0
## Median : 84.0
## Mean : 2394.2
## 3rd Qu.: 799.2
## Max. : 588931.0
##
## $Categories
## $Categories$country
## Unique_Values Counts.x
## 1 Afghanistan Afghanistan
## 2 Angola Albania
## 3 Albania Algeria
## 4 Andorra Andorra
## 5 United Arab Emirates Angola
## 6 Argentina Antigua and Barbuda
## 7 Armenia Argentina
## 8 Antigua and Barbuda Armenia
## 9 Australia Australia
## 10 Austria Austria
## 11 Azerbaijan Azerbaijan
## 12 Burundi Bahamas
## 13 Belgium Bahrain
## 14 Benin Bangladesh
## 15 Burkina Faso Barbados
## 16 Bangladesh Belarus
## 17 Bulgaria Belgium
## 18 Bahrain Belize
## 19 Bahamas Benin
## 20 Bosnia and Herzegovina Bhutan
## 21 Belarus Bolivia (Plurinational State of)
## 22 Belize Bosnia and Herzegovina
## 23 Bolivia (Plurinational State of) Botswana
## 24 Brazil Brazil
## 25 Barbados Brunei Darussalam
## 26 Brunei Darussalam Bulgaria
## 27 Bhutan Burkina Faso
## 28 Botswana Burundi
## 29 Central African Republic Côte d'Ivoire
## 30 Canada Cabo Verde
## 31 Switzerland Cambodia
## 32 Chile Cameroon
## 33 China Canada
## 34 Côte d'Ivoire Central African Republic
## 35 Cameroon Chad
## 36 Democratic Republic of the Congo Chile
## 37 Congo China
## 38 Cook Islands Colombia
## 39 Colombia Comoros
## 40 Comoros Congo
## 41 Cabo Verde Cook Islands
## 42 Costa Rica Costa Rica
## 43 Cuba Croatia
## 44 Cyprus Cuba
## 45 Czechia Cyprus
## 46 Germany Czechia
## 47 Djibouti Democratic People's Republic of Korea
## 48 Dominica Democratic Republic of the Congo
## 49 Denmark Denmark
## 50 Dominican Republic Djibouti
## 51 Algeria Dominica
## 52 Ecuador Dominican Republic
## 53 Egypt Ecuador
## 54 Eritrea Egypt
## 55 Spain El Salvador
## 56 Estonia Equatorial Guinea
## 57 Ethiopia Eritrea
## 58 Finland Estonia
## 59 Fiji Eswatini
## 60 France Ethiopia
## 61 Micronesia (Federated States of) Fiji
## 62 Gabon Finland
## 63 The United Kingdom France
## 64 Georgia Gabon
## 65 Ghana Gambia
## 66 Guinea Georgia
## 67 Gambia Germany
## 68 Guinea-Bissau Ghana
## 69 Equatorial Guinea Greece
## 70 Greece Grenada
## 71 Grenada Guatemala
## 72 Guatemala Guinea
## 73 Guyana Guinea-Bissau
## 74 Honduras Guyana
## 75 Croatia Haiti
## 76 Haiti Honduras
## 77 Hungary Hungary
## 78 Indonesia Iceland
## 79 India India
## 80 Ireland Indonesia
## 81 Iran (Islamic Republic of) Iran (Islamic Republic of)
## 82 Iraq Iraq
## 83 Iceland Ireland
## 84 Israel Israel
## 85 Italy Italy
## 86 Jamaica Jamaica
## 87 Jordan Japan
## 88 Japan Jordan
## 89 Kazakhstan Kazakhstan
## 90 Kenya Kenya
## 91 Kyrgyzstan Kiribati
## 92 Cambodia Kuwait
## 93 Kiribati Kyrgyzstan
## 94 Saint Kitts and Nevis Lao People's Democratic Republic
## 95 Republic of Korea Latvia
## 96 Kuwait Lebanon
## 97 Lao People's Democratic Republic Lesotho
## 98 Lebanon Liberia
## 99 Liberia Libya
## 100 Libya Lithuania
## 101 Saint Lucia Luxembourg
## 102 Sri Lanka Madagascar
## 103 Lesotho Malawi
## 104 Lithuania Malaysia
## 105 Luxembourg Maldives
## 106 Latvia Mali
## 107 Morocco Malta
## 108 Monaco Marshall Islands
## 109 Republic of Moldova Mauritania
## 110 Madagascar Mauritius
## 111 Maldives Mexico
## 112 Mexico Micronesia (Federated States of)
## 113 Marshall Islands Monaco
## 114 North Macedonia Mongolia
## 115 Mali Montenegro
## 116 Malta Morocco
## 117 Myanmar Mozambique
## 118 Montenegro Myanmar
## 119 Mongolia Namibia
## 120 Mozambique Nauru
## 121 Mauritania Nepal
## 122 Mauritius Netherlands
## 123 Malawi New Zealand
## 124 Malaysia Nicaragua
## 125 Namibia Niger
## 126 Niger Nigeria
## 127 Nigeria Niue
## 128 Nicaragua North Macedonia
## 129 Niue Norway
## 130 Netherlands Oman
## 131 Norway Pakistan
## 132 Nepal Palau
## 133 Nauru Panama
## 134 New Zealand Papua New Guinea
## 135 Oman Paraguay
## 136 Pakistan Peru
## 137 Panama Philippines
## 138 Peru Poland
## 139 Philippines Portugal
## 140 Palau Qatar
## 141 Papua New Guinea Republic of Korea
## 142 Poland Republic of Moldova
## 143 Democratic People's Republic of Korea Romania
## 144 Portugal Russian Federation
## 145 Paraguay Rwanda
## 146 Qatar Saint Kitts and Nevis
## 147 Romania Saint Lucia
## 148 Russian Federation Saint Vincent and the Grenadines
## 149 Rwanda Samoa
## 150 Saudi Arabia San Marino
## 151 Sudan Sao Tome and Principe
## 152 Senegal Saudi Arabia
## 153 Singapore Senegal
## 154 Solomon Islands Serbia
## 155 Sierra Leone Seychelles
## 156 El Salvador Sierra Leone
## 157 San Marino Singapore
## 158 Somalia Slovakia
## 159 Serbia Slovenia
## 160 South Sudan Solomon Islands
## 161 Sao Tome and Principe Somalia
## 162 Suriname South Africa
## 163 Slovakia South Sudan
## 164 Slovenia Spain
## 165 Sweden Sri Lanka
## 166 Eswatini Sudan
## 167 Seychelles Suriname
## 168 Syrian Arab Republic Sweden
## 169 Chad Switzerland
## 170 Togo Syrian Arab Republic
## 171 Thailand Türkiye
## 172 Tajikistan Tajikistan
## 173 Turkmenistan Thailand
## 174 Timor-Leste The United Kingdom
## 175 Tonga Timor-Leste
## 176 Trinidad and Tobago Togo
## 177 Tunisia Tonga
## 178 Türkiye Trinidad and Tobago
## 179 Tuvalu Tunisia
## 180 United Republic of Tanzania Turkmenistan
## 181 Uganda Tuvalu
## 182 Ukraine Uganda
## 183 Uruguay Ukraine
## 184 United States of America United Arab Emirates
## 185 Uzbekistan United Republic of Tanzania
## 186 Saint Vincent and the Grenadines United States of America
## 187 Venezuela (Bolivarian Republic of) Uruguay
## 188 Viet Nam Uzbekistan
## 189 Vanuatu Vanuatu
## 190 Samoa Venezuela (Bolivarian Republic of)
## 191 Yemen Viet Nam
## 192 South Africa Yemen
## 193 Zambia Zambia
## 194 Zimbabwe Zimbabwe
## Counts.Freq
## 1 32
## 2 32
## 3 32
## 4 32
## 5 32
## 6 32
## 7 32
## 8 32
## 9 32
## 10 32
## 11 32
## 12 32
## 13 32
## 14 32
## 15 32
## 16 32
## 17 32
## 18 32
## 19 32
## 20 32
## 21 32
## 22 32
## 23 32
## 24 32
## 25 32
## 26 32
## 27 32
## 28 32
## 29 32
## 30 32
## 31 32
## 32 32
## 33 32
## 34 32
## 35 32
## 36 32
## 37 32
## 38 32
## 39 32
## 40 32
## 41 32
## 42 32
## 43 32
## 44 32
## 45 32
## 46 32
## 47 32
## 48 32
## 49 32
## 50 32
## 51 32
## 52 32
## 53 32
## 54 32
## 55 32
## 56 32
## 57 32
## 58 32
## 59 32
## 60 32
## 61 32
## 62 32
## 63 32
## 64 32
## 65 32
## 66 32
## 67 32
## 68 32
## 69 32
## 70 32
## 71 32
## 72 32
## 73 32
## 74 32
## 75 32
## 76 32
## 77 32
## 78 32
## 79 32
## 80 32
## 81 32
## 82 32
## 83 32
## 84 32
## 85 32
## 86 32
## 87 32
## 88 32
## 89 32
## 90 32
## 91 32
## 92 32
## 93 32
## 94 32
## 95 32
## 96 32
## 97 32
## 98 32
## 99 32
## 100 32
## 101 32
## 102 32
## 103 32
## 104 32
## 105 32
## 106 32
## 107 32
## 108 32
## 109 32
## 110 32
## 111 32
## 112 32
## 113 32
## 114 32
## 115 32
## 116 32
## 117 32
## 118 32
## 119 32
## 120 32
## 121 32
## 122 32
## 123 32
## 124 32
## 125 32
## 126 32
## 127 32
## 128 32
## 129 32
## 130 32
## 131 32
## 132 32
## 133 32
## 134 32
## 135 32
## 136 32
## 137 32
## 138 32
## 139 32
## 140 32
## 141 32
## 142 32
## 143 32
## 144 32
## 145 32
## 146 32
## 147 32
## 148 32
## 149 32
## 150 32
## 151 32
## 152 32
## 153 32
## 154 32
## 155 32
## 156 32
## 157 32
## 158 32
## 159 32
## 160 32
## 161 32
## 162 32
## 163 32
## 164 32
## 165 32
## 166 32
## 167 32
## 168 32
## 169 32
## 170 32
## 171 32
## 172 32
## 173 32
## 174 32
## 175 32
## 176 32
## 177 32
## 178 32
## 179 32
## 180 32
## 181 32
## 182 32
## 183 32
## 184 32
## 185 32
## 186 32
## 187 32
## 188 32
## 189 32
## 190 32
## 191 32
## 192 32
## 193 32
## 194 32
##
## $Categories$iso3
## Unique_Values Counts.x Counts.Freq
## 1 AFG AFG 32
## 2 AGO AGO 32
## 3 ALB ALB 32
## 4 AND AND 32
## 5 ARE ARE 32
## 6 ARG ARG 32
## 7 ARM ARM 32
## 8 ATG ATG 32
## 9 AUS AUS 32
## 10 AUT AUT 32
## 11 AZE AZE 32
## 12 BDI BDI 32
## 13 BEL BEL 32
## 14 BEN BEN 32
## 15 BFA BFA 32
## 16 BGD BGD 32
## 17 BGR BGR 32
## 18 BHR BHR 32
## 19 BHS BHS 32
## 20 BIH BIH 32
## 21 BLR BLR 32
## 22 BLZ BLZ 32
## 23 BOL BOL 32
## 24 BRA BRA 32
## 25 BRB BRB 32
## 26 BRN BRN 32
## 27 BTN BTN 32
## 28 BWA BWA 32
## 29 CAF CAF 32
## 30 CAN CAN 32
## 31 CHE CHE 32
## 32 CHL CHL 32
## 33 CHN CHN 32
## 34 CIV CIV 32
## 35 CMR CMR 32
## 36 COD COD 32
## 37 COG COG 32
## 38 COK COK 32
## 39 COL COL 32
## 40 COM COM 32
## 41 CPV CPV 32
## 42 CRI CRI 32
## 43 CUB CUB 32
## 44 CYP CYP 32
## 45 CZE CZE 32
## 46 DEU DEU 32
## 47 DJI DJI 32
## 48 DMA DMA 32
## 49 DNK DNK 32
## 50 DOM DOM 32
## 51 DZA DZA 32
## 52 ECU ECU 32
## 53 EGY EGY 32
## 54 ERI ERI 32
## 55 ESP ESP 32
## 56 EST EST 32
## 57 ETH ETH 32
## 58 FIN FIN 32
## 59 FJI FJI 32
## 60 FRA FRA 32
## 61 FSM FSM 32
## 62 GAB GAB 32
## 63 GBR GBR 32
## 64 GEO GEO 32
## 65 GHA GHA 32
## 66 GIN GIN 32
## 67 GMB GMB 32
## 68 GNB GNB 32
## 69 GNQ GNQ 32
## 70 GRC GRC 32
## 71 GRD GRD 32
## 72 GTM GTM 32
## 73 GUY GUY 32
## 74 HND HND 32
## 75 HRV HRV 32
## 76 HTI HTI 32
## 77 HUN HUN 32
## 78 IDN IDN 32
## 79 IND IND 32
## 80 IRL IRL 32
## 81 IRN IRN 32
## 82 IRQ IRQ 32
## 83 ISL ISL 32
## 84 ISR ISR 32
## 85 ITA ITA 32
## 86 JAM JAM 32
## 87 JOR JOR 32
## 88 JPN JPN 32
## 89 KAZ KAZ 32
## 90 KEN KEN 32
## 91 KGZ KGZ 32
## 92 KHM KHM 32
## 93 KIR KIR 32
## 94 KNA KNA 32
## 95 KOR KOR 32
## 96 KWT KWT 32
## 97 LAO LAO 32
## 98 LBN LBN 32
## 99 LBR LBR 32
## 100 LBY LBY 32
## 101 LCA LCA 32
## 102 LKA LKA 32
## 103 LSO LSO 32
## 104 LTU LTU 32
## 105 LUX LUX 32
## 106 LVA LVA 32
## 107 MAR MAR 32
## 108 MCO MCO 32
## 109 MDA MDA 32
## 110 MDG MDG 32
## 111 MDV MDV 32
## 112 MEX MEX 32
## 113 MHL MHL 32
## 114 MKD MKD 32
## 115 MLI MLI 32
## 116 MLT MLT 32
## 117 MMR MMR 32
## 118 MNE MNE 32
## 119 MNG MNG 32
## 120 MOZ MOZ 32
## 121 MRT MRT 32
## 122 MUS MUS 32
## 123 MWI MWI 32
## 124 MYS MYS 32
## 125 NAM NAM 32
## 126 NER NER 32
## 127 NGA NGA 32
## 128 NIC NIC 32
## 129 NIU NIU 32
## 130 NLD NLD 32
## 131 NOR NOR 32
## 132 NPL NPL 32
## 133 NRU NRU 32
## 134 NZL NZL 32
## 135 OMN OMN 32
## 136 PAK PAK 32
## 137 PAN PAN 32
## 138 PER PER 32
## 139 PHL PHL 32
## 140 PLW PLW 32
## 141 PNG PNG 32
## 142 POL POL 32
## 143 PRK PRK 32
## 144 PRT PRT 32
## 145 PRY PRY 32
## 146 QAT QAT 32
## 147 ROU ROU 32
## 148 RUS RUS 32
## 149 RWA RWA 32
## 150 SAU SAU 32
## 151 SDN SDN 32
## 152 SEN SEN 32
## 153 SGP SGP 32
## 154 SLB SLB 32
## 155 SLE SLE 32
## 156 SLV SLV 32
## 157 SMR SMR 32
## 158 SOM SOM 32
## 159 SRB SRB 32
## 160 SSD SSD 32
## 161 STP STP 32
## 162 SUR SUR 32
## 163 SVK SVK 32
## 164 SVN SVN 32
## 165 SWE SWE 32
## 166 SWZ SWZ 32
## 167 SYC SYC 32
## 168 SYR SYR 32
## 169 TCD TCD 32
## 170 TGO TGO 32
## 171 THA THA 32
## 172 TJK TJK 32
## 173 TKM TKM 32
## 174 TLS TLS 32
## 175 TON TON 32
## 176 TTO TTO 32
## 177 TUN TUN 32
## 178 TUR TUR 32
## 179 TUV TUV 32
## 180 TZA TZA 32
## 181 UGA UGA 32
## 182 UKR UKR 32
## 183 URY URY 32
## 184 USA USA 32
## 185 UZB UZB 32
## 186 VCT VCT 32
## 187 VEN VEN 32
## 188 VNM VNM 32
## 189 VUT VUT 32
## 190 WSM WSM 32
## 191 YEM YEM 32
## 192 ZAF ZAF 32
## 193 ZMB ZMB 32
## 194 ZWE ZWE 32
##
## $Categories$sex
## Unique_Values Counts.x Counts.Freq
## 1 Female Female 3104
## 2 Male Male 3104
##
## $Categories$age_group
## Unique_Values Counts.x Counts.Freq
## 1 0-24 >85 776
## 2 25-34 0-24 776
## 3 35-44 25-34 776
## 4 45-54 35-44 776
## 5 55-64 45-54 776
## 6 65-74 55-64 776
## 7 75-84 65-74 776
## 8 >85 75-84 776
##
## $Categories$type
## Unique_Values Counts.x Counts.Freq
## 1 predicted predicted 2896
## 2 reported reported 3312
# NOTE: for the output in markdown, you will need to select the data.frame in which you want to view for the categorical data.
Numerical Findings: - Year: The stats for the ‘year’ column indicate that the dataset spans two years, which we know from looking at the dataset before hand. In terms of ‘stats’ the minimum a year can be is 2020 and max is 2021. This shows that the data set is collected over a specific time period which will be good for future temporal analysis.
Pop: “pop” as it is called in this dataset, indicates the population-related data. The maximum population is 324,033,981 indicating a wide range of population sizes within the dataset.
Expected Mean: For the expected mean, we can look at the quartiles (25th, 50th and 75th percentiles) to see the distribution of the expected mean across the dataset.
acm.means: This attribute provides statistics for reveal central tendency and spread. This attribute like ‘Expected_mean’ will provide insights to the distribution of the actual mean values.
excess.mean: The min value is -100,092, which indicates the potential for the outliers with negative values. Overall, we can expect excess.mean to highlight the spread from the quartiles but also the potential outliers.
Categorical Findings: - Country: Provides unique countries in the dataset. In this dataset it seems the count frequency for each country is 32. This indicates that the data is diverse and covers a wide geographical range.
iso3: this attribute represents the unique ISO3 country code. Now, the counts for the country codes are the same for the country attribute. Meaning, ISO3 is just a more standardized way of representing the country.
sex: Shows us that there are 3,104 entries for both Male and Female sexes. This shows a balance between the genders, making the data set gender-neutral, which is useful for gender-related analysis.
age_group: Gives us information about the age group category and their counts. For instance, if we take the age_group ‘0-24’ it appears 776 times within the dataset. This information is important to understand the age distribution of the data.
type: this attribute differentiates between ‘predicted’ and ‘reported’ types and provides the counts for each. From the summary, we can see that 2,896 entries with ‘predicted’ and 3,312 entries with ‘reported’. This information can be used to assess the proprtion of predicted and reported in the dataset.
For this section, I’m going to follow a format of:
I will follow this format 5 times.
Quick set-up: For Question 1 and 5 I will use data visualization to show the outcome of my question :). Therefore, I need to include some libs
library(dplyr)
library(ggplot2)
Question 1: Does the distribution of “excess.mean” vary significantly between different “country” values?
Reasoning I want to see if there are any significant differences in excess mortality between nations based on the summary numbers. Understanding differences in excess mortality between countries can provide insights into the efficiency of public health interventions and healthcare systems in responding to events like the COVID-19 pandemic that we all experienced. Identifying countries with considerably high or low excess rates can aid in more effective intervention targeting.
R-Script:
# Create a box-plot to show the distribution of excess.mean by country:
ggplot(COVID, aes(x = country, y = `excess.mean*`))+
geom_boxplot()+
labs(title = "Distribution of Excess Mean by Country",
x = "Country",
y = "Excess Mean")
Question 2: Is there a correlation between “expected.mean” and “acm.mean”?
Reasoning This topic investigates the relationship between the predicted and actual means and can be used to evaluate the accuracy of forecasts or models. If there is a strong positive correlation, it indicates that the predictions match the actual outcomes well. A weak connection, on the other hand, may signal the need for additional model development or study into external factors influencing the outcomes.
R-Script:
# Calculate the correlation between expected.mean and acm.mean
correlation <- cor(COVID$expected.mean, COVID$acm.mean)
# print
cat("The correlation between expected and actual mean is: ", correlation)
## The correlation between expected and actual mean is: 0.9854867
Question 3: What are the most common “age_group” categories associated with high “pop” (population) values?
Reasoning Investigating which age groups have the most people can help guide healthcare resource allocation and policy decisions. For example, if a certain age group has a much higher population count, more healthcare facilities and services may be required.
R-Script:
# Calculate the total population by age group
age_group_population <- COVID %>%
group_by(age_group) %>%
summarise(total_population = sum(pop))
# Sort the results in descending order
age_group_population <- age_group_population %>%
arrange(desc(total_population))
# Print the top age_group categories with the highest population:
cat("The top age_group categories with the highest population counts:\n")
## The top age_group categories with the highest population counts:
print(age_group_population)
## # A tibble: 8 × 2
## age_group total_population
## <chr> <dbl>
## 1 0-24 6442946008
## 2 25-34 2386774892
## 3 35-44 2086721597
## 4 45-54 1834185673
## 5 55-64 1418705086
## 6 65-74 931352411
## 7 75-84 422106904
## 8 >85 123026868
Question 4: Do certain “type” categories have higher “expected.mean” values compared to the others?
Reasoning This inquiry investigates if the levels of the expected means vary with different “types” (predicted or reported). Understanding whether higher expected means are predicted or reported can help guide data collection and quality control activities. For example, if a specific kind (predicted or reported) frequently returns higher expected means, the outcome may need closer examination or validation.
R-Script:
# Calculate the mean of expected.mean by type.
type_mean <- COVID %>%
group_by(type) %>%
summarise(expected_mean_mean = mean(expected.mean))
# Sort the results in desc order.
type_mean <- type_mean %>%
arrange(desc(expected_mean_mean))
# Print the type categories with the highest mean expected.mean.
cat("The type categories with the highest mean:\n")
## The type categories with the highest mean:
print(type_mean)
## # A tibble: 2 × 2
## type expected_mean_mean
## <chr> <dbl>
## 1 predicted 23799.
## 2 reported 12926.
Question 5: Are there significant differences in “pop” (population) distributions between different “sex” (Male or Female) categories?
Reasoning Investigating population distributions by gender can reveal demographic trends. This has consequences for healthcare planning and policy, particularly in terms of understanding how gender can contribute to or change COVID distribution based on COVID’s prevalence and the gender. This information can also be used to inform gender-specific healthcare activities.
R-Script:
# I haven't used a violin plot before, so I thought this would be a cool chance to do that!
# So, make a violin plot to visualize the distribution of population by sex.
ggplot(COVID, aes(x = sex, y = pop, fill = sex))+
geom_violin()+
labs(title = "Distribution of Population by Sex",
x = "Sex",
y = "Population")
In Part 2, I did employ visuals. I’d like to investigate the Population vs. Excess Mean by Year, but then utilize color to represent the Country. This plot can be used to investigate how population and excess mean connect to one another in the context of countries, years, and gender!
R-Script and Plot:
ggplot(COVID, aes(x = pop, y = `excess.mean*`, color = country, size = year, shape = sex))+
geom_point()+
labs(
title = "Population vs. Excess Mean by Year",
x = "Population",
y = "Excess Mean",
color = "Country",
size = "Year",
shape = "Gender") +
scale_size_continuous(range = c(2, 10))+
theme(legend.position = "bottom",
legend.key.size = unit(0.5, "lines"))
IDEA !
Since that graph is massive and doesn’t really preview really nicely, I’m going to get the top 10 countries based on the sum of the population.
# filter out basically 90% of the countries and only return 10
top_10 <- COVID %>%
group_by(country) %>%
summarize(total_population = sum(pop)) %>%
# I'm leaving this as 'top_n' as you can change how many countries you want displayed by changing the first parameter.
top_n(10, total_population) %>%
select(country)
# create a new data.frame to deal with the new graph, therefore, we aren't changing the actual data set.
filtered_COVID <- COVID %>%
filter(country %in% top_10$country)
# same code as the graph used in part 3, but the first parameter in the ggplot is changed to the filtered data frame instead of using the entire data set.
ggplot(filtered_COVID, aes(x = pop, y = `excess.mean*`, color = country, size = year, shape = sex))+
geom_point()+
labs(
title = "Population vs. Excess Mean by Year",
x = "Population",
y = "Excess Mean",
color = "Country",
size = "Year",
shape = "Gender") +
scale_size_continuous(range = c(2, 10))+
theme(legend.position = "bottom",
legend.key.size = unit(0.5, "lines"))
As you can see this graph is just the top 10 countries based on the sum of the population, so it makes us think what the larger graph represents :D
Questions:
How can we format or manipulate the ggplot variables to obtain a more readable graph?
What other types of visuals can we use to show the relationship between excess mean and population?
End of Week 2 - Data Dive - Summaries