MATH1324 Applied data project 2

Yearly patronage - Metro Train

Ayaan Gouse s3977494, Shashank Somwarpet Madhusudhan s4021856, Shivam Shinde s3994666

Last updated: 15 October, 2023

Introduction

Introduction Cont.

Problem Statement

Data

Viewing Data

MonthlyTransportMode <- read.csv("Monthly public transport patronage by mode.csv")

knitr::kable(head(MonthlyTransportMode,5))
Year Month Month.name Metropolitan.train Metropolitan.tram Metropolitan.bus Regional.train Regional.coach Regional.bus
2018 1 January 16,809,932 15,231,368 7,568,547 1,466,256 116,568 721,229
2018 2 February 19,554,477 16,980,925 10,487,311 1,522,981 103,197 1,118,494
2018 3 March 22,659,010 19,832,126 11,528,895 1,809,774 117,180 1,224,816
2018 4 April 20,312,040 16,919,872 9,592,750 1,684,827 107,480 946,218
2018 5 May 22,768,447 17,691,427 11,263,486 1,790,656 109,456 1,258,704

Pre processing

Filtered and Tidy Data

knitr::kable(head(MonthlyTransportMode,5))
Year Month Month_name Metropolitan_train
2018 1 JAN 16809932
2018 2 FEB 19554477
2018 3 MAR 22659010
2018 4 APR 20312040
2018 5 MAY 22768447

Descriptive Statistics and Visualisation

MonthlyTransportMode %>% group_by(Year) %>% 
  summarise(Min = min(Metropolitan_train,na.rm = TRUE),
  Q1 = quantile(Metropolitan_train,probs = .25,na.rm = TRUE),
  Median = median(Metropolitan_train, na.rm = TRUE),
  Q3 = quantile(Metropolitan_train,probs = .75,na.rm = TRUE),
  Max = max(Metropolitan_train,na.rm = TRUE),
  Mean = mean(Metropolitan_train, na.rm = TRUE),
  SD = sd(Metropolitan_train, na.rm = TRUE),
  n = n(),
  Missing = sum(is.na(Metropolitan_train))) -> table1
knitr::kable(table1)
Year Min Q1 Median Q3 Max Mean SD n Missing
2018 16665365 19487047 20522070 22366512 22768447 20376272 2093401 12 0
2019 17074623 18969591 20503343 22295431 23045436 20398136 1957482 12 0
2020 1887499 3083157 5198012 9337947 19811543 7360162 6167034 12 0
2021 2769485 5740102 7667575 9689825 11852314 7661465 3058209 12 0
2022 5778986 11861630 12426505 12963626 13095346 11639507 2258858 12 0
2023 10109375 12902488 13201612 14806415 16527142 13530645 2217171 6 0

Data Visualisation - Histogram

plotNormalHistogram(MonthlyTransportMode$Metropolitan_train, col = '#7AC5CD', main = 'Patronage Distribution', length = 500)

ggplot(data = MonthlyTransportMode) + 
  stat_summary(
    mapping = aes(x = Year, y = Metropolitan_train),
    fun.min = min,
    fun.max = max,
    fun = median
  ) +
  labs(
    title = "Patronage by years in Metropolitan Trains",
    caption = "Data from discover.data.vic.gov.au",
    y = "Patronage Count (Million)"
  )

Outlier Visualisation

is.outlier = function(x){(x < summary(x)[2] - 1.5*IQR(x))|(x > summary(x)[5] + 1.5*IQR(x))}

sum(is.outlier(MonthlyTransportMode$Metropolitan_train))
## [1] 0
MonthlyTransportMode %>% boxplot(Metropolitan_train ~ Year, data = ., ylab = "Patronage(Million)")

Hypothesis Testing

Hypothesis Testing - Assumpiton of Normality

MonthlyTransportMode19$Metropolitan_train %>% qqPlot(dist = "norm", 
                                                     main = "Patronage in 2019") 

## [1] 1 5
MonthlyTransportMode20$Metropolitan_train %>% qqPlot(dist = "norm",
                                                     main = "Patronage in 2020")

## [1] 2 1

Hypothesis Testing - Levene’s Test

leveneTest(Metropolitan_train ~ factor(Year), data = MonthlyTransportMode19_20) %>% as.data.frame() -> ltest
knitr::kable(ltest)
Df F value Pr(>F)
group 1 4.818528 0.039
22 NA NA

Hypothesis Testing - Two sample t-test

t.test(
  Metropolitan_train ~ factor(Year),
  data = MonthlyTransportMode19_20,
  var.equal = FALSE,
  alternative = "two.sided"
  )
## 
##  Welch Two Sample t-test
## 
## data:  Metropolitan_train by factor(Year)
## t = 6.9804, df = 13.194, p-value = 8.881e-06
## alternative hypothesis: true difference in means between group 2019 and group 2020 is not equal to 0
## 95 percent confidence interval:
##   9008871 17067077
## sample estimates:
## mean in group 2019 mean in group 2020 
##           20398136            7360162
#differene in mean 
20398136 - 7360162
## [1] 13037974

Hypothesis Testing - Two sample t-test

A two-sample t-test was used to test for a significant difference between the patronage in the year 2019 and 2020. Upon inspection of the normal Q-Q plot we saw two data points showed a little deviation from the line but it is safe to assume the patronage for the years 2019 and 2020 exhibited normal distribution as they do not exhibit a non linear trend, so we can proceed with the t-test. The Levene’s test of homogeneity of variance indicated that equal variance could not be assumed. The results of the two-sample t-test assuming unequal variance found a statistically significant difference between the mean patronage in the year 2019 and 2020, t(df=13.194)=6.98, p=8.881e-06, 95% CI for the difference in means [9008871 17067077]. The results of the investigation suggest that patronage in 2020 have significantly dropped compared to the patronage in 2019.

Discussion

References

Victorian Government Aus (2023), Monthly public transport patronage by mode - Victorian Government Data Directory, viewed 13 October 2023, https://discover.data.vic.gov.au/dataset/monthly-public-transport-patronage-by-mode.

Applied Analytics, Module 7 Notes - viewed 14 October 2023, http://rare-phoenix-161610.appspot.com/secured/Module_07.html.

RPubs, MATH1324 Applied Analytics Assignment 2, rpubs.com, viewed 14 October 2023, https://rpubs.com/CaptainJackHarkness/906830