# Loading necessary libraries

library(tidyverse)
## ── 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
library(lubridate)
library(dplyr)
# 1: Loading the CSV data file

data <- read.csv("York_Footfall_data.csv")
# 2: Check data integrity/quality
summary(data)
##      Date             SiteName         LocationName         WeekDay         
##  Length:8204        Length:8204        Length:8204        Length:8204       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    TotalCount      Recording_ID   
##  Min.   :   402   Min.   :    25  
##  1st Qu.:  7454   1st Qu.:253536  
##  Median : 16990   Median :501403  
##  Mean   : 16854   Mean   :500099  
##  3rd Qu.: 22808   3rd Qu.:746919  
##  Max.   :328310   Max.   :999828  
##  NA's   :10       NA's   :100
glimpse(data)
## Rows: 8,204
## Columns: 6
## $ Date         <chr> "2015-01-01", "2015-01-01", "2015-01-01", "2015-01-01", "…
## $ SiteName     <chr> "York", "York", "York", "York", "York", "York", "York", "…
## $ LocationName <chr> "Church Street", "Coney Street", "Micklegate", "Parliamen…
## $ WeekDay      <chr> "Thursday", "Thursday", "Thursday", "Thursday", "Thursday…
## $ TotalCount   <int> 1952, 12220, 5559, 7802, 14004, 3451, 31495, 7055, 25427,…
## $ Recording_ID <int> 375836, 724862, 451020, 523989, 382272, 464381, 654292, 9…
sum(is.na(data))
## [1] 110
# 3: Summary table for each location
summary_table <- data %>%
  group_by(LocationName) %>%
  summarise(
    first_day = min(Date, na.rm = TRUE),
    last_day = max(Date, na.rm = TRUE),
    mean_footfall = mean(TotalCount, na.rm = TRUE),
    sd_footfall = sd(TotalCount, na.rm = TRUE),
    max_footfall = max(TotalCount, na.rm = TRUE),
    min_footfall = min(TotalCount, na.rm = TRUE)
  )

summary_table
## # A tibble: 6 × 7
##   LocationName         first_day last_day mean_footfall sd_footfall max_footfall
##   <chr>                <chr>     <chr>            <dbl>       <dbl>        <int>
## 1 Church Street        2015-01-… 2017-06…         4352.       1389.        26848
## 2 Coney Street         2015-01-… 2019-12…        23507.       6608.        51050
## 3 Micklegate           2015-01-… 2019-12…         7487.       4800.        98180
## 4 Parliament Street    2015-06-… 2019-12…        22631.       6610.        53749
## 5 Parliament Street a… 2015-01-… 2015-06…        22432.       7750.        53057
## 6 Stonegate            2015-01-… 2019-12…        19902.      17826.       328310
## # ℹ 1 more variable: min_footfall <int>
# 4: Filter for year 2019 data
data_2019 <- data %>%
  filter(year(Date) == 2019)
# 5: Plot distribution of footfall by location
ggplot(data_2019, aes(x = TotalCount, fill = LocationName)) +
  geom_histogram(alpha = 0.6, position = 'identity') +
  facet_wrap(~ LocationName) +
  labs(title = "Distribution of Footfall by Location in 2019", x = "TotalCount", y = "Count")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#box plot

library(ggplot2)

ggplot(data_2019, aes(x = LocationName, y = TotalCount, fill = LocationName)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Boxplot of Footfall by Location in 2019",
       x = "Location",
       y = "Total Count") +
  theme_minimal() +  # A cleaner theme
  theme(legend.position = "none")  # Remove legend if not needed

# 6: Filtering data for Coney Street and Stonegate

filtered_data <- data_2019 %>%
  filter(LocationName %in% c("Coney Street", "Stonegate"))

# Performing t-test
t_test_result <- t.test(TotalCount ~ LocationName, data = filtered_data)

# Printing the results
print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  TotalCount by LocationName
## t = 3.3611, df = 699.18, p-value = 0.0008186
## alternative hypothesis: true difference in means between group Coney Street and group Stonegate is not equal to 0
## 95 percent confidence interval:
##   670.9189 2555.7989
## sample estimates:
## mean in group Coney Street    mean in group Stonegate 
##                   20817.45                   19204.09
# 7: T-test comparing Coney Street and Stonegate on weekends only


weekend_data <- data_2019 %>%
  filter(LocationName %in% c("Coney Street", "Stonegate") & wday(Date, label = TRUE) %in% c("Sat", "Sun"))

# Separate by location and perform t-test


t_test_weekends <- t.test(
  weekend_data %>% filter(LocationName == "Coney Street") %>% pull(TotalCount),
  weekend_data %>% filter(LocationName == "Stonegate") %>% pull(TotalCount)
)

t_test_weekends
## 
##  Welch Two Sample t-test
## 
## data:  weekend_data %>% filter(LocationName == "Coney Street") %>% pull(TotalCount) and weekend_data %>% filter(LocationName == "Stonegate") %>% pull(TotalCount)
## t = -0.29072, df = 203.88, p-value = 0.7716
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2362.601  1755.409
## sample estimates:
## mean of x mean of y 
##  25863.37  26166.96
# Printing results

list(Summary_Table = summary_table, T_Test_Weekends = t_test_weekends)
## $Summary_Table
## # A tibble: 6 × 7
##   LocationName         first_day last_day mean_footfall sd_footfall max_footfall
##   <chr>                <chr>     <chr>            <dbl>       <dbl>        <int>
## 1 Church Street        2015-01-… 2017-06…         4352.       1389.        26848
## 2 Coney Street         2015-01-… 2019-12…        23507.       6608.        51050
## 3 Micklegate           2015-01-… 2019-12…         7487.       4800.        98180
## 4 Parliament Street    2015-06-… 2019-12…        22631.       6610.        53749
## 5 Parliament Street a… 2015-01-… 2015-06…        22432.       7750.        53057
## 6 Stonegate            2015-01-… 2019-12…        19902.      17826.       328310
## # ℹ 1 more variable: min_footfall <int>
## 
## $T_Test_Weekends
## 
##  Welch Two Sample t-test
## 
## data:  weekend_data %>% filter(LocationName == "Coney Street") %>% pull(TotalCount) and weekend_data %>% filter(LocationName == "Stonegate") %>% pull(TotalCount)
## t = -0.29072, df = 203.88, p-value = 0.7716
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2362.601  1755.409
## sample estimates:
## mean of x mean of y 
##  25863.37  26166.96

Section 2

Assignment Summary Report: Footfall Data Analysis (2019)

Introduction

This report presents an analysis of footfall data collected in 2019, specifically comparing the footfall counts at two locations: Coney Street and Stonegate. The objective of this analysis is to identify any significant differences in footfall patterns between these locations.

Data Overview

The dataset contains footfall counts recorded at various locations. The key variables in this analysis include:

Location Name: Represents the name of the location (Coney Street and Stonegate). Total Count: Represents the total footfall count recorded at each location. Visual Analysis A boxplot was generated to visualize the distribution of footfall counts at Coney Street and Stonegate.

Key Observations:

Coney Street exhibited a wider range of footfall counts, indicating greater variability. The median footfall count at Coney Street appeared higher compared to Stonegate, suggesting that more people frequent this location on average. Statistical Analysis A two-sample t-test was conducted to assess whether there is a statistically significant difference in footfall counts between Coney Street and Stonegate.

Results: T-Statistic: -0.29072 Degrees of Freedom: 203.88 P-Value: 0.7716 Confidence Interval: -2362.601 1755.409 Mean Footfall for Coney Street: 25863.37 26166.96 Mean Footfall for Stonegate:

Interpretation: A p-value less than 0.05 indicates a statistically significant difference in footfall counts between the two locations, suggesting that factors influencing footfall may differ. Conversely, a p-value greater than 0.05 would imply no significant difference. Conclusion The analysis revealed notable differences in footfall counts between Coney Street and Stonegate. The findings suggest that Coney Street attracts more foot traffic on average, with greater variability in footfall counts. Understanding these differences is essential for businesses and stakeholders in optimizing their operations and marketing strategies.