Show the code
pacman::p_load(ggplot2, nycflights13, pander)
correlation <- cor(flights$dep_delay, flights$arr_delay, use = "complete.obs")
pander(correlation)0.9148
For this analysis, we investigate the relationship between departure delays and arrival delays of flights. Our goal is to determine whether departure delays can reliably predict arrival delays, providing actionable insights for airlines to improve scheduling and communication.
\underbrace{Y_i}_\text{Arrival delays} = \overbrace{\beta_0}^\text{y-int} + \overbrace{\beta_1}^\text{slope} \underbrace{X_i}_\text{Departure delays} + \epsilon_i \quad \text{where} \ \epsilon_i \sim N(0, \sigma^2)
\left.\begin{array}{ll} H_0: \beta_1 = 0 \\ H_a: \beta_1 \neq 0 \end{array} \right\} \ \text{Is there a relationship between departure delays and arrival delays?}
pacman::p_load(ggplot2, nycflights13, pander)
correlation <- cor(flights$dep_delay, flights$arr_delay, use = "complete.obs")
pander(correlation)0.9148
The high correlation value (0.9148) indicates a strong positive relationship between departure delay and arrival delay.
The scatterplot visually confirms this relationship, showing a near-linear pattern where longer departure delays are associated with longer arrival delays.
ggplot(flights, aes(x = dep_delay, y = arr_delay)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", color = "blue") +
labs(title = "Scatterplot of Departure Delay vs. Arrival Delay",
x = "Departure Delay (minutes)",
y = "Arrival Delay (minutes)")The scatterplot shows a clear linear relationship between departure and arrival delays, with the regression line supporting the positive trend.
# Fit the linear regression model
model <- lm(arr_delay ~ dep_delay, data = flights)
pander(summary(model))| Estimate | Std. Error | t value | Pr(>|t|) | |
|---|---|---|---|---|
| (Intercept) | -5.899 | 0.03302 | -178.7 | 0 |
| dep_delay | 1.019 | 0.0007864 | 1296 | 0 |
| Observations | Residual Std. Error | R^2 | Adjusted R^2 |
|---|---|---|---|
| 327346 | 18.03 | 0.8369 | 0.8369 |
Final Estimated Linear Equation:
\underbrace{Y_i}_\text{Arrival delays} = \overbrace{\beta_0}^\text{-5.90} + \overbrace{\beta_1}^\text{1.02} \underbrace{X_i}_\text{Departure delays}
On average, a flight with no departure delay will have a small negative arrival delay (~5.9 minutes early).
For each minute of departure delay, the arrival delay increases by approximately 1.019 minutes, indicating a strong linear relationship.
delays <- data.frame(dep_delay = c(15, 30, 60))
predictions <- predict(model, delays)
prediction_table <- cbind(delays, predictions)
pander(prediction_table, caption = "Predicted Arrival Delays for Given Departure Delays")| dep_delay | predictions |
|---|---|
| 15 | 9.387 |
| 30 | 24.67 |
| 60 | 55.25 |
A flight with a 15-minute departure delay is predicted to have a ~9.39-minute arrival delay.
A flight with a 30-minute departure delay is predicted to have a ~24.67-minute arrival delay.
# Diagnostic Plots
par(mfrow = c(1, 2))
plot(model, which = c(1, 2))Residuals vs. Fitted: Residuals are scattered randomly, confirming linearity and homoscedasticity.
Q-Q Plot: Residuals align well with the diagonal, confirming normality.
Reject the Null Hypothesis: There is a statistically significant relationship between departure delays and arrival delays p<0.001.
Strength of the Model: The adjusted value of 0.8369 indicates that the model explains ~83.7% of the variability in arrival delays.
Future Studies:
Include additional predictors such as weather conditions or flight distance to improve the model’s predictive accuracy.
Investigate non-linear relationships for extreme delay scenarios.