Airline Ticket Pricing Analysis

Sameer Mathur

Delhi-Mumbai Airline Pricing Analysis

PART 1

READING AND PREPARING DATA

1a. Reading data

Number of Rows and Columns

# reading data into R
airline.df <- read.csv(paste("AirlinePricingData.csv"))
# rows and columns of the data frame
dim(airline.df)
[1] 305  25

Column Names

# data column names
colnames(airline.df)
 [1] "FlightNumber"        "Airline"             "DepartureCityCode"  
 [4] "ArrivalCityCode"     "DepartureTime"       "ArrivalTime"        
 [7] "Departure"           "FlyingMinutes"       "Aircraft"           
[10] "PlaneModel"          "Capacity"            "SeatPitch"          
[13] "SeatWidth"           "DataCollectionDate"  "DateDeparture"      
[16] "IsWeekend"           "Price"               "AdvancedBookingDays"
[19] "IsDiwali"            "DayBeforeDiwali"     "DayAfterDiwali"     
[22] "MetroDeparture"      "MetroArrival"        "MarketShare"        
[25] "LoadFactor"         

1b. Data Types

# data types of the data columns
str(airline.df)
'data.frame':   305 obs. of  25 variables:
 $ FlightNumber       : Factor w/ 63 levels "6E 129","6E 155",..: 25 32 62 4 61 45 57 16 59 17 ...
 $ Airline            : Factor w/ 4 levels "Air India","IndiGo",..: 3 3 4 2 4 3 4 2 4 3 ...
 $ DepartureCityCode  : Factor w/ 2 levels "BOM","DEL": 2 1 2 2 1 1 2 2 1 1 ...
 $ ArrivalCityCode    : Factor w/ 2 levels "BOM","DEL": 1 2 1 1 2 2 1 1 2 2 ...
 $ DepartureTime      : int  225 300 350 455 555 605 635 640 645 700 ...
 $ ArrivalTime        : int  435 505 605 710 805 815 850 855 855 915 ...
 $ Departure          : Factor w/ 2 levels "AM","PM": 1 1 1 1 1 1 1 1 1 1 ...
 $ FlyingMinutes      : int  130 125 135 135 130 130 135 135 130 135 ...
 $ Aircraft           : Factor w/ 2 levels "Airbus","Boeing": 2 2 2 1 2 2 2 1 2 2 ...
 $ PlaneModel         : Factor w/ 9 levels "738","739","77W",..: 1 1 1 6 1 1 1 6 1 2 ...
 $ Capacity           : int  156 156 189 180 189 156 189 180 189 138 ...
 $ SeatPitch          : int  30 30 29 30 29 30 29 30 29 30 ...
 $ SeatWidth          : num  17 17 17 18 17 17 17 18 17 17 ...
 $ DataCollectionDate : Factor w/ 7 levels "Sep 10 2018",..: 2 4 6 7 6 4 6 7 6 4 ...
 $ DateDeparture      : Factor w/ 20 levels "Nov 6 2018","Nov 8 2018",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ IsWeekend          : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
 $ Price              : int  4051 11587 3977 4234 6837 6518 3189 4234 8623 6833 ...
 $ AdvancedBookingDays: int  54 52 48 59 48 52 48 59 48 52 ...
 $ IsDiwali           : int  1 1 1 1 1 1 1 1 1 1 ...
 $ DayBeforeDiwali    : int  1 1 1 1 1 1 1 1 1 1 ...
 $ DayAfterDiwali     : int  0 0 0 0 0 0 0 0 0 0 ...
 $ MetroDeparture     : int  1 1 1 1 1 1 1 1 1 1 ...
 $ MetroArrival       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ MarketShare        : num  15.4 15.4 13.2 39.6 13.2 15.4 13.2 39.6 13.2 15.4 ...
 $ LoadFactor         : num  83.3 83.3 94.1 87.2 94.1 ...

1c. Conversion of some data types of data columns into factor

# convert 'IsDiwali' into  factor
airline.df$IsDiwali <- as.factor(airline.df$IsDiwali)
# convert 'DayBeforeDiwali' into  factor
airline.df$DayBeforeDiwali <- as.factor(airline.df$DayBeforeDiwali)
# convert 'DayAfterDiwali' into  factor
airline.df$DayAfterDiwali <- as.factor(airline.df$DayAfterDiwali)
# convert 'MetroDeparture' into  factor
airline.df$MetroDeparture <- as.factor(airline.df$MetroDeparture)
# convert 'MetroArrival' into  factor
airline.df$MetroArrival <- as.factor(airline.df$MetroArrival)

# verify
str(airline.df)
'data.frame':   305 obs. of  25 variables:
 $ FlightNumber       : Factor w/ 63 levels "6E 129","6E 155",..: 25 32 62 4 61 45 57 16 59 17 ...
 $ Airline            : Factor w/ 4 levels "Air India","IndiGo",..: 3 3 4 2 4 3 4 2 4 3 ...
 $ DepartureCityCode  : Factor w/ 2 levels "BOM","DEL": 2 1 2 2 1 1 2 2 1 1 ...
 $ ArrivalCityCode    : Factor w/ 2 levels "BOM","DEL": 1 2 1 1 2 2 1 1 2 2 ...
 $ DepartureTime      : int  225 300 350 455 555 605 635 640 645 700 ...
 $ ArrivalTime        : int  435 505 605 710 805 815 850 855 855 915 ...
 $ Departure          : Factor w/ 2 levels "AM","PM": 1 1 1 1 1 1 1 1 1 1 ...
 $ FlyingMinutes      : int  130 125 135 135 130 130 135 135 130 135 ...
 $ Aircraft           : Factor w/ 2 levels "Airbus","Boeing": 2 2 2 1 2 2 2 1 2 2 ...
 $ PlaneModel         : Factor w/ 9 levels "738","739","77W",..: 1 1 1 6 1 1 1 6 1 2 ...
 $ Capacity           : int  156 156 189 180 189 156 189 180 189 138 ...
 $ SeatPitch          : int  30 30 29 30 29 30 29 30 29 30 ...
 $ SeatWidth          : num  17 17 17 18 17 17 17 18 17 17 ...
 $ DataCollectionDate : Factor w/ 7 levels "Sep 10 2018",..: 2 4 6 7 6 4 6 7 6 4 ...
 $ DateDeparture      : Factor w/ 20 levels "Nov 6 2018","Nov 8 2018",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ IsWeekend          : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
 $ Price              : int  4051 11587 3977 4234 6837 6518 3189 4234 8623 6833 ...
 $ AdvancedBookingDays: int  54 52 48 59 48 52 48 59 48 52 ...
 $ IsDiwali           : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
 $ DayBeforeDiwali    : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
 $ DayAfterDiwali     : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ MetroDeparture     : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
 $ MetroArrival       : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
 $ MarketShare        : num  15.4 15.4 13.2 39.6 13.2 15.4 13.2 39.6 13.2 15.4 ...
 $ LoadFactor         : num  83.3 83.3 94.1 87.2 94.1 ...

PART 2

DATA SUMMARY

2a. Descriptive statistics of the data frame

# attaching data columns
attach(airline.df)
# descriptive statistics
library(psych)
describe(airline.df)[c(7, 10:12, 15:17, 22, 23), c(2:5, 8:9)]
                  n    mean      sd median  min   max
Departure*      305    1.45    0.50      1    1     2
PlaneModel*     305    3.82    2.71      3    1     9
Capacity        305  176.36   32.39    180  138   303
SeatPitch       305   30.26    0.93     30   29    33
DateDeparture*  305    8.14    6.69      7    1    20
IsWeekend*      305    1.13    0.34      1    1     2
Price           305 5394.54 2388.29   4681 2607 18015
MetroDeparture* 305    1.00    0.00      1    1     1
MetroArrival*   305    1.00    0.00      1    1     1

2b. Number of flights by airlines in Diwali

# flights by airline in Diwali
table(Airline, IsDiwali)
           IsDiwali
Airline      0  1
  Air India 25 16
  IndiGo    48 32
  Jet       87 57
  Spice Jet 24 16

2c. Average ticket price and advanced booking days by airline

# average ticket price by airline
library(data.table)
dt <- data.table(airline.df)
dt[, list(AveragePrice = round(mean(Price), 2),
          AveragePrice = round(sd(Price), 2)), by = Airline]
     Airline AveragePrice AveragePrice
1:       Jet      5496.15      1989.66
2: Spice Jet      5094.85      1787.42
3:    IndiGo      4879.52      2956.46
4: Air India      6335.00      2693.64

PART 3

REGRESSION ANALYSIS

3a. Linear OLS Model

# linear OLS intearction model
fitOLSIntModel <- lm(Price ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth, 
                        data = airline.df)
# summary of linear OLS interaction model
summary(fitOLSIntModel)

Call:
lm(formula = Price ~ AdvancedBookingDays * Airline + Departure + 
    IsWeekend + IsDiwali + DepartureCityCode + FlyingMinutes + 
    SeatPitch + SeatWidth, data = airline.df)

Residuals:
    Min      1Q  Median      3Q     Max 
-3405.0 -1327.7  -352.0   649.4 11141.5 

Coefficients:
                                     Estimate Std. Error t value Pr(>|t|)
(Intercept)                          -5740.82    8645.69  -0.664   0.5072
AdvancedBookingDays                    -31.15      19.66  -1.584   0.1142
AirlineIndiGo                         1806.95     923.82   1.956   0.0514
AirlineJet                            1107.68     648.25   1.709   0.0886
AirlineSpice Jet                       208.21     921.57   0.226   0.8214
DeparturePM                           -560.75     267.30  -2.098   0.0368
IsWeekendYes                          -444.72     405.74  -1.096   0.2740
IsDiwali1                             4071.54     555.68   7.327 2.34e-12
DepartureCityCodeDEL                 -1421.50     342.21  -4.154 4.30e-05
FlyingMinutes                           40.31      28.40   1.419   0.1569
SeatPitch                             -244.28     220.07  -1.110   0.2679
SeatWidth                              796.64     492.66   1.617   0.1070
AdvancedBookingDays:AirlineIndiGo      -80.68      18.33  -4.402 1.51e-05
AdvancedBookingDays:AirlineJet         -44.87      17.68  -2.538   0.0117
AdvancedBookingDays:AirlineSpice Jet   -46.78      22.34  -2.094   0.0372

(Intercept)                             
AdvancedBookingDays                     
AirlineIndiGo                        .  
AirlineJet                           .  
AirlineSpice Jet                        
DeparturePM                          *  
IsWeekendYes                            
IsDiwali1                            ***
DepartureCityCodeDEL                 ***
FlyingMinutes                           
SeatPitch                               
SeatWidth                               
AdvancedBookingDays:AirlineIndiGo    ***
AdvancedBookingDays:AirlineJet       *  
AdvancedBookingDays:AirlineSpice Jet *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2017 on 290 degrees of freedom
Multiple R-squared:  0.3197,    Adjusted R-squared:  0.2868 
F-statistic: 9.733 on 14 and 290 DF,  p-value: < 2.2e-16

3b. Log-linear OLS Model

# linear OLS intearction model
fitLogOLSIntModel <- lm(log(Price) ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth, 
                        data = airline.df)
# summary of linear OLS interaction model
summary(fitLogOLSIntModel)

Call:
lm(formula = log(Price) ~ AdvancedBookingDays * Airline + Departure + 
    IsWeekend + IsDiwali + DepartureCityCode + FlyingMinutes + 
    SeatPitch + SeatWidth, data = airline.df)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.59755 -0.19913 -0.03802  0.15262  1.16078 

Coefficients:
                                      Estimate Std. Error t value Pr(>|t|)
(Intercept)                           6.380581   1.225651   5.206 3.66e-07
AdvancedBookingDays                  -0.008199   0.002787  -2.942 0.003525
AirlineIndiGo                         0.165430   0.130964   1.263 0.207542
AirlineJet                            0.146681   0.091899   1.596 0.111553
AirlineSpice Jet                      0.025470   0.130646   0.195 0.845564
DeparturePM                          -0.052828   0.037893  -1.394 0.164347
IsWeekendYes                         -0.049339   0.057520  -0.858 0.391723
IsDiwali1                             0.714659   0.078775   9.072  < 2e-16
DepartureCityCodeDEL                 -0.264292   0.048514  -5.448 1.09e-07
FlyingMinutes                         0.008870   0.004026   2.203 0.028358
SeatPitch                            -0.028846   0.031198  -0.925 0.355924
SeatWidth                             0.114373   0.069841   1.638 0.102587
AdvancedBookingDays:AirlineIndiGo    -0.008971   0.002598  -3.453 0.000637
AdvancedBookingDays:AirlineJet       -0.005310   0.002507  -2.118 0.035021
AdvancedBookingDays:AirlineSpice Jet -0.005399   0.003167  -1.705 0.089324

(Intercept)                          ***
AdvancedBookingDays                  ** 
AirlineIndiGo                           
AirlineJet                              
AirlineSpice Jet                        
DeparturePM                             
IsWeekendYes                            
IsDiwali1                            ***
DepartureCityCodeDEL                 ***
FlyingMinutes                        *  
SeatPitch                               
SeatWidth                               
AdvancedBookingDays:AirlineIndiGo    ***
AdvancedBookingDays:AirlineJet       *  
AdvancedBookingDays:AirlineSpice Jet .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.2859 on 290 degrees of freedom
Multiple R-squared:  0.3937,    Adjusted R-squared:  0.3645 
F-statistic: 13.45 on 14 and 290 DF,  p-value: < 2.2e-16

PART 5

REGRESSION DIAGNOSTICS

5a. Hetroscedasticity Test

# Goldfeld-Quandt Test
library(lmtest)
gqtest(fitOLSIntModel, order.by = ~ Price, data = airline.df)

    Goldfeld-Quandt test

data:  fitOLSIntModel
GQ = 21.27, df1 = 138, df2 = 137, p-value < 2.2e-16
alternative hypothesis: variance increases from segment 1 to 2

5b. Breusch-Pagan Test

library(lmtest)
# BP-test for OLS model
bptest(fitOLSIntModel)

    studentized Breusch-Pagan test

data:  fitOLSIntModel
BP = 52.463, df = 14, p-value = 2.347e-06

5c. Normality plots of residuals

# distribution of studentized residuals
library(MASS)
sresid <- studres(fitOLSIntModel) 
hist(sresid, freq=FALSE, 
   main="Distribution of Studentized Residuals")
xfit<-seq(min(sresid),max(sresid),length=40) 
yfit<-dnorm(xfit) 
lines(xfit, yfit)

plot of chunk unnamed-chunk-16

5d. Residuals Plots for Log-Linear FGLS Model

# residual plots of OLS model
par(mfrow=c(2,2))
plot(fitOLSIntModel)

plot of chunk unnamed-chunk-17

PART 6

FGLS REGRESSION MODEL

6a. Linear FGLS Model

# Step 1:Residuals of linear OLS Model
LogOLSModelRes <- resid(fitOLSIntModel)

# Step 2: Taking square of the residuals of linear OLS Model
LogOLSModelResSq <- LogOLSModelRes^2

# Step 3: Taking natural log of the squared residuals of linear OLS Model
lnOLSResSq <- log(LogOLSModelResSq)

# Step 4: Running auxiliary OLS Model
auxOLSModel <- lm(lnOLSResSq ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth,
                data = airline.df)

# Step 5: Get fitted value of auxiliary OLS Model i.e. 'auxOLSModel'
fittedValue <- fitted(auxOLSModel)

# Step 6: Compute exponential values of fiited value for auxialiary OLS Model
expValue <- exp(fittedValue)

# Step 7: Fit Log-linear FGLS Model
fitFGLSIntModel <- lm(Price ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth,
                   weights = 1/expValue, data = airline.df)
# summary of linear FGLS model
summary(fitFGLSIntModel)

Call:
lm(formula = Price ~ AdvancedBookingDays * Airline + Departure + 
    IsWeekend + IsDiwali + DepartureCityCode + FlyingMinutes + 
    SeatPitch + SeatWidth, data = airline.df, weights = 1/expValue)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-7.5444 -1.0129 -0.4436  0.8758  6.3196 

Coefficients:
                                     Estimate Std. Error t value Pr(>|t|)
(Intercept)                          -6708.20    5272.58  -1.272 0.204292
AdvancedBookingDays                    -22.18      11.70  -1.896 0.058936
AirlineIndiGo                          323.42     595.34   0.543 0.587367
AirlineJet                             810.56     381.20   2.126 0.034318
AirlineSpice Jet                       870.93     671.86   1.296 0.195905
DeparturePM                           -221.06     112.89  -1.958 0.051167
IsWeekendYes                           607.47     307.89   1.973 0.049441
IsDiwali1                             3199.38     321.04   9.966  < 2e-16
DepartureCityCodeDEL                 -1398.95     241.38  -5.796 1.77e-08
FlyingMinutes                           53.79      15.29   3.517 0.000506
SeatPitch                             -110.40     120.42  -0.917 0.360036
SeatWidth                              490.73     268.47   1.828 0.068597
AdvancedBookingDays:AirlineIndiGo      -38.97      14.73  -2.646 0.008580
AdvancedBookingDays:AirlineJet         -35.64      14.05  -2.537 0.011715
AdvancedBookingDays:AirlineSpice Jet   -44.18      19.96  -2.214 0.027599

(Intercept)                             
AdvancedBookingDays                  .  
AirlineIndiGo                           
AirlineJet                           *  
AirlineSpice Jet                        
DeparturePM                          .  
IsWeekendYes                         *  
IsDiwali1                            ***
DepartureCityCodeDEL                 ***
FlyingMinutes                        ***
SeatPitch                               
SeatWidth                            .  
AdvancedBookingDays:AirlineIndiGo    ** 
AdvancedBookingDays:AirlineJet       *  
AdvancedBookingDays:AirlineSpice Jet *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.665 on 290 degrees of freedom
Multiple R-squared:  0.4652,    Adjusted R-squared:  0.4394 
F-statistic: 18.02 on 14 and 290 DF,  p-value: < 2.2e-16

6b. Log-linear FGLS Model

# Step 1:Residuals of linear OLS Model
LogOLSModelRes <- resid(fitLogOLSIntModel)

# Step 2: Taking square of the residuals of linear OLS Model
LogOLSModelResSq <- LogOLSModelRes^2

# Step 3: Taking natural log of the squared residuals of linear OLS Model
lnOLSResSq <- log(LogOLSModelResSq)

# Step 4: Running auxiliary OLS Model
auxOLSModel <- lm(lnOLSResSq ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth,
                data = airline.df)

# Step 5: Get fitted value of auxiliary OLS Model i.e. 'auxOLSModel'
fittedValue <- fitted(auxOLSModel)

# Step 6: Compute exponential values of fiited value for auxialiary OLS Model
expValue <- exp(fittedValue)

# Step 7: Fit Log-linear FGLS Model
fitLogFGLSIntModel <- lm(log(Price) ~ 
                          AdvancedBookingDays * Airline 
                        + Departure + IsWeekend 
                        + IsDiwali 
                        + DepartureCityCode 
                        + FlyingMinutes 
                        + SeatPitch
                        + SeatWidth,
                   weights = 1/expValue, data = airline.df)
# summary of linear FGLS model
summary(fitLogFGLSIntModel)

Call:
lm(formula = log(Price) ~ AdvancedBookingDays * Airline + Departure + 
    IsWeekend + IsDiwali + DepartureCityCode + FlyingMinutes + 
    SeatPitch + SeatWidth, data = airline.df, weights = 1/expValue)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-7.4068 -1.1755 -0.3849  1.1028  5.6760 

Coefficients:
                                      Estimate Std. Error t value Pr(>|t|)
(Intercept)                           5.875369   0.912360   6.440 4.96e-10
AdvancedBookingDays                  -0.006190   0.002000  -3.096 0.002155
AirlineIndiGo                         0.024338   0.111169   0.219 0.826857
AirlineJet                            0.143865   0.067581   2.129 0.034115
AirlineSpice Jet                      0.196338   0.132408   1.483 0.139206
DeparturePM                          -0.035454   0.024810  -1.429 0.154068
IsWeekendYes                          0.113861   0.052979   2.149 0.032450
IsDiwali1                             0.696111   0.056942  12.225  < 2e-16
DepartureCityCodeDEL                 -0.307427   0.041264  -7.450 1.08e-12
FlyingMinutes                         0.010111   0.003001   3.370 0.000854
SeatPitch                            -0.015858   0.022113  -0.717 0.473877
SeatWidth                             0.108791   0.049671   2.190 0.029304
AdvancedBookingDays:AirlineIndiGo    -0.006156   0.002400  -2.565 0.010829
AdvancedBookingDays:AirlineJet       -0.006296   0.002273  -2.770 0.005963
AdvancedBookingDays:AirlineSpice Jet -0.009210   0.003595  -2.562 0.010909

(Intercept)                          ***
AdvancedBookingDays                  ** 
AirlineIndiGo                           
AirlineJet                           *  
AirlineSpice Jet                        
DeparturePM                             
IsWeekendYes                         *  
IsDiwali1                            ***
DepartureCityCodeDEL                 ***
FlyingMinutes                        ***
SeatPitch                               
SeatWidth                            *  
AdvancedBookingDays:AirlineIndiGo    *  
AdvancedBookingDays:AirlineJet       ** 
AdvancedBookingDays:AirlineSpice Jet *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.786 on 290 degrees of freedom
Multiple R-squared:  0.5193,    Adjusted R-squared:  0.4961 
F-statistic: 22.38 on 14 and 290 DF,  p-value: < 2.2e-16

PART 7

MULTICOLLINEARITY TEST

7a. VIF

library(car)
vif(fitFGLSIntModel)
                                   GVIF Df GVIF^(1/(2*Df))
AdvancedBookingDays           21.743703  1        4.663014
Airline                      473.028934  3        2.791352
Departure                      1.175864  1        1.084373
IsWeekend                      1.387644  1        1.177983
IsDiwali                       9.707042  1        3.115613
DepartureCityCode              3.518471  1        1.875759
FlyingMinutes                  1.136829  1        1.066222
SeatPitch                      3.348518  1        1.829895
SeatWidth                      5.676174  1        2.382472
AdvancedBookingDays:Airline 1134.590363  3        3.229534

7b. Correlation Matrix

expVar <- airline.df[c("Price", "AdvancedBookingDays", "FlyingMinutes", "SeatPitch", "SeatWidth")]
#cor(expVar)
library(Hmisc)
rcorr(as.matrix(expVar))
                    Price AdvancedBookingDays FlyingMinutes SeatPitch
Price                1.00               -0.01         -0.02      0.07
AdvancedBookingDays -0.01                1.00          0.01     -0.01
FlyingMinutes       -0.02                0.01          1.00     -0.03
SeatPitch            0.07               -0.01         -0.03      1.00
SeatWidth           -0.06                0.05         -0.18      0.32
                    SeatWidth
Price                   -0.06
AdvancedBookingDays      0.05
FlyingMinutes           -0.18
SeatPitch                0.32
SeatWidth                1.00

n= 305 


P
                    Price  AdvancedBookingDays FlyingMinutes SeatPitch
Price                      0.8732              0.7513        0.1942   
AdvancedBookingDays 0.8732                     0.9292        0.8052   
FlyingMinutes       0.7513 0.9292                            0.5521   
SeatPitch           0.1942 0.8052              0.5521                 
SeatWidth           0.2998 0.3411              0.0013        0.0000   
                    SeatWidth
Price               0.2998   
AdvancedBookingDays 0.3411   
FlyingMinutes       0.0013   
SeatPitch           0.0000   
SeatWidth                    

7c. Farrar - Glauber Test

The mctest package in R provides the Farrar-Glauber test and other relevant tests for multicollinearity. There are two functions viz. omcdiag() and imcdiag() under mctest package in R which will provide the overall and individual diagnostic checking for multicollinearity respectively.

library(mctest)
omcdiag(as.matrix(expVar), Price)

Call:
omcdiag(x = as.matrix(expVar), y = Price)


Overall Multicollinearity Diagnostics

                       MC Results detection
Determinant |X'X|:         0.8511         0
Farrar Chi-Square:        48.5237         1
Red Indicator:             0.1222         0
Sum of Lambda Inverse:     5.3489         0
Theil's Method:           -3.6906         0
Condition Number:        151.2290         1

1 --> COLLINEARITY is detected by the test 
0 --> COLLINEARITY is not detected by the test
imcdiag(expVar, Price)

Call:
imcdiag(x = expVar, y = Price)


All Individual Multicollinearity Diagnostics Result

                       VIF    TOL      Wi      Fi Leamer CVIF Klein
Price               1.0145 0.9857  1.0912  1.4597 0.9928    0     0
AdvancedBookingDays 1.0044 0.9956  0.3296  0.4410 0.9978    0     0
FlyingMinutes       1.0367 0.9646  2.7531  3.6830 0.9821    0     0
SeatPitch           1.1269 0.8874  9.5161 12.7304 0.9420    0     0
SeatWidth           1.1664 0.8573 12.4809 16.6967 0.9259    0     0

1 --> COLLINEARITY is detected by the test 
0 --> COLLINEARITY is not detected by the test

AdvancedBookingDays , SeatPitch , SeatWidth , coefficient(s) are non-significant may be due to multicollinearity

R-square of y on all x: 1 

* use method argument to check which regressors may be the reason of collinearity


***