UK Railway Analysis

Srishti Puri

2024-05-22

Objective

Build exploratory dashboard of the UK Railway dataset

Results

About the dataset

View of the dataset

Description of the dataset

railway Descriptives
railway

18 Variables   31653 Observations

Transaction ID
nmissingdistinct
31653031653
lowest :00004864-a97f-4926-a3950003be8d-7821-479f-b9ec0003cbeb-0015-4324-a2370004beaa-152e-43a6-975f000727a7-00d7-43ec-911b
highest:fffb264d-3c93-4df2-9e9dfffdc471-6109-4fdd-9f76fffe804d-63d1-4e6b-a8eeffff0a05-731d-4e78-8b35ffff53f3-6638-4f24-93c7

Date of Purchase
image
          n    missing   distinct       Info       Mean        Gmd        .05 
      31653          0        128          1 2024-02-28      40.75 2024-01-07 
        .10        .25        .50        .75        .90        .95 
 2024-01-13 2024-01-30 2024-03-01 2024-03-31 2024-04-18 2024-04-24  
lowest :2023-12-082023-12-162023-12-192023-12-202023-12-27
highest:2024-04-262024-04-272024-04-282024-04-292024-04-30

Time of Purchase secs
nmissingdistinct
31653024351
lowest : 00:00:09 00:00:10 00:00:14 00:00:20 00:00:22 , highest: 23:59:43 23:59:44 23:59:46 23:59:51 23:59:57
Purchase Type
nmissingdistinct
3165302
 Value       Online Station
 Frequency    18521   13132
 Proportion   0.585   0.415 

Payment Method
image
nmissingdistinct
3165303
 Value      Contactless Credit Card  Debit Card
 Frequency        10834       19136        1683
 Proportion       0.342       0.605       0.053 

Railcard
image
nmissingdistinct
3165304
 Value         Adult Disabled     None   Senior
 Frequency      4846     3089    20918     2800
 Proportion    0.153    0.098    0.661    0.088 

Ticket Class
nmissingdistinct
3165302
 Value      First Class    Standard
 Frequency         3058       28595
 Proportion       0.097       0.903 

Ticket Type
image
nmissingdistinct
3165303
 Value       Advance  Anytime Off-Peak
 Frequency     17561     5340     8752
 Proportion    0.555    0.169    0.276 

Price
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
3165301250.99723.4427.17 2 3 511356780
lowest : 1 2 3 4 5 , highest: 216 235 238 242 267
Departure Station
image
nmissingdistinct
31653012
lowest :Birmingham New StreetBristol Temple Meads Edinburgh Waverley Liverpool Lime StreetLondon Euston
highest:London St Pancras Manchester PiccadillyOxford Reading York

Arrival Destination
image
nmissingdistinct
31653032
lowest :Birmingham New StreetBristol Temple Meads Cardiff Central Coventry Crewe
highest:Tamworth Wakefield Warrington Wolverhampton York

Date of Journey
image
          n    missing   distinct       Info       Mean        Gmd        .05 
      31653          0        121          1 2024-03-01      40.26 2024-01-08 
        .10        .25        .50        .75        .90        .95 
 2024-01-13 2024-01-31 2024-03-01 2024-03-31 2024-04-19 2024-04-25  
lowest :2024-01-012024-01-022024-01-032024-01-042024-01-05
highest:2024-04-262024-04-272024-04-282024-04-292024-04-30

Departure Time secs
image
nmissingdistinct
31653096
lowest : 00:00:00 00:15:00 00:30:00 00:45:00 01:00:00 , highest: 22:45:00 23:00:00 23:15:00 23:30:00 23:45:00
Arrival Time secs
nmissingdistinct
316530203
lowest : 00:00:00 00:05:00 00:10:00 00:15:00 00:20:00 , highest: 23:30:00 23:35:00 23:40:00 23:45:00 23:50:00
Actual Arrival Time secs
nmissingdistinct
297731880623
lowest : 00:00:00 00:05:00 00:10:00 00:15:00 00:20:00 , highest: 23:30:00 23:35:00 23:40:00 23:45:00 23:50:00
Journey Status
image
nmissingdistinct
3165303
 Value      Cancelled   Delayed   On Time
 Frequency       1880      2292     27481
 Proportion     0.059     0.072     0.868 

Reason for Delay
image
nmissingdistinct
4172274818
 Value          Signal failure     Signal Failure     Staff Shortage
 Frequency                 447                523                399
 Proportion              0.107              0.125              0.096
                                                                    
 Value                Staffing    Technical Issue            Traffic
 Frequency                 410                707                314
 Proportion              0.098              0.169              0.075
                                                 
 Value                 Weather Weather Conditions
 Frequency                 995                377
 Proportion              0.238              0.090 

Refund Request
nmissingdistinct
3165302
 Value         No   Yes
 Frequency  30535  1118
 Proportion 0.965 0.035 

Data Pre-processing

Data cleaning

railway <- railway %>%
  mutate(reason_for_delay = str_to_title(reason_for_delay))
## [1] NA                   "Signal Failure"     "Technical Issue"   
## [4] "Weather Conditions" "Weather"            "Staffing"          
## [7] "Staff Shortage"     "Traffic"

Identify missing values

##         Transaction ID       Date of Purchase       Time of Purchase 
##                      0                      0                      0 
##          Purchase Type         Payment Method               Railcard 
##                      0                      0                      0 
##           ticket_class            ticket_type                  price 
##                      0                      0                      0 
##      departure_station        arrival_station        date_of_journey 
##                      0                      0                      0 
##         departure_time scheduled_arrival_time    actual_arrival_time 
##                      0                      0                   1880 
##         journey_status       reason_for_delay         refund_request 
##                      0                  27481                      0

Data Exploration

Numerical variables

##   variable    mean  std_dev variation_coef p_01 p_05 p_25 p_50 p_75 p_95 p_99
## 1    price 23.4392 29.99763       1.279806    2    2    5   11   35   80  151
##   skewness kurtosis iqr range_98 range_80
## 1 2.467235 10.59155  30 [2, 151]  [3, 67]

Categorical variables

Ticket Class

##           var frequency percentage cumulative_perc
## 1    Standard     28595      90.34           90.34
## 2 First Class      3058       9.66          100.00

Ticket Type

##        var frequency percentage cumulative_perc
## 1  Advance     17561      55.48           55.48
## 2 Off-Peak      8752      27.65           83.13
## 3  Anytime      5340      16.87          100.00

Purchase Type

##       var frequency percentage cumulative_perc
## 1  Online     18521      58.51           58.51
## 2 Station     13132      41.49          100.00

Railcard

##        var frequency percentage cumulative_perc
## 1     None     20918      66.09           66.09
## 2    Adult      4846      15.31           81.40
## 3 Disabled      3089       9.76           91.16
## 4   Senior      2800       8.85          100.00

Reason for Delay

##                  var frequency percentage cumulative_perc
## 1               <NA>     27481      86.82           86.82
## 2            Weather       995       3.14           89.96
## 3     Signal Failure       970       3.06           93.02
## 4    Technical Issue       707       2.23           95.25
## 5           Staffing       410       1.30           96.55
## 6     Staff Shortage       399       1.26           97.81
## 7 Weather Conditions       377       1.19           99.00
## 8            Traffic       314       0.99          100.00

Temporal variables

Explore relationships

Price vs. Journey Status

Cross-tabulation Journey Status vs. Ticket Type

##            
##             Advance Anytime Off-Peak
##   Cancelled    1041     365      474
##   Delayed      1211     486      595
##   On Time     15309    4489     7683

Price

Peak travel time

## # A tibble: 24 × 2
##    departure_hour count
##    <chr>          <int>
##  1 00               853
##  2 01               644
##  3 02               942
##  4 03               543
##  5 04              1041
##  6 05               725
##  7 06              3112
##  8 07              2795
##  9 08              2179
## 10 09              1230
## # ℹ 14 more rows

Revenue from different ticket types & classes

## # A tibble: 6 × 3
##   ticket_type ticket_class total_revenue
##   <chr>       <chr>                <dbl>
## 1 Advance     First Class          57015
## 2 Advance     Standard            204169
## 3 Anytime     First Class          37841
## 4 Anytime     Standard            171468
## 5 Off-Peak    First Class          36996
## 6 Off-Peak    Standard            142514

Diagnose on-time performance and contributing factors

On-time performance of journeys from January to April 2024.

## # A tibble: 1 × 6
##   total_journeys on_time_journeys delayed_journeys cancelled average_delay
##            <int>            <int>            <int>     <int>         <dbl>
## 1          26989            23214             2120      1655          3.65
## # ℹ 1 more variable: median_delay <dbl>

Diagnose on-time performance by Route

Route by on-time performance

Reasons for Delay

Correlation of price and delay_minutes

## # A tibble: 7 × 4
##   reason_for_delay   total_delays average_delay median_delay
##   <chr>                     <int>         <dbl>        <dbl>
## 1 Weather                     758          46.8         48  
## 2 Technical Issue             472          24.9         24  
## 3 Signal Failure              420          53.0         37  
## 4 Staffing                    172          25.9         20.5
## 5 Staff Shortage              154          83.9         59  
## 6 Traffic                      87          32.3         26  
## 7 Weather Conditions           57          46.6         45

Diagnose cancelled rides

## # A tibble: 1 × 3
##   total_journeys cancelled_journeys cancellation_rate
##            <int>              <int>             <dbl>
## 1          26989               1655              6.13

Reason for Cancellations

## # A tibble: 7 × 2
##   reason_for_delay   total_cancellations
##   <chr>                            <int>
## 1 Signal Failure                     461
## 2 Technical Issue                    217
## 3 Staffing                           204
## 4 Staff Shortage                     199
## 5 Weather                            197
## 6 Traffic                            195
## 7 Weather Conditions                 182

Refund requests by journey

Combined analysis: Refund requests and on-time performance