Warning: package 'ggplot2' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.1 ✔ stringr 1.5.2
✔ ggplot2 4.0.3 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)library(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(plotly)
Warning: package 'plotly' was built under R version 4.5.2
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Rows: 3606803 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (11): X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#clean function for names so coding is easierflights <- flights %>%clean_names()
head(flights)
# A tibble: 6 × 11
origin destination origin_city destination_city passengers seats flights
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 MHK AMW Manhattan..KS Ames..IA X21 X30 X1
2 EUG RDM Eugene, OR Bend, OR 41 396 22
3 EUG RDM Eugene, OR Bend, OR 88 342 19
4 EUG RDM Eugene, OR Bend, OR 11 72 4
5 MFR RDM Medford, OR Bend, OR 0 18 1
6 MFR RDM Medford, OR Bend, OR 11 18 1
# ℹ 4 more variables: distance <chr>, fly_date <chr>, origin_population <chr>,
# destination_population <chr>
#Introduction #Research question-
#How did the average load factor of U.S. domestic flights change between 1998 and 2009
#How did the distribution of median average yearly flight load differ from 1998-2003 and 2004-2009?
#Source- #####This analysis follows a dataset containing detailed information on all recorded U.S. domestic flights from 1998-2009 published by the US Census.
#What is load factor? ###The load factor is a percentage based on the number of passengers per flight, dividied by the number of available seats.A higher load factor means more seats are filled, while a lower load factor means many seats are empty, suggesting underutilized flights. Analyzing the change in load factor is a great indication of the efficiency and profitability during economic hardship, and to better understand for future reference the determent a recession has on the travel habits within US airports.
#View raw data then convert it into character format to be able to be explored
I had to fix the error of the console reading my data as numeric when all values should be read as characters, I went from about 3.6 million original rows to 3.2 million rows after cleaning
Min. 1st Qu. Median Mean 3rd Qu. Max.
1990 1995 2001 2000 2005 2009
#We see there are 270 more passangers than seats and should further explore
sum(flights_clean$load_factor >1, na.rm =TRUE)
[1] 270
sum(flights_clean$load_factor <0, na.rm =TRUE)
[1] 0
#Explore how to fix this issue, in order to do so I must explore the culprit of this issue, whether it be thats the seats are recorded across entire cabin capacity or if passanger data is inconsistently recorded.
#In running the summary stats of the data set with this 270 concerning obersevations , one can see how extreme of a potential skew these data points have on the overall distriubtion.
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.001 1.036 1.085 1.146 1.120 11.057
#Choose to omit based on how extreme it skewed the datas load factors all over 100% and noteably inflating the maximum value. Then check to ensure the load factor has been properly cleaned and values omitted.
# A tibble: 2 × 2
period average_median
<chr> <dbl>
1 1998–2003 66.0
2 2004–2009 74.6
#Findings- #You can see the cluster from 1998-2003 is much more rigid than that of 2004-200
#74.58 − 66.04 = 8.54 percentage points
###The average yearly median increased by 8.54 percentage points between 1998-2003 and 2004-2009.
#Conclusion-
#The results were somewhat surprising because the data does not show an obvious decline in load factor during the later part of the study period like I hypothesized it would have due to such a stark drop in the economy. In fact, the median load factor was generally higher in 2004–2009 than in 1998–2003. This means that data as such cannot simply be used as the sole visualization to see the effects of immediate changes within the economy in industries such as aviation, rather a tool to watch how over the long haul, depressions may affect distributuions over longer time periods.
#One limitation one must keep in mind is the flight industry capacity has tripled since the 1990’s when accounting for that time periods datas dsitrubtions. As well that this analysis only examines load factor and does not include other varying factors that could influence airline travel, such as ticket prices,, fuel costs, route distance, airline type, or the number of flights in the air. Because of this, the results show an association and change over time , not a correlation. With more time, I would include economic and airline-specific variables to investigate how changes in the economy may have influenced passenger travel and flight occupancy. Future research can build on this exploration to further see how a roust market like the UNitef States may tend to trend toward in economic recessions.
#By continuing to monitor changes over time, researchers can identify how events such as economic recessions, pandemics directly affect flight occupancy rates, and overall revenue loss that would occur in the modern aviation system.