2025-06-08

Topic: Simple Linear Regression

Goal: Produce the best fit model to predict a flight’s arrival delay time for Denver International Airport.

Data: The five causes of arrival delay will be used as the independent variables: Carrier, Weather, NAS, Security, Late Aircraft.

Context:

Negative arrival delay time -> flight arrived early.

Positive arrival delay time -> flight arrived late.

An arrival time of 0 -> flight arrived on time.

Data obtained from United States Department of Transportation:

https://www.bts.gov

Number of Arrival Delays in February 2025

Linear regression

## 
## Call:
## lm(formula = ARR_DELAY ~ CARRIER_DELAY + WEATHER_DELAY + NAS_DELAY + 
##     SECURITY_DELAY + LATE_AIRCRAFT_DELAY, data = delays)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -4.461e-11 -7.000e-15 -3.000e-15  0.000e+00  5.863e-11 
## 
## Coefficients:
##                       Estimate Std. Error    t value Pr(>|t|)    
## (Intercept)         -5.161e-13  2.491e-14 -2.072e+01   <2e-16 ***
## CARRIER_DELAY        1.000e+00  2.631e-16  3.801e+15   <2e-16 ***
## WEATHER_DELAY        1.000e+00  6.067e-16  1.648e+15   <2e-16 ***
## NAS_DELAY            1.000e+00  5.779e-16  1.730e+15   <2e-16 ***
## SECURITY_DELAY       1.000e+00  1.650e-14  6.060e+13   <2e-16 ***
## LATE_AIRCRAFT_DELAY  1.000e+00  2.911e-16  3.435e+15   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.306e-12 on 4657 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 5.304e+30 on 5 and 4657 DF,  p-value: < 2.2e-16

Linear Regression Model

\[ \text{Linear Regression Formula} \\ \hat{Y} = \beta_0 + \beta_1X_1 + \beta_2X_2 + \dots + \beta_nX_n \] \[ \text{The best fit linear regression model is: } \] \[ \hat{Y} = -5.161 \times 10^{-13} + 1.000 \cdot \text{CARRIERDELAY} \\ + 1.000 \cdot \text{WEATHERDELAY} \\ + 1.000 \cdot \text{NASDELAY} \\ + 1.000 \cdot \text{SECURITYDELAY} \\ + 1.000 \cdot \text{LATEAIRCRAFTDELAY} \\ \]

Linear regression plot

Top 5 Arrival Flight Origins

Average Delay Times for Top 5 arrival Origins

\[ \begin{aligned} \text{PHX} &= -1.67\ \text{minutes} \\ \text{SLC} &= 5.29\ \text{minutes} \\ \text{LAS} &= 3.16\ \text{minutes} \\ \text{LAX} &= -2.79\ \text{minutes} \\ \text{DWF} &= 2.14\ \text{minutes} \\ \end{aligned} \] On average, PHX and LAX had early arrival flights to Denver.

SLC, LAS, and DWF on average had delayed arrival flights to Denver.

R Code for Plots

## Bar Plot for the Arrival Delays in February
ggplot(delayNum, aes(x = DAY_OF_MONTH, y = n)) +
  geom_bar(stat = "identity", fill = "#5D3FD3") +
  labs(title = "Arrival Delays to Denver (DEN) by Day of Month",
       x = "Day of the Month",
       y = "Number of Delays") + 
  theme_minimal()
# Actual and Predicted Model
ggplot(delays, aes(x = ARR_DELAY, y = predicted)) +
  geom_point(alpha = 0.6, color = "#5D3FD3") +
  geom_abline(slope = 1, intercept = -5.161e-13, 
              color = "black", linetype = "dashed") +
  labs(title = "Linear Regression Model for Arrival Delay",
       x = "Actual Arrival Delay",
       y = "Predicted Arrival Delay") +
  theme_minimal()

R Code For Plots

barplot(
  height = top5$Flights,
  names.arg = top5$ORIGIN,
  col = "#5D3FD3",
  main = "Top 5 Origin Airports to Denver (DEN)",
  xlab = "Origin Airpot",
  ylab = "Number of Flights",
  las = 1,  
  ylim = c(0,1000)