Introduction

This report seeks to answer several questions related mainly to departure times and causes of late departure of NYC flights in 2013. We will be exploring the relationships between delayed flights and weather as well as cancelled flights.

We will be using a data set called flights from the tidyverse package nycflights13. It contains information for all flights that departed from NYC in the year 2013. There are a total of 18 variables to describe each flight. year day and month describe the day of departure, dep_time and arr_time describe the actual departure and arrival times, sched_dep_time and sched_arr_time describe the scheduled arrival and departure times, dep_delay and arr_delay describe departure and arrival delays from the scheduled times in minutes, carrier describes the airline carrier for the flight, tailnum describes the tail number of the plane for the flight, origin and dest describe the origin and destination airports, air_time describes the amount of time in minutes the flight was in the air, distance is the distance in miles of the flight, hour and minute describe time of departure broken into hour and minutes.

Throughout, we will need the functionality of the tidyverse package.

library(tidyverse)

Noteworthy Delay and Cancellation Metrics

One thing that is important to look at is how often certain flights are delayed or cancelled. The first thing that this report will examine is the percentages of flights that were either delayed by an hour or more or cancelled.

flights %>%
  group_by(month, day) %>%
  summarize(can_or_del = 
              (mean((is.na(dep_delay)) | dep_delay >= 60)) * 100 ) %>%
  filter(can_or_del >= 35) %>%
  arrange(desc(can_or_del))
## # A tibble: 12 × 3
## # Groups:   month [7]
##    month   day can_or_del
##    <int> <int>      <dbl>
##  1     2     9       61.5
##  2     3     8       59.0
##  3     2     8       54.6
##  4     5    23       44.1
##  5     7     1       42.7
##  6     9    12       40.7
##  7    12     5       39.8
##  8     6    28       37.4
##  9     7    23       36.6
## 10     7    10       36.3
## 11     6    24       35.4
## 12     9     2       35.2

Here we can see the percentage of flights cancelled or delayed by over an hour on each specific day, filtering out days that had a percentage less than 35%. It returns a list of 12 days with abnormally high cancellation or delay percentages.

A reasonable hypothesis could be that the weather in New York City on those days was particularly bad. On 2/ 8 and 2/9, the weather was likely a large factor since there was a snowstorm a most of the day on 2/8 that lasted into 2/9. 3/8 was quite foggy with some ice and snow. 5/23 was a little rainy, but there was likely another reason the percentage was high that day. 6/24 was sunny and not very windy weather was almost certainly not the cause for the high percentage. 6/28 was a little cloudy although weather probably not the cause either. 7/1 was overcast and a little foggy, which may have been a small factor but likely not the main cause. 7/10 was a little cloudy, again likely not the main cause for delays. 7/23 has some early morning rain and scattered clouds, but again, probably not the reason for delays. 9/2 had a lot of rain and fog likely causing some delays but probably not any cancellations. 9/12 was clear for a lot of the day with some haze and fog in the evening which could have played a role. 12/5 was overcast and foggy probably contributing minorly to the delays. Overall, I think the weather in New York City was certainly a factor but not the only factor causing delays and cancellations

Next, this report will zoom in on specific hours of the day to see when the most delays and cancellations occured.

flights_w_can_or_del_hour <- flights %>%
  group_by(hour) %>%
  summarize(can_del_per = (mean((is.na(dep_delay)) | dep_delay >= 60)) * 100,
            count = n()) %>%
  arrange(hour)
ggplot(data = flights_w_can_or_del_hour) +
  geom_line(mapping = aes(x = hour, y = can_del_per)) +
  labs(x = "Hour",
       y = "Cancellation or Delay Percentage",
       title = "Percentage of Flights Cancelled or Delayed by at Least An Hour Per Hour") +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23))

This returns a graph depicting how many flights were either cancelled or delayed at least an hour broken down by hour.

This graph shows a spike around 1 AM which is an outlier becuase there was only one scheduled flight at that time and it got cancelled. Other than that, there is a noticeable increase in the amount of flights cancelled or delayed as the day goes on peaking at 9 and then tapering off. I think that this happens because as the day begins, many flights are on time but as soon as there is a delay at one gate, it can make the next flight after it late and so on. This snowball effect causes more flights to be delayed or cancelled as they day goes on. Another explanation is that the volume of flights also increases as the day goes on, so more total flights get delayed or cancelled as a result. There is a drop off after 9:00 pm which tells us that either there are probably not a lot of flights scheduled after 9 and the airport has time to catch up and space to move flights to unoccupied gates to get them out on time.

Based on the chart, the riskiest time of day to fly would be 9 pm. This likely means that between 9 and 10 pm is when the airport is the most backed up and likely a lot of flights arrive around 9 creating congestion.

Next, this report will find the flights that left either on time or early on those days that had large cancellation or delay percentages.

flights_on_time <- flights %>%
  filter(((month == 2) & (day == 8 | day == 9)) | ((month == 3) & (day == 8)) | 
           ((month == 5) & (day == 23)) | ((month == 6) & (day == 24 | day == 28)) | 
           ((month == 7) & (day == 1 | day == 10 | day == 23)) | 
           ((month == 9) & (day == 2 | day == 12)) | 
           ((month == 12) & (day == 5))) %>%
  filter(dep_delay <= 0)

This data set includes the flights that were able to leave on time or early despite the day having large cancellation or delay percentages.

A potential explanation for why these flights were able to leave on time/early is that they were able to get out before any bad weather occurred on those days.

flights_on_time %>%
  group_by(month, day) %>%
  summarize(avg_scheduled_dep_hour = mean(hour))
## # A tibble: 12 × 3
## # Groups:   month [7]
##    month   day avg_scheduled_dep_hour
##    <int> <int>                  <dbl>
##  1     2     8                   8.86
##  2     2     9                  17.0 
##  3     3     8                  10.2 
##  4     5    23                   9.45
##  5     6    24                   9.82
##  6     6    28                  10.1 
##  7     7     1                   9.43
##  8     7    10                   9.60
##  9     7    23                  10.0 
## 10     9     2                   9.85
## 11     9    12                   9.03
## 12    12     5                  10.1

The average departure hour for the flights on these days were mostly in the morning, this makes sense as the bad weather usually hit later on and the early flights were able to avoid it.

2/9 has an average departure hour in the afternoon despite the trend. However, there was a snowstorm that morning meaning that the afternoon flights were likely the ones that made it out on time. That’s when they were able to clear the snow and ice.

Conclusions

The Flights data set contains a lot of useful insight into why flights were cancelled or delayed in NYC in 2013. Firstly, from Flights this report was able to isolate dates when there was a large percentage of cancellations or delays. This isolation was analyzed and it was found that the weather in NYC does play a factor when it comes to having a lot of cancellations and delays. The cancellation and delay percentage was further broken down by hour and this was interpreted to show that less risky to fly later at night or early in the morning (excluding the outlier flight at 1 am). Then, the flights that were able to leave either on time or early on the problematic days were also isolated. It was found that those flights typically left before bad weather started. The average hour of departure for each day confirmed this