Source: Psi Chi R
Contest
#Load packages and import data
#install.packages(ggplot2,dplyr,lubridate,readr)
library(ggplot2)
library(dplyr)
library(readr)
theme_set(theme_bw())
december=read.csv('C:/Users/alanh/Documents/R/Flight Data December 2023 Contest.csv')
Level 1-
Provide descriptive statistics for the actual_flown_miles variable.
Indicate the minimum number of miles flow, the
maximum number of miles flow, the
average number of miles flown, and the
median number of miles flown.
sum(is.na(december$actual_flown_miles))
## [1] 0
min(december$actual_flown_miles,na.rm = T) #Minimum = 45
## [1] 45
max(december$actual_flown_miles,na.rm=T) #Maximum = 8440
## [1] 8440
mean(december$actual_flown_miles,na.rm=T) #Average = 2477.738
## [1] 2477.738
median(december$actual_flown_miles,na.rm=T) #Median = 1846
## [1] 1846
Level 2-
Describe the relationship between satisfaction (satisfaction_score)
and delay time (arrival_delay_minutes). Note that for satisfaction_score
a value of 1 is the lowest (dissatisfied) and 5 is the highest
(satisfied). Note that negative values in the arrival delay minutes mean
the flight was early, while positive values indicate the flight was
late.
summary(december$satisfaction_score) #transform from char into numeric
## Length Class Mode
## 47074 character character
summary(december$arrival_delay_minutes)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -104.000 -19.000 -9.000 -1.702 4.000 907.000
december$satisfaction_score=as.numeric(december$satisfaction_score)
december$arrival_delay_minutes=as.numeric(december$arrival_delay_minutes)
december1=december %>%
filter(complete.cases(satisfaction_score))
december2=december1 %>%
filter(complete.cases(arrival_delay_minutes))
cor.test(december2$satisfaction_score,december2$arrival_delay_minutes) #p-value < 2.2e-16, cor -0.07935616
##
## Pearson's product-moment correlation
##
## data: december2$satisfaction_score and december2$arrival_delay_minutes
## t = -14.885, df = 34961, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.08976354 -0.06893144
## sample estimates:
## cor
## -0.07935616
Level 3-
Does satisfaction level (satisfaction_score) vary by the cabin
(cabin_code) that they’re in?
summary(december2$satisfaction_score)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.000 3.000 2.876 4.000 5.000
december2 %>%
ggplot(aes(x=cabin_code,y=satisfaction_score,fill=satisfaction_type))+
geom_col()+
labs(title='Satisfaction Score by Cabin Type',y='Satisfaction Score',x='Cabin Type',fill='Satisfaction Type')+
theme(plot.title = element_text(hjust=.5))

#Yes. Per the column chart, there are varying levels of satisfaction by cabin type.
Level 4-
Describe the relationship between loyalty program membership
(loyalty_program_level) and satisfaction (satisfaction_score). Hint:
you’ll have to do some recoding for folks who don’t belong to a
program
december3=december2 %>%
filter(complete.cases(loyalty_program_level))
#Rename blanks as NA
december3$loyalty_program_level[december3$loyalty_program_level==""]="Non-Membership"
december3 %>%
ggplot(aes(y=loyalty_program_level,x=satisfaction_score,fill=satisfaction_type))+
geom_col()+
labs(title='Loyalty and Satisfaction',y='Program Membership',x='Satisfaction Score',fill='Satisfaction Type')+
theme(plot.title = element_text(hjust=.5))

LS0tDQp0aXRsZTogJ1BzaSBDaGkgUiBDb250ZXN0IC0gRGVjIDIwMjMnDQphdXRob3I6ICdCeSBBbGFuIExhbScNCm91dHB1dDoNCiAgaHRtbF9kb2N1bWVudDoNCiAgICBhbHdheXNfYWxsb3dfaHRtbDogeWVzDQogICAgZGZfcHJpbnQ6IHBhZ2VkDQogICAgdG9jOiB5ZXMNCiAgICB0b2NfZmxvYXQ6IHllcw0KICAgIG51bWJlcl9zZWN0aW9uczogbm8NCiAgICBhbmNob3Jfc2VjdGlvbnM6IFRSVUUNCiAgICBjb2RlX2ZvbGRpbmc6IGhpZGUNCiAgICBjb2RlX2Rvd25sb2FkOiB0cnVlDQotLS0NCg0KWyoqU291cmNlKio6IFBzaSBDaGkgUiBDb250ZXN0XShodHRwczovL29zZi5pby9yODZwMi8pDQoNCg0KYGBge3Igc2V0dXAsaW5jbHVkZT1GfQ0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KG1lc3NhZ2U9Rix3YXJuaW5nPUYsZWNobyA9IFQpDQpgYGANCg0KYGBge3J9DQojTG9hZCBw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