November 16, 2024
What if there was a way to predict within a much smaller range how long a particular flight would take?
Spoiler alert: We can do that by looking for correlations between flight time and other flight data that we have.
# Data frame is named fl_timedist # We'll use the lm function to perform the fit. # The first argument is a "formula" of the # form [response variable] ~ [predicting variable] lin_reg <- lm(air_time ~ distance, data=fl_timedist) lin_reg
## ## Call: ## lm(formula = air_time ~ distance, data = fl_timedist) ## ## Coefficients: ## (Intercept) distance ## 18.7348 0.1187
## ## Call: ## lm(formula = air_time ~ distance, data = fl_timedist) ## ## Coefficients: ## (Intercept) distance ## 18.7348 0.1187
\(\hat{\beta}_0\) (y-intercept) \(=18.7348\), \(\hat{\beta}_1\) (slope) \(=0.1187\)
We can therefore estimate the flight time (in-air) of any flight with the formula \(time = 18.7348+(0.1187*distance)\)
0.1187 is in minutes/mile, therefore:
1/0.1187 \(\approx\) 8.425 miles/minute \(\approx\) 505.5 miles/hour
Data Set: nycflights13
Logo: Vecteezy