COVID Vaccinations in the UK EDA Project
Covid was a major global crisis. Exploring vaccination data helps evaluate the response to the crisis. The vaccine roll-out, although controversial, was largely successful. The data set shows the amount of first, second and third doses given out in each area through late 2021 and early 2022. This project explores the differential rates between areas of the UK and explores the tendency for people to take booster vaccines. Statistical tests are used to show the relationships between variables in the data set.
#Installing packages to read Excel file
install.packages("readxl",repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/morga/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\morga\AppData\Local\Temp\RtmpYNozih\downloaded_packages
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.3
#Viewing Excel data
UKVaccinationData <- read_excel("UkVaccinationData.xlsx")
head(UKVaccinationData)
#Task 1
#Generating Descriptive Statistics Table of Vaccination Data
summary(UKVaccinationData)
## areaName areaCode year month
## Length:904 Length:904 Min. :2021 Min. : 1.000
## Class :character Class :character 1st Qu.:2021 1st Qu.: 2.000
## Mode :character Mode :character Median :2022 Median : 4.000
## Mean :2022 Mean : 5.947
## 3rd Qu.:2022 3rd Qu.:11.000
## Max. :2022 Max. :12.000
## NA's :1
## Quarter day WorkingDay FirstDose
## Length:904 Length:904 Length:904 Min. : 0.0
## Class :character Class :character Class :character 1st Qu.: 338.5
## Mode :character Mode :character Mode :character Median : 876.5
## Mean : 4994.3
## 3rd Qu.: 3653.2
## Max. :115551.0
## NA's :4
## SecondDose ThirdDose Booster
## Min. : 0 Min. : 0 Min. :0.0000
## 1st Qu.: 478 1st Qu.: 1314 1st Qu.:0.0000
## Median : 971 Median : 6992 Median :1.0000
## Mean : 5574 Mean : 42530 Mean :0.6482
## 3rd Qu.: 5770 3rd Qu.: 23465 3rd Qu.:1.0000
## Max. :48491 Max. :830403 Max. :1.0000
## NA's :3 NA's :6
From the descriptive statistics we can see that we have 904 data points. The average amount of first doses given out each day was 4994.3, ranging from 0 to a maximum of 115,551. The mean number of second doses was 5574 with a minimum of 0 and maximum 48,491. The average number of third doses given out each day was 42,530 with a minimum of 0 and maximum of 830,403. This shows in this period most people were getting their third dose of the vaccine. Note there are 14 NA values.
#Task 2
#Installing tidyverse to handle missing data
install.packages("tidyverse",repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/morga/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'tidyverse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\morga\AppData\Local\Temp\RtmpYNozih\downloaded_packages
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'tibble' was built under R version 4.4.0
## Warning: package 'tidyr' was built under R version 4.4.0
## Warning: package 'readr' was built under R version 4.4.0
## Warning: package 'purrr' was built under R version 4.4.0
## Warning: package 'dplyr' was built under R version 4.4.0
## Warning: package 'stringr' was built under R version 4.4.0
## Warning: package 'forcats' was built under R version 4.4.0
## Warning: package 'lubridate' was built under R version 4.4.0
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#Removing rows with N/A values and generating new descriptive statistics table for new full data set
UKVaccinationData2 <-drop_na(UKVaccinationData)
View(UKVaccinationData2)
summary(UKVaccinationData2)
## areaName areaCode year month
## Length:890 Length:890 Min. :2021 Min. : 1.000
## Class :character Class :character 1st Qu.:2021 1st Qu.: 2.000
## Mode :character Mode :character Median :2022 Median : 4.000
## Mean :2022 Mean : 5.903
## 3rd Qu.:2022 3rd Qu.:11.000
## Max. :2022 Max. :12.000
## Quarter day WorkingDay FirstDose
## Length:890 Length:890 Length:890 Min. : 0
## Class :character Class :character Class :character 1st Qu.: 340
## Mode :character Mode :character Mode :character Median : 882
## Mean : 5007
## 3rd Qu.: 3654
## Max. :115551
## SecondDose ThirdDose Booster
## Min. : 0.0 Min. : 0 Min. :0.0000
## 1st Qu.: 476.5 1st Qu.: 1319 1st Qu.:0.0000
## Median : 978.5 Median : 7185 Median :1.0000
## Mean : 5598.8 Mean : 42852 Mean :0.6517
## 3rd Qu.: 6163.2 3rd Qu.: 23818 3rd Qu.:1.0000
## Max. :48491.0 Max. :830403 Max. :1.0000
Removing NA values raises mean values of affected variables. These mean values are now more accurate and will be used henceforth.
#Task 3
#Creating histogram of 1st and 2nd doses
hist(UKVaccinationData2$FirstDose,xlab = "First Doses (given on a specific day)", main = "Distribution of First Doses of COVID Vaccine", breaks =10)
hist(UKVaccinationData2$SecondDose, xlab = "Second Doses (given on a specific day)", main = "Distribution of Second Doses of COVID Vaccine", breaks=10)
Both histograms are skewed to the left and showing most of the time less
than 10,000 first doses were given out each day and for second doses
this value is 5000. This clearly shows the consistent but relatively low
levels of roll-out within the UK.
#Plotting the relationship between First Doses and Second Doses given on a specific day
plot(UKVaccinationData2$FirstDose, UKVaccinationData2$SecondDose, col="blue", main = "Relationship between First and Second Doses given each day", xlab = "First Doses given each day", ylab= "Second Doses given each day")
#Removing Outlier
UKVaccinationData3<- UKVaccinationData2 %>%
filter(FirstDose < 100000)
#Plotting relationship after removing outlier
plot(UKVaccinationData3$FirstDose, UKVaccinationData3$SecondDose, col="red", main = "Relationship between First and Second Doses given each day", xlab = "First Doses given each day", ylab= "Second Doses given each day")
The first plot shows the relationship between first doses and second
doses given each day. There is a clear outlier of over 100,000 first.
Further, exploration into this date in November 2021 should be made to
explore the cause of it. This could be due to logistical error or
targets needing to be met, hence the inflated value.
The second scatter plot removes this outlier to show the relationship more accurately. Overall, it is a strong positive correlation. This likely due to the efficiency of vaccination sites increasing over time; therefore, more vaccinations could be given in total.
#Packages installed to create bar chart
install.packages("ggplot2",repos = "http://cran.us.r-project.org")
## Warning: package 'ggplot2' is in use and will not be installed
library(ggplot2)
library(dplyr)
#Creating separate data frames for booster values 0 and 1 and getting the total sum of First Doses in each
dfb <-UKVaccinationData3 %>%
filter(Booster=="1")
nob<-sum(dfb$FirstDose)
dfnb <-UKVaccinationData3 %>%
filter(Booster=="0")
nonb<-sum(dfnb$FirstDose)
#Combining previous two data frames into one data frame
dfsum <- data.frame(Booster = c("0", "1"), Total_FirstDose = c(nonb, nob))
head(dfsum)
#Creating a bar chart showing total First Doses of areas that are unlikely to have a booster vaccine compared to areas that are not
ggplot(dfsum, aes(x = Booster, y = Total_FirstDose, fill = Booster)) +
geom_bar(stat = "identity") +
labs(title = "Total First Dose Vaccinations by Booster Status",
x = "Booster Status",
y = "Total First Dose Vaccinations") +
scale_fill_manual(values = c("0" = "red", "1" = "blue"))
This bar plot shows the total number of first doses given to people who
are likely (1) or unlikely (0) to take a booster vaccine. Around 2.39
million people who took a first dose were unlikely to take a booster,
whereas 2.07 million were likely to. Further analysis could ascertain
the amount of people who ended up taking a booster. Results may have
differed as more research came out about effectiveness and longevity of
the vaccine.
Task 4
#Displaying unique values of Area Names and their frequencies
unique(UKVaccinationData3$areaName)
## [1] "England" "Northern Ireland" "Scotland" "Wales"
table(UKVaccinationData3$areaName)
##
## England Northern Ireland Scotland Wales
## 234 233 218 204
This frequency table shows that the data is gathered evenly from each country within the UK. Further analysis can be made to explore the discrepancies in which may be explained by regional bank holidays or socio-economic differences.
Task 5
#Building a contingency table on Area Name and whether people are likely to take a booster
table(UKVaccinationData3$areaName, UKVaccinationData3$Booster)
##
## 0 1
## England 93 141
## Northern Ireland 73 160
## Scotland 66 152
## Wales 77 127
#Running a chi-squared test to test independence between the two variables
chisq.test(table(UKVaccinationData3$areaName, UKVaccinationData3$Booster))
##
## Pearson's Chi-squared test
##
## data: table(UKVaccinationData3$areaName, UKVaccinationData3$Booster)
## X-squared = 6.5065, df = 3, p-value = 0.08941
The frequency table shows that across each country in the UK, overall areas were more likely to take a booster than not.
Testing at a significance level of 5%.
H0: That the country and likeliness of someone taking a booster is INDEPENDANT
H1: That the country and likeliness of someone taking a booster is DEPENDANT
These variables were chosen to see if there was any dependence on likeliness to take a booster based on the country potentially due to differences in attitudes or effectiveness in government information. The p-value of this test is above this at 7.92%. Therefore, at the 5% significance level, we cannot reject the null hypothesis that there is no dependence between the country and likeliness of booster uptake. Hence, we can say that the attitudes towards taking a booster were consistent and it was unlikely that there was much difference in messaging between local governments.
Task 6
#Installing dplyr to retrieve subsets
library(dplyr)
#Retrieving subset based on England in the year 2022 and generating descriptive statistics table
Eng2022 <- UKVaccinationData3 %>%
filter(
areaName == "England",
year == "2022")
summary(Eng2022)
## areaName areaCode year month
## Length:143 Length:143 Min. :2022 Min. :1.000
## Class :character Class :character 1st Qu.:2022 1st Qu.:2.000
## Mode :character Mode :character Median :2022 Median :3.000
## Mean :2022 Mean :2.902
## 3rd Qu.:2022 3rd Qu.:4.000
## Max. :2022 Max. :5.000
## Quarter day WorkingDay FirstDose
## Length:143 Length:143 Length:143 Min. : 2203
## Class :character Class :character Class :character 1st Qu.: 5130
## Mode :character Mode :character Mode :character Median : 8576
## Mean : 9914
## 3rd Qu.:13836
## Max. :29231
## SecondDose ThirdDose Booster
## Min. : 2126 Min. : 2287 Min. :0.0000
## 1st Qu.: 8762 1st Qu.: 12594 1st Qu.:0.0000
## Median :12964 Median : 15788 Median :1.0000
## Mean :14967 Mean : 30476 Mean :0.6993
## 3rd Qu.:22059 3rd Qu.: 28159 3rd Qu.:1.0000
## Max. :41351 Max. :206676 Max. :1.0000
#Retrieving subset based on England in the year 2021 and generating descriptive statistics table
Eng2021 <- UKVaccinationData3 %>%
filter(
areaName == "England",
year == "2021")
summary(Eng2021)
## areaName areaCode year month
## Length:91 Length:91 Min. :2021 Min. :10
## Class :character Class :character 1st Qu.:2021 1st Qu.:10
## Mode :character Mode :character Median :2021 Median :11
## Mean :2021 Mean :11
## 3rd Qu.:2021 3rd Qu.:12
## Max. :2021 Max. :12
## Quarter day WorkingDay FirstDose
## Length:91 Length:91 Length:91 Min. : 955
## Class :character Class :character Class :character 1st Qu.:19671
## Mode :character Mode :character Mode :character Median :25536
## Mean :26584
## 3rd Qu.:34181
## Max. :44558
## SecondDose ThirdDose Booster
## Min. : 916 Min. : 10477 Min. :0.0000
## 1st Qu.:18537 1st Qu.:192229 1st Qu.:0.0000
## Median :22423 Median :266470 Median :0.0000
## Mean :23561 Mean :299516 Mean :0.4505
## 3rd Qu.:27730 3rd Qu.:337682 3rd Qu.:1.0000
## Max. :48491 Max. :830403 Max. :1.0000
It is important to compare between different years to show how the roll out of the COVID vaccine adapted overtime. Interestingly, the data suggests for first, second and third doses suggests the average was higher in 2021. This aligns with suggestions that as time went on people became more sceptical and less frightened due to mutations of the virus making it less severe.
Task 7
#Creating subsets of data for First Doses in England in 2021 and 2022
Eng <- UKVaccinationData3 %>%
filter(
areaName == "England")
mF21 = Eng[Eng$year == 2021,]$FirstDose
mF22 = Eng[Eng$year == 2022,]$FirstDose
#Running a two sample t-test to test significance of the difference between the means of First Doses in England in 2021 and 2022
t.test(mF21, mF22)
##
## Welch Two Sample t-test
##
## data: mF21 and mF22
## t = 15.166, df = 135.47, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 14496.03 18843.59
## sample estimates:
## mean of x mean of y
## 26584.308 9914.497
H0= the difference of means of First Doses in England in 2021 and 2022 is 0
H1= the difference of the means of First Doses in England in 2021 and 2022 is not 0
Testing at a significance level of 5%.
The p-value is below the 5% significance level, so we can reject the null hypothesis and accept the alternative hypothesis that there is a significant difference between the First Doses given out in 2021 and 2022. This is logical because most people had received their first dose in 2021 so the number of doses given in 2022 should be lower as there are fewer people needing a first dose.
Task 8
#Table of First Doses given in England
Eng <- UKVaccinationData3 %>%
filter(
areaName == "England")
head(Eng)
#Total number of first doses in England
sum(Eng$FirstDose)
## [1] 3836945
#Average number of first doses in England
mean(Eng$FirstDose)
## [1] 16397.2
#Table of First Doses given in Scotland
Scot <- UKVaccinationData3 %>%
filter(
areaName == "Scotland")
head(Scot)
#Total number of first doses in Scotland
sum(Scot$FirstDose)
## [1] 253443
#Average number of first doses in England
mean(Scot$FirstDose)
## [1] 1162.583
The total number of first doses given in England is 3,836,945 and in Scotland is 253,443. the average number given in a day in England was 16,397 and in Scotland was 1,162. England’s population being around 10x bigger than that of Scotland’s explains much of the significant difference between these values. However, increasing Scotland’s total first doses by 10-fold still leaves around 1,300,000 fewer. Infrastructure, investment, and socio-economic factors play a part in the rest of the difference. In future, doses should also be recorded as a percentage of population to allow this comparison.
Task 9
cor.test(UKVaccinationData2$SecondDose, UKVaccinationData2$FirstDose, method="pearson")
##
## Pearson's product-moment correlation
##
## data: UKVaccinationData2$SecondDose and UKVaccinationData2$FirstDose
## t = 44.944, df = 888, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8122185 0.8524729
## sample estimates:
## cor
## 0.8334481
model <- lm(UKVaccinationData2$SecondDose~UKVaccinationData2$FirstDose)
plot(UKVaccinationData3$FirstDose, UKVaccinationData3$SecondDose, col="red", main = "Relationship between First and Second Doses given each day", xlab = "First Doses given each day", ylab= "Second Doses given each day", abline(model))
summary(model)
##
## Call:
## lm(formula = UKVaccinationData2$SecondDose ~ UKVaccinationData2$FirstDose)
##
## Residuals:
## Min 1Q Median 3Q Max
## -49120 -1628 -1356 -408 22503
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.635e+03 1.916e+02 8.53 <2e-16 ***
## UKVaccinationData2$FirstDose 7.917e-01 1.761e-02 44.94 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5076 on 888 degrees of freedom
## Multiple R-squared: 0.6946, Adjusted R-squared: 0.6943
## F-statistic: 2020 on 1 and 888 DF, p-value: < 2.2e-16
The correlation between first and second doses given daily is 0.833. This represents a strong positive correlation. The adjusted R-squared value of 69.4% tells us that the model is a relatively good fit and leaves 30.6% of the data to be explained by other variables. This may include the likeliness of a booster or the year. Further analysis of these variables should be carried out.
Overall, this project corrects errors and outliers and conducts exploratory data analysis, showing that first and second doses tended to be relatively low. The relationship between them showed they both tended to increase together rather than one coming at the cost of the other. The data was collected evenly across the UK. The data showed that more people tended not to take a booster. Reasons for this could include scepticism and the general fear of the virus diminishing, although it was found attitudes remained similar in different countries. The evolution of the rollout was explored and showed first doses decreased as 2022 came around. The difference between total doses in England and Scotland show there was more factors affecting the difference than just population. The correlation between first and second doses showed there was potential of other factors at play, such as the year or booster uptake, which should be investigated.