2.b Read the data
Load the titanic data file
air.df <- read.csv(paste("SixAirlinesDataV2.csv", sep=""))
View the data
View(air.df)
summary(air.df)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 74 AirBus:151 Min. : 1.250 Aug:127
## British :175 Boeing:307 1st Qu.: 4.260 Jul: 75
## Delta : 46 Median : 7.790 Oct:127
## Jet : 61 Mean : 7.578 Sep:129
## Singapore: 40 3rd Qu.:10.620
## Virgin : 62 Max. :14.660
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 40 Min. : 78.0 Min. : 8.00 Min. :30.00
## International:418 1st Qu.:133.0 1st Qu.:21.00 1st Qu.:31.00
## Median :185.0 Median :36.00 Median :31.00
## Mean :202.3 Mean :33.65 Mean :31.22
## 3rd Qu.:243.0 3rd Qu.:40.00 3rd Qu.:32.00
## Max. :389.0 Max. :66.00 Max. :33.00
## PitchPremium WidthEconomy WidthPremium PriceEconomy
## Min. :34.00 Min. :17.00 Min. :17.00 Min. : 65
## 1st Qu.:38.00 1st Qu.:18.00 1st Qu.:19.00 1st Qu.: 413
## Median :38.00 Median :18.00 Median :19.00 Median :1242
## Mean :37.91 Mean :17.84 Mean :19.47 Mean :1327
## 3rd Qu.:38.00 3rd Qu.:18.00 3rd Qu.:21.00 3rd Qu.:1909
## Max. :40.00 Max. :19.00 Max. :21.00 Max. :3593
## PricePremium PriceRelative SeatsTotal PitchDifference
## Min. : 86.0 Min. :0.0200 Min. : 98 Min. : 2.000
## 1st Qu.: 528.8 1st Qu.:0.1000 1st Qu.:166 1st Qu.: 6.000
## Median :1737.0 Median :0.3650 Median :227 Median : 7.000
## Mean :1845.3 Mean :0.4872 Mean :236 Mean : 6.688
## 3rd Qu.:2989.0 3rd Qu.:0.7400 3rd Qu.:279 3rd Qu.: 7.000
## Max. :7414.0 Max. :1.8900 Max. :441 Max. :10.000
## WidthDifference PercentPremiumSeats
## Min. :0.000 Min. : 4.71
## 1st Qu.:1.000 1st Qu.:12.28
## Median :1.000 Median :13.21
## Mean :1.633 Mean :14.65
## 3rd Qu.:3.000 3rd Qu.:15.36
## Max. :4.000 Max. :24.69
library(psych)
attach(air.df)
describe(air.df$FlightDuration)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 7.58 3.54 7.79 7.57 4.81 1.25 14.66 13.41 -0.07 -1.12
## se
## X1 0.17
describe(SeatsEconomy)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 202.31 76.37 185 194.64 85.99 78 389 311 0.72 -0.36
## se
## X1 3.57
describe(SeatsPremium)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 33.65 13.26 36 33.35 11.86 8 66 58 0.23 -0.46
## se
## X1 0.62
describe(PitchEconomy)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 31.22 0.66 31 31.26 0 30 33 3 -0.03 -0.35
## se
## X1 0.03
describe(PitchPremium)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 37.91 1.31 38 38.05 0 34 40 6 -1.51 3.52
## se
## X1 0.06
describe(WidthEconomy)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 458 17.84 0.56 18 17.81 0 17 19 2 -0.04 -0.08
## se
## X1 0.03
describe(WidthPremium)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 458 19.47 1.1 19 19.53 0 17 21 4 -0.08 -0.31 0.05
describe(PriceEconomy)
## vars n mean sd median trimmed mad min max range skew
## X1 1 458 1327.08 988.27 1242 1244.4 1159.39 65 3593 3528 0.51
## kurtosis se
## X1 -0.88 46.18
describe(PricePremium)
## vars n mean sd median trimmed mad min max range skew
## X1 1 458 1845.26 1288.14 1737 1799.05 1845.84 86 7414 7328 0.5
## kurtosis se
## X1 0.43 60.19
Monthly analysis of seats
library(car)
par(mfrow=c(1, 2))
scatterplot( TravelMonth,SeatsEconomy)
scatterplot( TravelMonth,SeatsPremium)

## [1] "165" "175" "164" "174" "166" "176"
cor(SeatsPremium,SeatsEconomy)
## [1] 0.6250566
Usage of different type of flight during different months
mytable <- xtabs(~ TravelMonth+Airline+Aircraft, data=air.df)
ftable(mytable)
## Aircraft AirBus Boeing
## TravelMonth Airline
## Aug AirFrance 9 11
## British 13 39
## Delta 2 10
## Jet 2 14
## Singapore 4 7
## Virgin 9 7
## Jul AirFrance 6 6
## British 6 10
## Delta 0 10
## Jet 1 14
## Singapore 4 4
## Virgin 8 6
## Oct AirFrance 9 11
## British 14 39
## Delta 5 8
## Jet 2 13
## Singapore 4 6
## Virgin 7 9
## Sep AirFrance 12 10
## British 14 40
## Delta 5 6
## Jet 2 13
## Singapore 4 7
## Virgin 9 7
Type of journey available with different airlines(monthly)
mytable <- xtabs(~ Airline+TravelMonth+IsInternational, data=air.df)
ftable(mytable)
## IsInternational Domestic International
## Airline TravelMonth
## AirFrance Aug 0 20
## Jul 0 12
## Oct 0 20
## Sep 0 22
## British Aug 0 52
## Jul 0 16
## Oct 0 53
## Sep 0 54
## Delta Aug 10 2
## Jul 10 0
## Oct 11 2
## Sep 9 2
## Jet Aug 0 16
## Jul 0 15
## Oct 0 15
## Sep 0 15
## Singapore Aug 0 11
## Jul 0 8
## Oct 0 10
## Sep 0 11
## Virgin Aug 0 16
## Jul 0 14
## Oct 0 16
## Sep 0 16
to analyse data of each airline seperately
British <- air.df[ which(air.df$Airline=='British'), ]
AirFrance <- air.df[ which(air.df$Airline=='AirFrance'), ]
Delta <- air.df[ which(air.df$Airline=='Delta'), ]
Singapore <- air.df[ which(air.df$Airline=='Singapore'), ]
Virgin <- air.df[ which(air.df$Airline=='Virgin'), ]
Jet <- air.df[ which(air.df$Airline=='Jet'), ]
summary of british airline
summary(British)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 0 AirBus: 47 Min. : 1.250 Aug:52
## British :175 Boeing:128 1st Qu.: 4.290 Jul:16
## Delta : 0 Median : 8.580 Oct:53
## Jet : 0 Mean : 7.855 Sep:54
## Singapore: 0 3rd Qu.:11.120
## Virgin : 0 Max. :13.830
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 0 Min. :122.0 Min. :24.00 Min. :31
## International:175 1st Qu.:122.0 1st Qu.:36.00 1st Qu.:31
## Median :243.0 Median :40.00 Median :31
## Mean :216.6 Mean :43.18 Mean :31
## 3rd Qu.:303.0 3rd Qu.:55.00 3rd Qu.:31
## Max. :312.0 Max. :56.00 Max. :31
## PitchPremium WidthEconomy WidthPremium PriceEconomy
## Min. :38 Min. :18 Min. :19 Min. : 65.0
## 1st Qu.:38 1st Qu.:18 1st Qu.:19 1st Qu.: 528.5
## Median :38 Median :18 Median :19 Median :1444.0
## Mean :38 Mean :18 Mean :19 Mean :1293.5
## 3rd Qu.:38 3rd Qu.:18 3rd Qu.:19 3rd Qu.:1813.0
## Max. :38 Max. :18 Max. :19 Max. :3102.0
## PricePremium PriceRelative SeatsTotal PitchDifference
## Min. : 86.0 Min. :0.0400 Min. :162.0 Min. :7
## 1st Qu.: 807.5 1st Qu.:0.2100 1st Qu.:162.0 1st Qu.:7
## Median :2049.0 Median :0.3600 Median :279.0 Median :7
## Mean :1937.0 Mean :0.4375 Mean :259.8 Mean :7
## 3rd Qu.:2982.0 3rd Qu.:0.5200 3rd Qu.:358.0 3rd Qu.:7
## Max. :7414.0 Max. :1.3900 Max. :367.0 Max. :7
## WidthDifference PercentPremiumSeats
## Min. :1 Min. :10.57
## 1st Qu.:1 1st Qu.:12.90
## Median :1 Median :15.36
## Mean :1 Mean :17.79
## 3rd Qu.:1 3rd Qu.:24.69
## Max. :1 Max. :24.69
summary of AirFrance airline
summary(AirFrance)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance:74 AirBus:36 Min. : 6.830 Aug:20
## British : 0 Boeing:38 1st Qu.: 7.770 Jul:12
## Delta : 0 Median : 8.750 Oct:20
## Jet : 0 Mean : 8.989 Sep:22
## Singapore: 0 3rd Qu.: 9.500
## Virgin : 0 Max. :13.000
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 0 Min. :147.0 Min. :21.0 Min. :32
## International:74 1st Qu.:147.0 1st Qu.:21.0 1st Qu.:32
## Median :200.0 Median :24.0 Median :32
## Mean :214.5 Mean :26.7 Mean :32
## 3rd Qu.:200.0 3rd Qu.:28.0 3rd Qu.:32
## Max. :389.0 Max. :38.0 Max. :32
## PitchPremium WidthEconomy WidthPremium PriceEconomy PricePremium
## Min. :38 Min. :17.00 Min. :19 Min. : 630 Min. :1611
## 1st Qu.:38 1st Qu.:17.00 1st Qu.:19 1st Qu.:2659 1st Qu.:2859
## Median :38 Median :18.00 Median :19 Median :2988 Median :3196
## Mean :38 Mean :17.57 Mean :19 Mean :2770 Mean :3065
## 3rd Qu.:38 3rd Qu.:18.00 3rd Qu.:19 3rd Qu.:3165 3rd Qu.:3289
## Max. :38 Max. :18.00 Max. :19 Max. :3593 Max. :3972
## PriceRelative SeatsTotal PitchDifference WidthDifference
## Min. :0.0200 Min. :168.0 Min. :6 Min. :1.000
## 1st Qu.:0.0300 1st Qu.:168.0 1st Qu.:6 1st Qu.:1.000
## Median :0.0700 Median :228.0 Median :6 Median :1.000
## Mean :0.2047 Mean :241.2 Mean :6 Mean :1.432
## 3rd Qu.:0.0800 3rd Qu.:228.0 3rd Qu.:6 3rd Qu.:2.000
## Max. :1.6400 Max. :427.0 Max. :6 Max. :2.000
## PercentPremiumSeats
## Min. : 8.90
## 1st Qu.:12.12
## Median :12.28
## Mean :11.59
## 3rd Qu.:12.50
## Max. :12.50
summary of Delta airline
summary(Delta)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 0 AirBus:12 Min. :1.570 Aug:12
## British : 0 Boeing:34 1st Qu.:2.270 Jul:10
## Delta :46 Median :4.260 Oct:13
## Jet : 0 Mean :4.029 Sep:11
## Singapore: 0 3rd Qu.:4.645
## Virgin : 0 Max. :9.500
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic :40 Min. : 78.0 Min. :18.00 Min. :31.00
## International: 6 1st Qu.:120.0 1st Qu.:18.00 1st Qu.:31.00
## Median :126.0 Median :20.00 Median :32.00
## Mean :137.2 Mean :22.57 Mean :31.72
## 3rd Qu.:139.0 3rd Qu.:21.00 3rd Qu.:32.00
## Max. :233.0 Max. :38.00 Max. :33.00
## PitchPremium WidthEconomy WidthPremium PriceEconomy
## Min. :34.00 Min. :17.00 Min. :17.00 Min. : 158.0
## 1st Qu.:34.00 1st Qu.:17.00 1st Qu.:17.00 1st Qu.: 293.0
## Median :34.00 Median :17.00 Median :17.00 Median : 363.0
## Mean :34.72 Mean :17.39 Mean :17.78 Mean : 560.9
## 3rd Qu.:35.00 3rd Qu.:18.00 3rd Qu.:18.00 3rd Qu.: 449.2
## Max. :38.00 Max. :18.00 Max. :21.00 Max. :1999.0
## PricePremium PriceRelative SeatsTotal PitchDifference
## Min. : 173.0 Min. :0.0300 Min. : 98.0 Min. :2
## 1st Qu.: 312.8 1st Qu.:0.0700 1st Qu.:138.0 1st Qu.:2
## Median : 406.5 Median :0.0900 Median :144.0 Median :2
## Mean : 684.7 Mean :0.1250 Mean :159.8 Mean :3
## 3rd Qu.: 489.5 3rd Qu.:0.1175 3rd Qu.:160.0 3rd Qu.:3
## Max. :2765.0 Max. :0.4600 Max. :271.0 Max. :7
## WidthDifference PercentPremiumSeats
## Min. :0.0000 Min. :12.50
## 1st Qu.:0.0000 1st Qu.:12.50
## Median :0.0000 Median :13.09
## Mean :0.3913 Mean :14.48
## 3rd Qu.:0.0000 3rd Qu.:14.50
## Max. :3.0000 Max. :20.41
summary of Singapore airline
summary(Singapore)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 0 AirBus:16 Min. : 3.83 Aug:11
## British : 0 Boeing:24 1st Qu.: 6.50 Jul: 8
## Delta : 0 Median :12.41 Oct:10
## Jet : 0 Mean :10.48 Sep:11
## Singapore:40 3rd Qu.:13.33
## Virgin : 0 Max. :14.66
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 0 Min. :184.0 Min. :28.0 Min. :32
## International:40 1st Qu.:184.0 1st Qu.:28.0 1st Qu.:32
## Median :184.0 Median :28.0 Median :32
## Mean :243.6 Mean :31.2 Mean :32
## 3rd Qu.:333.0 3rd Qu.:36.0 3rd Qu.:32
## Max. :333.0 Max. :36.0 Max. :32
## PitchPremium WidthEconomy WidthPremium PriceEconomy PricePremium
## Min. :38 Min. :19 Min. :20 Min. : 505.0 Min. : 619
## 1st Qu.:38 1st Qu.:19 1st Qu.:20 1st Qu.: 563.0 1st Qu.:1004
## Median :38 Median :19 Median :20 Median : 690.0 Median :1110
## Mean :38 Mean :19 Mean :20 Mean : 860.2 Mean :1240
## 3rd Qu.:38 3rd Qu.:19 3rd Qu.:20 3rd Qu.:1223.0 3rd Qu.:1564
## Max. :38 Max. :19 Max. :20 Max. :1431.0 Max. :1947
## PriceRelative SeatsTotal PitchDifference WidthDifference
## Min. :0.0900 Min. :212.0 Min. :6 Min. :1
## 1st Qu.:0.1300 1st Qu.:212.0 1st Qu.:6 1st Qu.:1
## Median :0.6050 Median :212.0 Median :6 Median :1
## Mean :0.5298 Mean :274.8 Mean :6 Mean :1
## 3rd Qu.:0.8300 3rd Qu.:369.0 3rd Qu.:6 3rd Qu.:1
## Max. :1.1100 Max. :369.0 Max. :6 Max. :1
## PercentPremiumSeats
## Min. : 9.76
## 1st Qu.: 9.76
## Median :13.21
## Mean :11.83
## 3rd Qu.:13.21
## Max. :13.21
summary of Virgin airline
summary(Virgin)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 0 AirBus:33 Min. : 6.580 Aug:16
## British : 0 Boeing:29 1st Qu.: 7.473 Jul:14
## Delta : 0 Median : 8.830 Oct:16
## Jet : 0 Mean : 9.250 Sep:16
## Singapore: 0 3rd Qu.:10.830
## Virgin :62 Max. :12.580
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 0 Min. :185.0 Min. :35.00 Min. :31
## International:62 1st Qu.:198.0 1st Qu.:35.00 1st Qu.:31
## Median :198.0 Median :38.00 Median :31
## Mean :230.2 Mean :42.53 Mean :31
## 3rd Qu.:233.0 3rd Qu.:48.00 3rd Qu.:31
## Max. :375.0 Max. :66.00 Max. :31
## PitchPremium WidthEconomy WidthPremium PriceEconomy PricePremium
## Min. :38 Min. :18 Min. :21 Min. : 540 Min. : 594
## 1st Qu.:38 1st Qu.:18 1st Qu.:21 1st Qu.:1434 1st Qu.:2499
## Median :38 Median :18 Median :21 Median :1774 Median :2973
## Mean :38 Mean :18 Mean :21 Mean :1604 Mean :2722
## 3rd Qu.:38 3rd Qu.:18 3rd Qu.:21 3rd Qu.:1903 3rd Qu.:3128
## Max. :38 Max. :18 Max. :21 Max. :2445 Max. :3694
## PriceRelative SeatsTotal PitchDifference WidthDifference
## Min. :0.1000 Min. :233.0 Min. :7 Min. :3
## 1st Qu.:0.4000 1st Qu.:233.0 1st Qu.:7 1st Qu.:3
## Median :0.7300 Median :233.0 Median :7 Median :3
## Mean :0.7606 Mean :272.7 Mean :7 Mean :3
## 3rd Qu.:1.0150 3rd Qu.:271.0 3rd Qu.:7 3rd Qu.:3
## Max. :1.8200 Max. :441.0 Max. :7 Max. :3
## PercentPremiumSeats
## Min. :14.02
## 1st Qu.:14.02
## Median :15.02
## Mean :15.75
## 3rd Qu.:15.02
## Max. :20.60
summary of Jet airline
summary(Jet)
## Airline Aircraft FlightDuration TravelMonth
## AirFrance: 0 AirBus: 7 Min. :2.500 Aug:16
## British : 0 Boeing:54 1st Qu.:2.660 Jul:15
## Delta : 0 Median :3.250 Oct:15
## Jet :61 Mean :4.144 Sep:15
## Singapore: 0 3rd Qu.:4.330
## Virgin : 0 Max. :9.500
## IsInternational SeatsEconomy SeatsPremium PitchEconomy
## Domestic : 0 Min. :124.0 Min. : 8.00 Min. :30.00
## International:61 1st Qu.:124.0 1st Qu.: 8.00 1st Qu.:30.00
## Median :138.0 Median :16.00 Median :30.00
## Mean :140.3 Mean :15.66 Mean :30.23
## 3rd Qu.:162.0 3rd Qu.:16.00 3rd Qu.:30.00
## Max. :162.0 Max. :28.00 Max. :32.00
## PitchPremium WidthEconomy WidthPremium PriceEconomy
## Min. :38.00 Min. :17.00 Min. :19.00 Min. :108.0
## 1st Qu.:40.00 1st Qu.:17.00 1st Qu.:21.00 1st Qu.:154.0
## Median :40.00 Median :17.00 Median :21.00 Median :201.0
## Mean :39.77 Mean :17.11 Mean :20.77 Mean :276.2
## 3rd Qu.:40.00 3rd Qu.:17.00 3rd Qu.:21.00 3rd Qu.:354.0
## Max. :40.00 Max. :18.00 Max. :21.00 Max. :676.0
## PricePremium PriceRelative SeatsTotal PitchDifference
## Min. :228.0 Min. :0.1200 Min. :140 Min. : 6.000
## 1st Qu.:318.0 1st Qu.:0.4800 1st Qu.:140 1st Qu.:10.000
## Median :483.0 Median :0.8200 Median :166 Median :10.000
## Mean :483.4 Mean :0.9397 Mean :156 Mean : 9.541
## 3rd Qu.:569.0 3rd Qu.:1.2900 3rd Qu.:170 3rd Qu.:10.000
## Max. :931.0 Max. :1.8900 Max. :170 Max. :10.000
## WidthDifference PercentPremiumSeats
## Min. :1.000 Min. : 4.71
## 1st Qu.:4.000 1st Qu.: 4.71
## Median :4.000 Median :11.43
## Mean :3.656 Mean :10.17
## 3rd Qu.:4.000 3rd Qu.:11.43
## Max. :4.000 Max. :16.87
Plot of Premium Ticket Prices versus Economy Ticket Prices
plot(~PriceEconomy + PricePremium, main="Premium Economy Price vs. Economy Price")

Scatter plot of Premium Economy vs Economy Airfares
library(car)
scatterplotMatrix(~PricePremium+PriceEconomy+PitchDifference+WidthDifference, data=air.df,
main="Premium Economy vs. Economy Airfares")

t-test of PricePremium, PriceEconomy
t.test(PricePremium,PriceEconomy)
##
## Welch Two Sample t-test
##
## data: PricePremium and PriceEconomy
## t = 6.8304, df = 856.56, p-value = 1.605e-11
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 369.2793 667.0831
## sample estimates:
## mean of x mean of y
## 1845.258 1327.076