1. Read Data

# Read Data directly
t = "F:/NGHIEN CUU SINH/NCS - PHUONG ANH/Part 2-Satisfaction and Loyalty/So lieu/So lieu - PA xu ly/873_Loyaltyofbuspassenger_PAcode_NonBus_Mising data_outliers_forMLM_Analyse.csv"
DataLOY = read.csv(t, header = T)
head(DataLOY)
##   ID AGE CITY FRE TripPurpose Departure TimeUseonBus TravelTime PSSW PSSS PSAB
## 1  3   1    2   1           5         0            4       3.00  4.9  5.4  5.5
## 2  4   1    2   2           7         0            4       2.00  3.4  2.4  3.5
## 3  5   1    2   1           5         1            4       0.17  3.9  3.4  4.5
## 4  6   1    2   1           5         1            1       4.00  4.1  4.4  5.5
## 5  7   1    2   1           5         1            4       2.00  3.7  2.6  3.5
## 6  8   1    2   1           5         1            6       2.00  4.6  2.7  3.8
##   PSEB PSQ SAT LOY IMA PHB PEV ATM PPI SIM PPA SBE EXB EC_Stop WC_Stop EC_Bus
## 1  5.8 4.8 6.0 5.7 5.6 6.6 4.0 4.3 6.0 3.5 4.5 4.0 4.8       2       1      2
## 2  6.0 4.6 4.7 4.3 4.8 4.0 5.3 4.1 4.0 4.0 4.0 4.8 4.2       2       2      1
## 3  4.5 2.7 2.0 3.7 3.0 5.0 5.8 3.1 2.7 3.5 4.5 6.0 4.0       2       2      2
## 4  6.0 4.8 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0       2       1      2
## 5  4.5 4.5 4.0 4.6 4.6 5.6 6.0 3.3 3.0 5.5 5.0 5.0 4.2       2       1      2
## 6  4.0 3.9 4.7 4.4 3.0 5.4 5.3 2.7 3.0 2.0 2.5 2.0 5.0       2       1      2
##   WC_Bus Gender MarriedStatus Occupation Education Income
## 1      1      2             1          1         2      1
## 2      2      2             1          1         2      1
## 3      2      1             1          1         2      1
## 4      1      1             1          1         2      1
## 5      1      1             1          1         2      1
## 6      1      2             1          1         3      1
names(DataLOY)
##  [1] "ID"            "AGE"           "CITY"          "FRE"          
##  [5] "TripPurpose"   "Departure"     "TimeUseonBus"  "TravelTime"   
##  [9] "PSSW"          "PSSS"          "PSAB"          "PSEB"         
## [13] "PSQ"           "SAT"           "LOY"           "IMA"          
## [17] "PHB"           "PEV"           "ATM"           "PPI"          
## [21] "SIM"           "PPA"           "SBE"           "EXB"          
## [25] "EC_Stop"       "WC_Stop"       "EC_Bus"        "WC_Bus"       
## [29] "Gender"        "MarriedStatus" "Occupation"    "Education"    
## [33] "Income"
dim(DataLOY)
## [1] 873  33

2. Desscriptive statistic

# 2.1 Recoding
# Regroup value of variables
DataLOY$SAT[DataLOY$SAT <2.5] <- 1
DataLOY$SAT[DataLOY$SAT >= 2.5 & DataLOY$SAT <5.5] <- 2
DataLOY$SAT[DataLOY$SAT >= 5.5] <- 3
DataLOY$LOY[DataLOY$LOY <2.5] <- 1
DataLOY$LOY[DataLOY$LOY >= 2.5 & DataLOY$LOY <5.5] <- 2
DataLOY$LOY[DataLOY$LOY >= 5.5] <- 3
# 2.2. Change type of LOY, SAT and other factor variables
head(DataLOY)
##   ID AGE CITY FRE TripPurpose Departure TimeUseonBus TravelTime PSSW PSSS PSAB
## 1  3   1    2   1           5         0            4       3.00  4.9  5.4  5.5
## 2  4   1    2   2           7         0            4       2.00  3.4  2.4  3.5
## 3  5   1    2   1           5         1            4       0.17  3.9  3.4  4.5
## 4  6   1    2   1           5         1            1       4.00  4.1  4.4  5.5
## 5  7   1    2   1           5         1            4       2.00  3.7  2.6  3.5
## 6  8   1    2   1           5         1            6       2.00  4.6  2.7  3.8
##   PSEB PSQ SAT LOY IMA PHB PEV ATM PPI SIM PPA SBE EXB EC_Stop WC_Stop EC_Bus
## 1  5.8 4.8   3   3 5.6 6.6 4.0 4.3 6.0 3.5 4.5 4.0 4.8       2       1      2
## 2  6.0 4.6   2   2 4.8 4.0 5.3 4.1 4.0 4.0 4.0 4.8 4.2       2       2      1
## 3  4.5 2.7   1   2 3.0 5.0 5.8 3.1 2.7 3.5 4.5 6.0 4.0       2       2      2
## 4  6.0 4.8   2   2 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0       2       1      2
## 5  4.5 4.5   2   2 4.6 5.6 6.0 3.3 3.0 5.5 5.0 5.0 4.2       2       1      2
## 6  4.0 3.9   2   2 3.0 5.4 5.3 2.7 3.0 2.0 2.5 2.0 5.0       2       1      2
##   WC_Bus Gender MarriedStatus Occupation Education Income
## 1      1      2             1          1         2      1
## 2      2      2             1          1         2      1
## 3      2      1             1          1         2      1
## 4      1      1             1          1         2      1
## 5      1      1             1          1         2      1
## 6      1      2             1          1         3      1
str(DataLOY)
## 'data.frame':    873 obs. of  33 variables:
##  $ ID           : int  3 4 5 6 7 8 10 11 12 13 ...
##  $ AGE          : int  1 1 1 1 1 1 4 1 1 2 ...
##  $ CITY         : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : int  1 2 1 1 1 1 1 1 1 1 ...
##  $ TripPurpose  : int  5 7 5 5 5 5 4 5 5 5 ...
##  $ Departure    : int  0 0 1 1 1 1 1 1 0 1 ...
##  $ TimeUseonBus : int  4 4 4 1 4 6 4 4 3 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 2 2.5 1.5 2 ...
##  $ PSSW         : num  4.9 3.4 3.9 4.1 3.7 4.6 3.9 3.4 5.3 4 ...
##  $ PSSS         : num  5.4 2.4 3.4 4.4 2.6 2.7 4 2.7 3.1 4.7 ...
##  $ PSAB         : num  5.5 3.5 4.5 5.5 3.5 3.8 6 3.5 4.8 5.5 ...
##  $ PSEB         : num  5.8 6 4.5 6 4.5 4 4.5 6.3 7 4.5 ...
##  $ PSQ          : num  4.8 4.6 2.7 4.8 4.5 3.9 4.2 4.1 6 4.5 ...
##  $ SAT          : num  3 2 1 2 2 2 3 2 3 3 ...
##  $ LOY          : num  3 2 2 2 2 2 3 2 3 3 ...
##  $ IMA          : num  5.6 4.8 3 5 4.6 3 5.8 5.8 6.8 6 ...
##  $ PHB          : num  6.6 4 5 5 5.6 5.4 5.8 5.6 7 6.4 ...
##  $ PEV          : num  4 5.3 5.8 5 6 5.3 6.3 6.5 7 5.3 ...
##  $ ATM          : num  4.3 4.1 3.1 5 3.3 2.7 4 4.1 4.4 3.9 ...
##  $ PPI          : num  6 4 2.7 5 3 3 6 2 3.3 5.3 ...
##  $ SIM          : num  3.5 4 3.5 5 5.5 2 6 5.3 4.3 6 ...
##  $ PPA          : num  4.5 4 4.5 5 5 2.5 4 4 4 4.3 ...
##  $ SBE          : num  4 4.8 6 5 5 2 5.3 4 5 3.8 ...
##  $ EXB          : num  4.8 4.2 4 5 4.2 5 5.3 5.3 5.3 5 ...
##  $ EC_Stop      : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ WC_Stop      : int  1 2 2 1 1 1 2 1 2 2 ...
##  $ EC_Bus       : int  2 1 2 2 2 2 2 2 2 2 ...
##  $ WC_Bus       : int  1 2 2 1 1 1 2 1 2 2 ...
##  $ Gender       : int  2 2 1 1 1 2 2 2 2 1 ...
##  $ MarriedStatus: int  1 1 1 1 1 1 2 1 1 1 ...
##  $ Occupation   : int  1 1 1 1 1 1 2 1 1 7 ...
##  $ Education    : int  2 2 2 2 2 3 1 2 3 5 ...
##  $ Income       : int  1 1 1 1 1 1 1 1 1 1 ...
attach(DataLOY)
DataLOY = within(DataLOY, {
  AGE = factor(AGE, labels = c("16-25", "26-35", "36-45", "46-55", ">55"))
  CITY = factor(CITY,labels = c("DaNang", "HoChiMinh"))
  FRE = factor(FRE, labels = c(">=3 days/week", "2days/month-2days/week", "2days/year-1day/month", "<2 days/year"))
  TripPurpose = factor(TripPurpose, labels = c("Working", "Studying", "Shopping", "Entertaining", "Others"))
  Departure = factor(Departure, labels = c("Normal", "Peak-Hour"))
  TimeUseonBus = factor(TimeUseonBus, labels = c("Using.telephone", "Reading", "Listening", "Nothing", "Talking", "Others"))
  SAT = factor(SAT, labels = c("Not satisfied", "Normal", "Satisfied"))
  LOY = factor(LOY, labels = c("Notloyal", "Normal", "Loyal"))
  EC_Stop = factor(EC_Stop, labels = c("Ever", "Never"))
  WC_Stop = factor(WC_Stop, labels = c("Ever", "Never"))
  EC_Bus = factor(EC_Bus, labels = c("Ever", "Never"))
  WC_Bus = factor(WC_Bus, labels = c("Ever", "Never"))
  Gender = factor(Gender, labels = c("Male", "Female"))
  MarriedStatus = factor(MarriedStatus, labels = c("Single", "Married"))
  Occupation = factor(Occupation, labels = c("Students/Pupils", "Full.time.job", "Part.time.job", "Retirement", "No.job", "Housewife", "Others"))
  Education = factor(Education, labels = c("Secondary.school", "Undergraduate", "High.school", "Postgraduate", "Others"))
  Income = factor(Income, labels = c("<5millions", "5-10millions", "10-15millions", ">15millions"))
    } )
str(DataLOY)
## 'data.frame':    873 obs. of  33 variables:
##  $ ID           : int  3 4 5 6 7 8 10 11 12 13 ...
##  $ AGE          : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 3 1 1 2 ...
##  $ CITY         : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : Factor w/ 4 levels ">=3 days/week",..: 1 2 1 1 1 1 1 1 1 1 ...
##  $ TripPurpose  : Factor w/ 5 levels "Working","Studying",..: 2 4 2 2 2 2 1 2 2 2 ...
##  $ Departure    : Factor w/ 2 levels "Normal","Peak-Hour": 1 1 2 2 2 2 2 2 1 2 ...
##  $ TimeUseonBus : Factor w/ 6 levels "Using.telephone",..: 4 4 4 1 4 6 4 4 3 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 2 2.5 1.5 2 ...
##  $ PSSW         : num  4.9 3.4 3.9 4.1 3.7 4.6 3.9 3.4 5.3 4 ...
##  $ PSSS         : num  5.4 2.4 3.4 4.4 2.6 2.7 4 2.7 3.1 4.7 ...
##  $ PSAB         : num  5.5 3.5 4.5 5.5 3.5 3.8 6 3.5 4.8 5.5 ...
##  $ PSEB         : num  5.8 6 4.5 6 4.5 4 4.5 6.3 7 4.5 ...
##  $ PSQ          : num  4.8 4.6 2.7 4.8 4.5 3.9 4.2 4.1 6 4.5 ...
##  $ SAT          : Factor w/ 3 levels "Not satisfied",..: 3 2 1 2 2 2 3 2 3 3 ...
##  $ LOY          : Factor w/ 3 levels "Notloyal","Normal",..: 3 2 2 2 2 2 3 2 3 3 ...
##  $ IMA          : num  5.6 4.8 3 5 4.6 3 5.8 5.8 6.8 6 ...
##  $ PHB          : num  6.6 4 5 5 5.6 5.4 5.8 5.6 7 6.4 ...
##  $ PEV          : num  4 5.3 5.8 5 6 5.3 6.3 6.5 7 5.3 ...
##  $ ATM          : num  4.3 4.1 3.1 5 3.3 2.7 4 4.1 4.4 3.9 ...
##  $ PPI          : num  6 4 2.7 5 3 3 6 2 3.3 5.3 ...
##  $ SIM          : num  3.5 4 3.5 5 5.5 2 6 5.3 4.3 6 ...
##  $ PPA          : num  4.5 4 4.5 5 5 2.5 4 4 4 4.3 ...
##  $ SBE          : num  4 4.8 6 5 5 2 5.3 4 5 3.8 ...
##  $ EXB          : num  4.8 4.2 4 5 4.2 5 5.3 5.3 5.3 5 ...
##  $ EC_Stop      : Factor w/ 2 levels "Ever","Never": 2 2 2 2 2 2 2 2 2 2 ...
##  $ WC_Stop      : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ EC_Bus       : Factor w/ 2 levels "Ever","Never": 2 1 2 2 2 2 2 2 2 2 ...
##  $ WC_Bus       : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ Gender       : Factor w/ 2 levels "Male","Female": 2 2 1 1 1 2 2 2 2 1 ...
##  $ MarriedStatus: Factor w/ 2 levels "Single","Married": 1 1 1 1 1 1 2 1 1 1 ...
##  $ Occupation   : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 2 1 1 7 ...
##  $ Education    : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 1 2 3 5 ...
##  $ Income       : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
dim(DataLOY)
## [1] 873  33
# 2.3. Descritive Table
library(tableone)
require(tableone)
library(magrittr)
summary(DataLOY)
##        ID           AGE             CITY                         FRE     
##  Min.   :  3.0   16-25:425   DaNang   :422   >=3 days/week         :508  
##  1st Qu.:273.0   26-35:172   HoChiMinh:451   2days/month-2days/week:168  
##  Median :526.0   36-45:105                   2days/year-1day/month : 99  
##  Mean   :521.7   46-55: 77                   <2 days/year          : 98  
##  3rd Qu.:769.0   >55  : 94                                               
##  Max.   :993.0                                                           
##                                                                          
##        TripPurpose      Departure            TimeUseonBus   TravelTime    
##  Working     :305   Normal   :296   Using.telephone:198   Min.   : 0.000  
##  Studying    :303   Peak-Hour:577   Reading        : 53   1st Qu.: 0.500  
##  Shopping    : 60                   Listening      :138   Median : 1.000  
##  Entertaining:100                   Nothing        :428   Mean   : 1.291  
##  Others      :105                   Talking        : 34   3rd Qu.: 2.000  
##                                     Others         : 22   Max.   :20.000  
##                                                                           
##       PSSW            PSSS            PSAB            PSEB      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.300   1st Qu.:3.700   1st Qu.:4.000   1st Qu.:5.500  
##  Median :4.900   Median :4.600   Median :5.500   Median :6.000  
##  Mean   :4.768   Mean   :4.478   Mean   :5.047   Mean   :5.786  
##  3rd Qu.:5.400   3rd Qu.:5.400   3rd Qu.:6.000   3rd Qu.:6.300  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       PSQ                   SAT            LOY           IMA       
##  Min.   :1.000   Not satisfied: 16   Notloyal: 12   Min.   :1.000  
##  1st Qu.:4.800   Normal       :347   Normal  :342   1st Qu.:4.800  
##  Median :5.400   Satisfied    :510   Loyal   :519   Median :5.600  
##  Mean   :5.226                                      Mean   :5.338  
##  3rd Qu.:5.800                                      3rd Qu.:6.000  
##  Max.   :7.000                                      Max.   :7.000  
##                                                                    
##       PHB             PEV             ATM             PPI       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.200   1st Qu.:5.300   1st Qu.:4.300   1st Qu.:3.700  
##  Median :5.800   Median :6.000   Median :5.100   Median :4.300  
##  Mean   :5.611   Mean   :5.619   Mean   :4.979   Mean   :4.373  
##  3rd Qu.:6.200   3rd Qu.:6.300   3rd Qu.:5.900   3rd Qu.:5.300  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       SIM             PPA             SBE            EXB        EC_Stop   
##  Min.   :1.000   Min.   :1.000   Min.   :1.80   Min.   :2.00   Ever : 36  
##  1st Qu.:4.000   1st Qu.:4.000   1st Qu.:4.30   1st Qu.:5.00   Never:837  
##  Median :5.000   Median :5.000   Median :5.30   Median :5.80              
##  Mean   :4.901   Mean   :4.957   Mean   :5.18   Mean   :5.59              
##  3rd Qu.:6.000   3rd Qu.:5.800   3rd Qu.:6.00   3rd Qu.:6.00              
##  Max.   :7.000   Max.   :7.000   Max.   :7.00   Max.   :7.00              
##                                                                           
##   WC_Stop      EC_Bus      WC_Bus       Gender    MarriedStatus
##  Ever :121   Ever : 42   Ever :116   Male  :364   Single :535  
##  Never:752   Never:831   Never:757   Female:509   Married:338  
##                                                                
##                                                                
##                                                                
##                                                                
##                                                                
##            Occupation             Education             Income   
##  Students/Pupils:368   Secondary.school: 57   <5millions   :465  
##  Full.time.job  :305   Undergraduate   :287   5-10millions :249  
##  Part.time.job  : 69   High.school     :368   10-15millions:122  
##  Retirement     : 46   Postgraduate    :106   >15millions  : 37  
##  No.job         :  3   Others          : 55                      
##  Housewife      : 54                                             
##  Others         : 28
library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
Tab1_LOY <- table1(~ PSSW + PSSS + PSAB + PSEB + PSQ + SAT + IMA + PHB + PEV + ATM + PPI + SIM + PPA + SBE + EXB + EC_Stop + WC_Stop + EC_Bus + WC_Bus + Gender + MarriedStatus + Occupation + Education + Income + AGE + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime| LOY , data = DataLOY)
Tab1_LOY
Notloyal
(N=12)
Normal
(N=342)
Loyal
(N=519)
Overall
(N=873)
PSSW
Mean (SD) 3.48 (1.29) 4.40 (0.996) 5.04 (0.908) 4.77 (1.01)
Median [Min, Max] 3.25 [2.00, 6.40] 4.60 [1.00, 7.00] 5.10 [1.00, 7.00] 4.90 [1.00, 7.00]
PSSS
Mean (SD) 3.08 (1.04) 4.02 (1.02) 4.81 (1.15) 4.48 (1.17)
Median [Min, Max] 2.95 [2.00, 5.30] 4.00 [1.00, 6.40] 4.90 [1.00, 7.00] 4.60 [1.00, 7.00]
PSAB
Mean (SD) 3.53 (1.61) 4.51 (1.28) 5.44 (1.07) 5.05 (1.26)
Median [Min, Max] 3.00 [2.00, 7.00] 4.50 [1.00, 7.00] 5.80 [1.00, 7.00] 5.50 [1.00, 7.00]
PSEB
Mean (SD) 4.49 (1.46) 5.44 (1.07) 6.04 (0.727) 5.79 (0.948)
Median [Min, Max] 4.50 [2.30, 7.00] 5.80 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
PSQ
Mean (SD) 3.06 (0.986) 4.71 (0.834) 5.61 (0.607) 5.23 (0.871)
Median [Min, Max] 3.10 [1.20, 4.30] 4.80 [1.00, 7.00] 5.70 [2.90, 7.00] 5.40 [1.00, 7.00]
SAT
Not satisfied 6 (50.0%) 10 (2.9%) 0 (0%) 16 (1.8%)
Normal 6 (50.0%) 254 (74.3%) 87 (16.8%) 347 (39.7%)
Satisfied 0 (0%) 78 (22.8%) 432 (83.2%) 510 (58.4%)
IMA
Mean (SD) 3.75 (1.29) 4.75 (0.971) 5.76 (0.660) 5.34 (0.964)
Median [Min, Max] 3.40 [2.20, 6.00] 4.80 [1.00, 7.00] 6.00 [1.60, 7.00] 5.60 [1.00, 7.00]
PHB
Mean (SD) 4.28 (1.38) 5.05 (1.10) 6.01 (0.666) 5.61 (1.00)
Median [Min, Max] 4.30 [2.00, 6.00] 5.20 [1.00, 7.00] 6.00 [2.00, 7.00] 5.80 [1.00, 7.00]
PEV
Mean (SD) 4.97 (1.47) 5.08 (1.38) 5.99 (0.906) 5.62 (1.21)
Median [Min, Max] 5.75 [2.00, 6.50] 5.30 [1.00, 7.00] 6.00 [1.00, 7.00] 6.00 [1.00, 7.00]
ATM
Mean (SD) 3.38 (1.43) 4.37 (1.03) 5.42 (1.02) 4.98 (1.16)
Median [Min, Max] 3.35 [1.00, 6.00] 4.40 [1.00, 6.40] 5.70 [1.00, 7.00] 5.10 [1.00, 7.00]
PPI
Mean (SD) 3.37 (1.47) 3.95 (1.33) 4.67 (1.39) 4.37 (1.41)
Median [Min, Max] 2.85 [1.70, 6.00] 4.00 [1.00, 7.00] 5.00 [1.00, 7.00] 4.30 [1.00, 7.00]
SIM
Mean (SD) 4.08 (1.63) 4.42 (1.07) 5.24 (1.05) 4.90 (1.14)
Median [Min, Max] 4.00 [1.80, 6.00] 4.30 [1.00, 7.00] 5.50 [1.00, 7.00] 5.00 [1.00, 7.00]
PPA
Mean (SD) 3.96 (1.30) 4.60 (0.876) 5.21 (1.02) 4.96 (1.02)
Median [Min, Max] 4.00 [2.00, 6.00] 4.50 [1.00, 7.00] 5.50 [1.00, 7.00] 5.00 [1.00, 7.00]
SBE
Mean (SD) 4.32 (1.23) 4.88 (0.990) 5.40 (1.02) 5.18 (1.05)
Median [Min, Max] 4.15 [2.00, 6.00] 5.00 [1.80, 7.00] 5.80 [1.80, 7.00] 5.30 [1.80, 7.00]
EXB
Mean (SD) 3.63 (1.10) 5.03 (0.837) 6.00 (0.595) 5.59 (0.881)
Median [Min, Max] 3.65 [2.00, 6.00] 5.00 [2.00, 7.00] 6.00 [3.70, 7.00] 5.80 [2.00, 7.00]
EC_Stop
Ever 1 (8.3%) 21 (6.1%) 14 (2.7%) 36 (4.1%)
Never 11 (91.7%) 321 (93.9%) 505 (97.3%) 837 (95.9%)
WC_Stop
Ever 2 (16.7%) 65 (19.0%) 54 (10.4%) 121 (13.9%)
Never 10 (83.3%) 277 (81.0%) 465 (89.6%) 752 (86.1%)
EC_Bus
Ever 2 (16.7%) 20 (5.8%) 20 (3.9%) 42 (4.8%)
Never 10 (83.3%) 322 (94.2%) 499 (96.1%) 831 (95.2%)
WC_Bus
Ever 2 (16.7%) 58 (17.0%) 56 (10.8%) 116 (13.3%)
Never 10 (83.3%) 284 (83.0%) 463 (89.2%) 757 (86.7%)
Gender
Male 6 (50.0%) 152 (44.4%) 206 (39.7%) 364 (41.7%)
Female 6 (50.0%) 190 (55.6%) 313 (60.3%) 509 (58.3%)
MarriedStatus
Single 8 (66.7%) 247 (72.2%) 280 (53.9%) 535 (61.3%)
Married 4 (33.3%) 95 (27.8%) 239 (46.1%) 338 (38.7%)
Occupation
Students/Pupils 7 (58.3%) 178 (52.0%) 183 (35.3%) 368 (42.2%)
Full.time.job 5 (41.7%) 118 (34.5%) 182 (35.1%) 305 (34.9%)
Part.time.job 0 (0%) 19 (5.6%) 50 (9.6%) 69 (7.9%)
Retirement 0 (0%) 9 (2.6%) 37 (7.1%) 46 (5.3%)
No.job 0 (0%) 0 (0%) 3 (0.6%) 3 (0.3%)
Housewife 0 (0%) 12 (3.5%) 42 (8.1%) 54 (6.2%)
Others 0 (0%) 6 (1.8%) 22 (4.2%) 28 (3.2%)
Education
Secondary.school 0 (0%) 14 (4.1%) 43 (8.3%) 57 (6.5%)
Undergraduate 2 (16.7%) 110 (32.2%) 175 (33.7%) 287 (32.9%)
High.school 10 (83.3%) 157 (45.9%) 201 (38.7%) 368 (42.2%)
Postgraduate 0 (0%) 43 (12.6%) 63 (12.1%) 106 (12.1%)
Others 0 (0%) 18 (5.3%) 37 (7.1%) 55 (6.3%)
Income
<5millions 5 (41.7%) 187 (54.7%) 273 (52.6%) 465 (53.3%)
5-10millions 3 (25.0%) 101 (29.5%) 145 (27.9%) 249 (28.5%)
10-15millions 3 (25.0%) 39 (11.4%) 80 (15.4%) 122 (14.0%)
>15millions 1 (8.3%) 15 (4.4%) 21 (4.0%) 37 (4.2%)
AGE
16-25 8 (66.7%) 214 (62.6%) 203 (39.1%) 425 (48.7%)
26-35 2 (16.7%) 68 (19.9%) 102 (19.7%) 172 (19.7%)
36-45 1 (8.3%) 27 (7.9%) 77 (14.8%) 105 (12.0%)
46-55 1 (8.3%) 21 (6.1%) 55 (10.6%) 77 (8.8%)
>55 0 (0%) 12 (3.5%) 82 (15.8%) 94 (10.8%)
CITY
DaNang 2 (16.7%) 136 (39.8%) 284 (54.7%) 422 (48.3%)
HoChiMinh 10 (83.3%) 206 (60.2%) 235 (45.3%) 451 (51.7%)
FRE
>=3 days/week 4 (33.3%) 179 (52.3%) 325 (62.6%) 508 (58.2%)
2days/month-2days/week 2 (16.7%) 62 (18.1%) 104 (20.0%) 168 (19.2%)
2days/year-1day/month 2 (16.7%) 49 (14.3%) 48 (9.2%) 99 (11.3%)
<2 days/year 4 (33.3%) 52 (15.2%) 42 (8.1%) 98 (11.2%)
TripPurpose
Working 4 (33.3%) 114 (33.3%) 187 (36.0%) 305 (34.9%)
Studying 4 (33.3%) 135 (39.5%) 164 (31.6%) 303 (34.7%)
Shopping 0 (0%) 13 (3.8%) 47 (9.1%) 60 (6.9%)
Entertaining 1 (8.3%) 45 (13.2%) 54 (10.4%) 100 (11.5%)
Others 3 (25.0%) 35 (10.2%) 67 (12.9%) 105 (12.0%)
Departure
Normal 5 (41.7%) 105 (30.7%) 186 (35.8%) 296 (33.9%)
Peak-Hour 7 (58.3%) 237 (69.3%) 333 (64.2%) 577 (66.1%)
TimeUseonBus
Using.telephone 3 (25.0%) 79 (23.1%) 116 (22.4%) 198 (22.7%)
Reading 1 (8.3%) 19 (5.6%) 33 (6.4%) 53 (6.1%)
Listening 1 (8.3%) 64 (18.7%) 73 (14.1%) 138 (15.8%)
Nothing 5 (41.7%) 156 (45.6%) 267 (51.4%) 428 (49.0%)
Talking 1 (8.3%) 11 (3.2%) 22 (4.2%) 34 (3.9%)
Others 1 (8.3%) 13 (3.8%) 8 (1.5%) 22 (2.5%)
TravelTime
Mean (SD) 1.67 (2.69) 1.35 (1.65) 1.24 (1.29) 1.29 (1.46)
Median [Min, Max] 1.00 [0, 10.0] 1.00 [0, 20.0] 1.00 [0.100, 20.0] 1.00 [0, 20.0]
library(compareGroups)
Des_LOY <- compareGroups(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + SAT + IMA + PHB + PEV + ATM + PPI + SIM + PPA + SBE + EXB + EC_Stop + WC_Stop + EC_Bus + WC_Bus + Gender + MarriedStatus + Occupation + Education + Income + AGE + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime, data = DataLOY)
createTable(Des_LOY)
## 
## --------Summary descriptives table by 'LOY'---------
## 
## ________________________________________________________________________ 
##                             Notloyal     Normal       Loyal    p.overall 
##                               N=12        N=342       N=519              
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
## PSSW                       3.48 (1.29) 4.40 (1.00) 5.04 (0.91)  <0.001   
## PSSS                       3.08 (1.04) 4.02 (1.02) 4.81 (1.15)  <0.001   
## PSAB                       3.53 (1.61) 4.51 (1.28) 5.44 (1.07)  <0.001   
## PSEB                       4.49 (1.46) 5.44 (1.07) 6.04 (0.73)  <0.001   
## PSQ                        3.06 (0.99) 4.71 (0.83) 5.61 (0.61)  <0.001   
## SAT:                                                            <0.001   
##     Not satisfied           6 (50.0%)  10 (2.92%)   0 (0.00%)            
##     Normal                  6 (50.0%)  254 (74.3%) 87 (16.8%)            
##     Satisfied               0 (0.00%)  78 (22.8%)  432 (83.2%)           
## IMA                        3.75 (1.29) 4.75 (0.97) 5.76 (0.66)  <0.001   
## PHB                        4.28 (1.38) 5.05 (1.10) 6.01 (0.67)  <0.001   
## PEV                        4.97 (1.47) 5.08 (1.38) 5.99 (0.91)  <0.001   
## ATM                        3.38 (1.43) 4.37 (1.03) 5.42 (1.02)  <0.001   
## PPI                        3.37 (1.47) 3.95 (1.33) 4.67 (1.39)  <0.001   
## SIM                        4.08 (1.63) 4.42 (1.07) 5.24 (1.05)  <0.001   
## PPA                        3.96 (1.30) 4.60 (0.88) 5.21 (1.02)  <0.001   
## SBE                        4.32 (1.23) 4.88 (0.99) 5.40 (1.02)  <0.001   
## EXB                        3.63 (1.10) 5.03 (0.84) 6.00 (0.60)  <0.001   
## EC_Stop:                                                         0.026   
##     Ever                    1 (8.33%)  21 (6.14%)  14 (2.70%)            
##     Never                  11 (91.7%)  321 (93.9%) 505 (97.3%)           
## WC_Stop:                                                         0.001   
##     Ever                    2 (16.7%)  65 (19.0%)  54 (10.4%)            
##     Never                  10 (83.3%)  277 (81.0%) 465 (89.6%)           
## EC_Bus:                                                          0.058   
##     Ever                    2 (16.7%)  20 (5.85%)  20 (3.85%)            
##     Never                  10 (83.3%)  322 (94.2%) 499 (96.1%)           
## WC_Bus:                                                          0.024   
##     Ever                    2 (16.7%)  58 (17.0%)  56 (10.8%)            
##     Never                  10 (83.3%)  284 (83.0%) 463 (89.2%)           
## Gender:                                                          0.323   
##     Male                    6 (50.0%)  152 (44.4%) 206 (39.7%)           
##     Female                  6 (50.0%)  190 (55.6%) 313 (60.3%)           
## MarriedStatus:                                                  <0.001   
##     Single                  8 (66.7%)  247 (72.2%) 280 (53.9%)           
##     Married                 4 (33.3%)  95 (27.8%)  239 (46.1%)           
## Occupation:                                                        .     
##     Students/Pupils         7 (58.3%)  178 (52.0%) 183 (35.3%)           
##     Full.time.job           5 (41.7%)  118 (34.5%) 182 (35.1%)           
##     Part.time.job           0 (0.00%)  19 (5.56%)  50 (9.63%)            
##     Retirement              0 (0.00%)   9 (2.63%)  37 (7.13%)            
##     No.job                  0 (0.00%)   0 (0.00%)   3 (0.58%)            
##     Housewife               0 (0.00%)  12 (3.51%)  42 (8.09%)            
##     Others                  0 (0.00%)   6 (1.75%)  22 (4.24%)            
## Education:                                                         .     
##     Secondary.school        0 (0.00%)  14 (4.09%)  43 (8.29%)            
##     Undergraduate           2 (16.7%)  110 (32.2%) 175 (33.7%)           
##     High.school            10 (83.3%)  157 (45.9%) 201 (38.7%)           
##     Postgraduate            0 (0.00%)  43 (12.6%)  63 (12.1%)            
##     Others                  0 (0.00%)  18 (5.26%)  37 (7.13%)            
## Income:                                                            .     
##     <5millions              5 (41.7%)  187 (54.7%) 273 (52.6%)           
##     5-10millions            3 (25.0%)  101 (29.5%) 145 (27.9%)           
##     10-15millions           3 (25.0%)  39 (11.4%)  80 (15.4%)            
##     >15millions             1 (8.33%)  15 (4.39%)  21 (4.05%)            
## AGE:                                                               .     
##     16-25                   8 (66.7%)  214 (62.6%) 203 (39.1%)           
##     26-35                   2 (16.7%)  68 (19.9%)  102 (19.7%)           
##     36-45                   1 (8.33%)  27 (7.89%)  77 (14.8%)            
##     46-55                   1 (8.33%)  21 (6.14%)  55 (10.6%)            
##     >55                     0 (0.00%)  12 (3.51%)  82 (15.8%)            
## CITY:                                                           <0.001   
##     DaNang                  2 (16.7%)  136 (39.8%) 284 (54.7%)           
##     HoChiMinh              10 (83.3%)  206 (60.2%) 235 (45.3%)           
## FRE:                                                               .     
##     >=3 days/week           4 (33.3%)  179 (52.3%) 325 (62.6%)           
##     2days/month-2days/week  2 (16.7%)  62 (18.1%)  104 (20.0%)           
##     2days/year-1day/month   2 (16.7%)  49 (14.3%)  48 (9.25%)            
##     <2 days/year            4 (33.3%)  52 (15.2%)  42 (8.09%)            
## TripPurpose:                                                       .     
##     Working                 4 (33.3%)  114 (33.3%) 187 (36.0%)           
##     Studying                4 (33.3%)  135 (39.5%) 164 (31.6%)           
##     Shopping                0 (0.00%)  13 (3.80%)  47 (9.06%)            
##     Entertaining            1 (8.33%)  45 (13.2%)  54 (10.4%)            
##     Others                  3 (25.0%)  35 (10.2%)  67 (12.9%)            
## Departure:                                                       0.244   
##     Normal                  5 (41.7%)  105 (30.7%) 186 (35.8%)           
##     Peak-Hour               7 (58.3%)  237 (69.3%) 333 (64.2%)           
## TimeUseonBus:                                                      .     
##     Using.telephone         3 (25.0%)  79 (23.1%)  116 (22.4%)           
##     Reading                 1 (8.33%)  19 (5.56%)  33 (6.36%)            
##     Listening               1 (8.33%)  64 (18.7%)  73 (14.1%)            
##     Nothing                 5 (41.7%)  156 (45.6%) 267 (51.4%)           
##     Talking                 1 (8.33%)  11 (3.22%)  22 (4.24%)            
##     Others                  1 (8.33%)  13 (3.80%)   8 (1.54%)            
## TravelTime                 1.67 (2.69) 1.35 (1.65) 1.24 (1.29)   0.393   
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

3. Describe Data by graph

library(magrittr)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.4     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x tidyr::extract()   masks magrittr::extract()
## x dplyr::filter()    masks stats::filter()
## x dplyr::lag()       masks stats::lag()
## x purrr::set_names() masks magrittr::set_names()
library(ggplot2)
library(car)
## Warning: package 'car' was built under R version 4.0.4
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:car':
## 
##     logit
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
hist(DataLOY$PSSW)

# Correlations between LOY and continuous variables of users' perception
Cor1_1 = data.frame(DataLOY$LOY, DataLOY$PSSW, DataLOY$PSSS, DataLOY$PSAB, DataLOY$PSEB, DataLOY$PSQ, DataLOY$SAT, DataLOY$IMA)
pairs.panels(Cor1_1)

Cor1_2 = data.frame(DataLOY$LOY, DataLOY$PHB, DataLOY$PEV, DataLOY$ATM, DataLOY$PPI, DataLOY$SIM, DataLOY$PPA, DataLOY$SBE, DataLOY$EXB)
pairs.panels(Cor1_2)

# Correlation between LOY and variables of users experiences
Cor2 = data.frame(DataLOY$LOY, DataLOY$EC_Stop, DataLOY$WC_Stop, DataLOY$EC_Bus, DataLOY$WC_Bus)
pairs.panels(Cor2)

# Correlation between LOY and variables of travel characteristics
Cor3 = data.frame(DataLOY$LOY, DataLOY$CITY, DataLOY$FRE, DataLOY$TripPurpose, DataLOY$Departure, DataLOY$TimeUseonBus, DataLOY$TravelTime)
pairs.panels(Cor3)

# Correlation between LOY and variables of socioeconomics
Cor4 = data.frame(DataLOY$LOY, DataLOY$Gender, DataLOY$MarriedStatus, DataLOY$Occupation, DataLOY$Education, DataLOY$Income, DataLOY$AGE)
pairs.panels(Cor4)

# Boxplot of variables/CITY
# Chia cot theo cach khac : library(gridExtra) ; grid.arrange(p1, p2, ncol=2)
par(mfrow = c(1,2))
boxplot (DataLOY$PSSW ~ DataLOY$CITY, main = "Perceived Security & Safety on the way to/from bus stops", xlab = "PSSW", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PSSW ~ DataLOY$Gender, main = "Perceived Security & Safety on the way to/from bus stops", xlab = "PSSW", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PSSS ~ DataLOY$CITY, main = "Perceived Security & Safety at bus Stations", xlab = "PSSS", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PSSS ~ DataLOY$Gender, main = "Perceived Security & Safety at bus Stations", xlab = "PSSS", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PSAB ~ DataLOY$CITY, main = "Perceived Safety on Buses", xlab = "PSAB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PSAB ~ DataLOY$Gender, main = "Perceived Safety on Buses", xlab = "PSAB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PSEB ~ DataLOY$CITY, main = "Perceived Security on Buses", xlab = "PSEB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
## Warning in bxp(list(stats = structure(c(4.8, 5.8, 6, 6.5, 7, 3.5, 5, 6, : some
## notches went outside hinges ('box'): maybe set notch=FALSE
boxplot (DataLOY$PSEB ~ DataLOY$Gender, main = "Perceived Security on Buses", xlab = "PSEB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PSQ ~ DataLOY$CITY, main = "Perceived Service Quality", xlab = "PSQ", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PSQ ~ DataLOY$Gender, main = "Perceived Service Quality", xlab = "PSQ", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$IMA ~ DataLOY$CITY, main = "Perceived Image", xlab = "IMA", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$IMA ~ DataLOY$Gender, main = "Perceived Image", xlab = "IMA", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PHB ~ DataLOY$CITY, main = "Perceived Health Benefits", xlab = "PHB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
## Warning in bxp(list(stats = structure(c(4.4, 5.4, 5.8, 6.2, 7, 3.6, 5, 6, : some
## notches went outside hinges ('box'): maybe set notch=FALSE
boxplot (DataLOY$PHB ~ DataLOY$Gender, main = "Perceived Health Benefits", xlab = "PHB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PEV ~ DataLOY$CITY, main = "Perceived Environment Value/Benefits", xlab = "PEV", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PEV ~ DataLOY$Gender, main = "Perceived Environment Value/Benefits", xlab = "PEV", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$ATM ~ DataLOY$CITY, main = "Perceived Atmospheric", xlab = "ATM", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$ATM ~ DataLOY$Gender, main = "Perceived Atmospheric", xlab = "ATM", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PPI ~ DataLOY$CITY, main = "Passenger to Passenger Interaction", xlab = "PPI", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PPI ~ DataLOY$Gender, main = "Passenger to Passenger Interaction", xlab = "PPI", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$SIM ~ DataLOY$CITY, main = "Similarity", xlab = "SIM", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$SIM ~ DataLOY$Gender, main = "Similarity", xlab = "SIM", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$PPA ~ DataLOY$CITY, main = "Perceived Physical Appearance", xlab = "PPA", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$PPA ~ DataLOY$Gender, main = "Perceived Physical Appearance", xlab = "PPA", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$SBE ~ DataLOY$CITY, main = "Perceived Suitable Behavior", xlab = "SBE", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$SBE ~ DataLOY$Gender, main = "Perceived Suitable Behavior", xlab = "SBE", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

boxplot (DataLOY$EXB ~ DataLOY$CITY, main = "Experience on the Bus", xlab = "EXB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Da Nang", "Ho Chi Minh"))
boxplot (DataLOY$EXB ~ DataLOY$Gender, main = "Experience on the Bus", xlab = "EXB", ylab = "Point (1-7)", col = c("Red", "blue"), notch = T, names = c("Male", "Female"))

## LOY ~ EC_Stop
DataLOY %>%
  group_by(LOY, EC_Stop) %>%
  count() %>% 
  ggplot(aes(EC_Stop, n, fill = LOY)) +
  geom_col(position = "fill") +
  xlab("Experienced crime at bus stops") +
  ylab("Perceived loyalty") +
  ggtitle("Experienced crime at bus stops ~ Perceived loyalty")

## LOY ~ WC_Stop
DataLOY %>%
  group_by(LOY, WC_Stop) %>%
  count() %>% 
  ggplot(aes(WC_Stop, n, fill = LOY)) +
  geom_col(position = "fill") +
  xlab("Witnessed crime at bus stops") +
  ylab("Perceived loyalty") +
  ggtitle("Witnessed crime at bus stops ~ Perceived loyalty")

## LOY ~ EC_Bus
DataLOY %>%
  group_by(LOY, EC_Bus) %>%
  count() %>% 
  ggplot(aes(EC_Bus, n, fill = LOY)) +
  geom_col(position = "fill") +
  xlab("Experienced crime on bus") +
  ylab("Perceived loyalty") +
  ggtitle("Experienced crime on bus ~ Perceived loyalty")

## LOY ~ WC_Bus
DataLOY %>%
  group_by(LOY, WC_Bus) %>%
  count() %>% 
  ggplot(aes(WC_Bus, n, fill = LOY)) +
  geom_col(position = "fill") +
  xlab("Witnessed crime on bus") +
  ylab("Perceived loyalty") +
  ggtitle("Witnessed crime on bus ~ Perceived loyalty")

4. Descriptive statistical analysis

summary(DataLOY)
##        ID           AGE             CITY                         FRE     
##  Min.   :  3.0   16-25:425   DaNang   :422   >=3 days/week         :508  
##  1st Qu.:273.0   26-35:172   HoChiMinh:451   2days/month-2days/week:168  
##  Median :526.0   36-45:105                   2days/year-1day/month : 99  
##  Mean   :521.7   46-55: 77                   <2 days/year          : 98  
##  3rd Qu.:769.0   >55  : 94                                               
##  Max.   :993.0                                                           
##                                                                          
##        TripPurpose      Departure            TimeUseonBus   TravelTime    
##  Working     :305   Normal   :296   Using.telephone:198   Min.   : 0.000  
##  Studying    :303   Peak-Hour:577   Reading        : 53   1st Qu.: 0.500  
##  Shopping    : 60                   Listening      :138   Median : 1.000  
##  Entertaining:100                   Nothing        :428   Mean   : 1.291  
##  Others      :105                   Talking        : 34   3rd Qu.: 2.000  
##                                     Others         : 22   Max.   :20.000  
##                                                                           
##       PSSW            PSSS            PSAB            PSEB      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.300   1st Qu.:3.700   1st Qu.:4.000   1st Qu.:5.500  
##  Median :4.900   Median :4.600   Median :5.500   Median :6.000  
##  Mean   :4.768   Mean   :4.478   Mean   :5.047   Mean   :5.786  
##  3rd Qu.:5.400   3rd Qu.:5.400   3rd Qu.:6.000   3rd Qu.:6.300  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       PSQ                   SAT            LOY           IMA       
##  Min.   :1.000   Not satisfied: 16   Notloyal: 12   Min.   :1.000  
##  1st Qu.:4.800   Normal       :347   Normal  :342   1st Qu.:4.800  
##  Median :5.400   Satisfied    :510   Loyal   :519   Median :5.600  
##  Mean   :5.226                                      Mean   :5.338  
##  3rd Qu.:5.800                                      3rd Qu.:6.000  
##  Max.   :7.000                                      Max.   :7.000  
##                                                                    
##       PHB             PEV             ATM             PPI       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:5.200   1st Qu.:5.300   1st Qu.:4.300   1st Qu.:3.700  
##  Median :5.800   Median :6.000   Median :5.100   Median :4.300  
##  Mean   :5.611   Mean   :5.619   Mean   :4.979   Mean   :4.373  
##  3rd Qu.:6.200   3rd Qu.:6.300   3rd Qu.:5.900   3rd Qu.:5.300  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
##                                                                 
##       SIM             PPA             SBE            EXB        EC_Stop   
##  Min.   :1.000   Min.   :1.000   Min.   :1.80   Min.   :2.00   Ever : 36  
##  1st Qu.:4.000   1st Qu.:4.000   1st Qu.:4.30   1st Qu.:5.00   Never:837  
##  Median :5.000   Median :5.000   Median :5.30   Median :5.80              
##  Mean   :4.901   Mean   :4.957   Mean   :5.18   Mean   :5.59              
##  3rd Qu.:6.000   3rd Qu.:5.800   3rd Qu.:6.00   3rd Qu.:6.00              
##  Max.   :7.000   Max.   :7.000   Max.   :7.00   Max.   :7.00              
##                                                                           
##   WC_Stop      EC_Bus      WC_Bus       Gender    MarriedStatus
##  Ever :121   Ever : 42   Ever :116   Male  :364   Single :535  
##  Never:752   Never:831   Never:757   Female:509   Married:338  
##                                                                
##                                                                
##                                                                
##                                                                
##                                                                
##            Occupation             Education             Income   
##  Students/Pupils:368   Secondary.school: 57   <5millions   :465  
##  Full.time.job  :305   Undergraduate   :287   5-10millions :249  
##  Part.time.job  : 69   High.school     :368   10-15millions:122  
##  Retirement     : 46   Postgraduate    :106   >15millions  : 37  
##  No.job         :  3   Others          : 55                      
##  Housewife      : 54                                             
##  Others         : 28
table(LOY) 
## LOY
##   1   2   3 
##  12 342 519
# Descriptive Statistics of categorical variables
with(DataLOY, do.call(rbind, tapply(TravelTime, LOY, function(x) c(M = mean(x), SD = sd(x)))))
##                 M       SD
## Notloyal 1.666667 2.692151
## Normal   1.348763 1.647059
## Loyal    1.243487 1.289686
with(DataLOY, do.call(rbind, tapply(PSSW, LOY, function(x) c(M = mean(x), SD = sd(x)))))
##                 M        SD
## Notloyal 3.475000 1.2899084
## Normal   4.404678 0.9961399
## Loyal    5.037380 0.9076199

5.1. Estimate Multinominal Logit Regression Model - DataLOY for 2 cities

library(mlogitBMA)
## Warning: package 'mlogitBMA' was built under R version 4.0.4
## Loading required package: BMA
## Loading required package: survival
## Loading required package: leaps
## Loading required package: robustbase
## 
## Attaching package: 'robustbase'
## The following object is masked from 'package:survival':
## 
##     heart
## Loading required package: inline
## Loading required package: rrcov
## Scalable Robust Estimators with High Breakdown Point (version 1.5-5)
## Loading required package: abind
## Loading required package: maxLik
## Warning: package 'maxLik' was built under R version 4.0.4
## Loading required package: miscTools
## Warning: package 'miscTools' was built under R version 4.0.4
## 
## Attaching package: 'miscTools'
## The following objects are masked from 'package:robustbase':
## 
##     colMedians, rowMedians
## 
## Please cite the 'maxLik' package as:
## Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
## 
## If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
## https://r-forge.r-project.org/projects/maxlik/
attach(DataLOY)
## The following objects are masked from DataLOY (pos = 30):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
str(DataLOY)
## 'data.frame':    873 obs. of  33 variables:
##  $ ID           : int  3 4 5 6 7 8 10 11 12 13 ...
##  $ AGE          : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 3 1 1 2 ...
##  $ CITY         : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : Factor w/ 4 levels ">=3 days/week",..: 1 2 1 1 1 1 1 1 1 1 ...
##  $ TripPurpose  : Factor w/ 5 levels "Working","Studying",..: 2 4 2 2 2 2 1 2 2 2 ...
##  $ Departure    : Factor w/ 2 levels "Normal","Peak-Hour": 1 1 2 2 2 2 2 2 1 2 ...
##  $ TimeUseonBus : Factor w/ 6 levels "Using.telephone",..: 4 4 4 1 4 6 4 4 3 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 2 2.5 1.5 2 ...
##  $ PSSW         : num  4.9 3.4 3.9 4.1 3.7 4.6 3.9 3.4 5.3 4 ...
##  $ PSSS         : num  5.4 2.4 3.4 4.4 2.6 2.7 4 2.7 3.1 4.7 ...
##  $ PSAB         : num  5.5 3.5 4.5 5.5 3.5 3.8 6 3.5 4.8 5.5 ...
##  $ PSEB         : num  5.8 6 4.5 6 4.5 4 4.5 6.3 7 4.5 ...
##  $ PSQ          : num  4.8 4.6 2.7 4.8 4.5 3.9 4.2 4.1 6 4.5 ...
##  $ SAT          : Factor w/ 3 levels "Not satisfied",..: 3 2 1 2 2 2 3 2 3 3 ...
##  $ LOY          : Factor w/ 3 levels "Notloyal","Normal",..: 3 2 2 2 2 2 3 2 3 3 ...
##  $ IMA          : num  5.6 4.8 3 5 4.6 3 5.8 5.8 6.8 6 ...
##  $ PHB          : num  6.6 4 5 5 5.6 5.4 5.8 5.6 7 6.4 ...
##  $ PEV          : num  4 5.3 5.8 5 6 5.3 6.3 6.5 7 5.3 ...
##  $ ATM          : num  4.3 4.1 3.1 5 3.3 2.7 4 4.1 4.4 3.9 ...
##  $ PPI          : num  6 4 2.7 5 3 3 6 2 3.3 5.3 ...
##  $ SIM          : num  3.5 4 3.5 5 5.5 2 6 5.3 4.3 6 ...
##  $ PPA          : num  4.5 4 4.5 5 5 2.5 4 4 4 4.3 ...
##  $ SBE          : num  4 4.8 6 5 5 2 5.3 4 5 3.8 ...
##  $ EXB          : num  4.8 4.2 4 5 4.2 5 5.3 5.3 5.3 5 ...
##  $ EC_Stop      : Factor w/ 2 levels "Ever","Never": 2 2 2 2 2 2 2 2 2 2 ...
##  $ WC_Stop      : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ EC_Bus       : Factor w/ 2 levels "Ever","Never": 2 1 2 2 2 2 2 2 2 2 ...
##  $ WC_Bus       : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ Gender       : Factor w/ 2 levels "Male","Female": 2 2 1 1 1 2 2 2 2 1 ...
##  $ MarriedStatus: Factor w/ 2 levels "Single","Married": 1 1 1 1 1 1 2 1 1 1 ...
##  $ Occupation   : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 2 1 1 7 ...
##  $ Education    : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 1 2 3 5 ...
##  $ Income       : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
# All variables - rempve: EC_Stop + WC_Stop + EC_Bus + WC_Bus + SAT and variable have cor > 0.7 - AGE, PPA
bma.LOY <- bic.mlogit(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime, data = DataLOY)
## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length
## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length
summary(bma.LOY)
## 
## Call:
## bic.mlogit(f = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA +     PHB + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus +     Occupation + Education + Income + CITY + FRE + TripPurpose +     Departure + TimeUseonBus + TravelTime, data = DataLOY)
## 
## 
##   3  models were selected
##  Best  3  models (cumulative posterior probability =  1 ): 
## 
##                     p!=0    EV      SD      model 1   model 2   model 3 
## Intercept           100    19.7131  1.3528   19.5830   20.0530   19.4016
## Intercept.Notloyal  100.0  15.0010  0.5669   14.8929   15.3089   14.6009
## CITY                  0.0                                               
##     .                       0.0000  0.0000      .         .         .   
## FRE                   0.0                                               
##    .                        0.0000  0.0000      .         .         .   
## TripPurpose           0.0                                               
##            .                0.0000  0.0000      .         .         .   
## Departure             0.0                                               
##          .                  0.0000  0.0000      .         .         .   
## TimeUseonBus          0.0                                               
##             .               0.0000  0.0000      .         .         .   
## TravelTime            0.0   0.0000  0.0000      .         .         .   
## PSSW                  0.0   0.0000  0.0000      .         .         .   
## PSSS                  0.0   0.0000  0.0000      .         .         .   
## PSAB                  0.0   0.0000  0.0000      .         .         .   
## PSEB                  0.0   0.0000  0.0000      .         .         .   
## PSQ                 100.0   0.0000  0.0000      .         .         .   
## IMA                 100.0   0.0000  0.0000      .         .         .   
## PHB                  35.1   0.0000  0.0000      .         .         .   
## PEV                  94.6   0.0000  0.0000      .         .         .   
## ATM                   0.0   0.0000  0.0000      .         .         .   
## PPI                   0.0   0.0000  0.0000      .         .         .   
## SIM                 100.0   0.0000  0.0000      .         .         .   
## SBE                 100.0   0.0000  0.0000      .         .         .   
## EXB                 100.0   0.0000  0.0000      .         .         .   
## Gender                0.0                                               
##       .                    -1.3102  0.1733   -1.3157   -1.3009   -1.2951
## MarriedStatus         0.0                                               
##              .             -0.8294  0.1504   -0.8442   -0.8039   -0.7912
## Occupation            0.0                                               
##           .                -0.1430  0.2167      .      -0.3744   -0.5882
## Education             0.0                                               
##          .                 -0.3601  0.1367   -0.4210   -0.2922      .   
## Income                0.0                                               
##       .                     0.0000  0.0000      .         .         .   
##                                                                         
## nVar                                            4         5         4   
## BIC                                         819.9786  821.5370  824.9627
## post prob                                     0.649     0.298     0.054 
## 
## MNL specification:
## ==================
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept      1     2             3           4
## 1      Loyal:                                                    
## 2     Normal:   asc.Normal + CITY + FRE + TripPurpose + Departure
## 3   Notloyal: asc.Notloyal + CITY + FRE + TripPurpose + Departure
##                5            6      7      8      9     10    11    12    13
## 1                                                                          
## 2 + TimeUseonBus + TravelTime + PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB
## 3 + TimeUseonBus + TravelTime + PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB
##      14    15    16    17    18    19       20              21           22
## 1                                                                          
## 2 + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation
## 3 + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation
##            23       24
## 1                     
## 2 + Education + Income
## 3 + Education + Income
# All variables - rempve: EC_Stop + WC_Stop + EC_Bus + WC_Bus + SAT and variable have cor > 0.7 - AGE, PPA and cor > 0.6 : PHB, PSQ, PSSW, PSAB
bma.LOY3 <- bic.mlogit(LOY ~ PSSS + PSEB + IMA + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime, data = DataLOY)
## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length
summary(bma.LOY3)
## 
## Call:
## bic.mlogit(f = LOY ~ PSSS + PSEB + IMA + PEV + ATM + PPI + SIM +     SBE + EXB + Gender + MarriedStatus + Occupation + Education +     Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus +     TravelTime, data = DataLOY)
## 
## 
##   1  models were selected
##  Best  1  models (cumulative posterior probability =  1 ): 
## 
##                     p!=0   EV      SD       model 1 
## Intercept           100   17.4991  1.20366   17.4991
## Intercept.Notloyal  100   13.0409  0.48623   13.0409
## CITY                  0                             
##     .                      0.0000  0.00000      .   
## FRE                   0                             
##    .                       0.0000  0.00000      .   
## TripPurpose           0                             
##            .               0.0000  0.00000      .   
## Departure             0                             
##          .                 0.0000  0.00000      .   
## TimeUseonBus          0                             
##             .              0.0000  0.00000      .   
## TravelTime            0    0.0000  0.00000      .   
## PSSS                100    0.0000  0.00000      .   
## PSEB                  0    0.0000  0.00000      .   
## IMA                 100    0.0000  0.00000      .   
## PEV                 100    0.0000  0.00000      .   
## ATM                   0    0.0000  0.00000      .   
## PPI                   0    0.0000  0.00000      .   
## SIM                 100    0.0000  0.00000      .   
## SBE                 100    0.0000  0.00000      .   
## EXB                 100    0.0000  0.00000      .   
## Gender                0                             
##       .                   -0.3857  0.09075   -0.3857
## MarriedStatus         0                             
##              .             0.0000  0.00000      .   
## Occupation            0                             
##           .               -1.2094  0.13820   -1.2094
## Education             0                             
##          .                -0.3820  0.08698   -0.3820
## Income                0                             
##       .                    0.0000  0.00000      .   
##                                                     
## nVar                                            4   
## BIC                                         849.7514
## post prob                                     1     
## 
## MNL specification:
## ==================
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept      1     2             3           4
## 1      Loyal:                                                    
## 2     Normal:   asc.Normal + CITY + FRE + TripPurpose + Departure
## 3   Notloyal: asc.Notloyal + CITY + FRE + TripPurpose + Departure
##                5            6      7      8     9    10    11    12    13    14
## 1                                                                              
## 2 + TimeUseonBus + TravelTime + PSSS + PSEB + IMA + PEV + ATM + PPI + SIM + SBE
## 3 + TimeUseonBus + TravelTime + PSSS + PSEB + IMA + PEV + ATM + PPI + SIM + SBE
##      15       16              17           18          19       20
## 1                                                                 
## 2 + EXB + Gender + MarriedStatus + Occupation + Education + Income
## 3 + EXB + Gender + MarriedStatus + Occupation + Education + Income
# Remove 3 variables non significant : Gender, Departure, Travel time compare to bma.LOY
bma.LOY1 <- bic.mlogit(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + TimeUseonBus, data = DataLOY)
## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length

## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length
summary(bma.LOY1)
## 
## Call:
## bic.mlogit(f = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA +     PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus +     Occupation + Education + Income + CITY + FRE + TripPurpose +     TimeUseonBus, data = DataLOY)
## 
## 
##   3  models were selected
##  Best  3  models (cumulative posterior probability =  1 ): 
## 
##                     p!=0    EV      SD      model 1   model 2   model 3 
## Intercept           100    19.7131  1.3528   19.5830   20.0530   19.4016
## Intercept.Notloyal  100.0  15.0010  0.5669   14.8929   15.3089   14.6009
## CITY                  0.0                                               
##     .                       0.0000  0.0000      .         .         .   
## FRE                   0.0                                               
##    .                        0.0000  0.0000      .         .         .   
## TripPurpose           0.0                                               
##            .                0.0000  0.0000      .         .         .   
## TimeUseonBus          0.0                                               
##             .               0.0000  0.0000      .         .         .   
## PSSW                  0.0   0.0000  0.0000      .         .         .   
## PSSS                  0.0   0.0000  0.0000      .         .         .   
## PSAB                  0.0   0.0000  0.0000      .         .         .   
## PSEB                  0.0   0.0000  0.0000      .         .         .   
## PSQ                 100.0   0.0000  0.0000      .         .         .   
## IMA                 100.0   0.0000  0.0000      .         .         .   
## PHB                  35.1   0.0000  0.0000      .         .         .   
## PEV                  94.6   0.0000  0.0000      .         .         .   
## ATM                   0.0   0.0000  0.0000      .         .         .   
## PPI                   0.0   0.0000  0.0000      .         .         .   
## SIM                 100.0   0.0000  0.0000      .         .         .   
## SBE                 100.0   0.0000  0.0000      .         .         .   
## EXB                 100.0   0.0000  0.0000      .         .         .   
## MarriedStatus         0.0                                               
##              .             -1.3102  0.1733   -1.3157   -1.3009   -1.2951
## Occupation            0.0                                               
##           .                -0.8294  0.1504   -0.8442   -0.8039   -0.7912
## Education             0.0                                               
##          .                 -0.1430  0.2167      .      -0.3744   -0.5882
## Income                0.0                                               
##       .                    -0.3601  0.1367   -0.4210   -0.2922      .   
##                                                                         
## nVar                                            4         5         4   
## BIC                                         819.9786  821.5370  824.9627
## post prob                                     0.649     0.298     0.054 
## 
## MNL specification:
## ==================
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept      1     2             3              4      5
## 1      Loyal:                                                              
## 2     Normal:   asc.Normal + CITY + FRE + TripPurpose + TimeUseonBus + PSSW
## 3   Notloyal: asc.Notloyal + CITY + FRE + TripPurpose + TimeUseonBus + PSSW
##        6      7      8     9    10    11    12    13    14    15    16    17
## 1                                                                           
## 2 + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB
## 3 + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB
##                18           19          20       21
## 1                                                  
## 2 + MarriedStatus + Occupation + Education + Income
## 3 + MarriedStatus + Occupation + Education + Income
# Only variables related to personal perception , remove SAT, PPI
bma.LOY2 <- bic.mlogit(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + SIM + PPA + SBE + EXB + CITY, data = DataLOY)
## Warning in new.output.names[names(output.names)[new.idx[i - 1]]] <-
## output.names[[i - : number of items to replace is not a multiple of replacement
## length
summary(bma.LOY2)
## 
## Call:
## bic.mlogit(f = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA +     PHB + PEV + ATM + SIM + PPA + SBE + EXB + CITY, data = DataLOY)
## 
## 
##   10  models were selected
##  Best  5  models (cumulative posterior probability =  0.8542 ): 
## 
##                     p!=0    EV        SD       model 1   model 2   model 3 
## Intercept           100    19.806445  1.37103   19.5830   20.0530   19.9257
## Intercept.Notloyal  100.0  15.085372  0.59154   14.8929   15.3089   15.1966
## CITY                  0.0                                                  
##     .                       0.000000  0.00000      .         .         .   
## PSSW                  2.1  -0.002589  0.02413      .         .         .   
## PSSS                  3.8  -0.005154  0.03229      .         .         .   
## PSAB                  0.0   0.000000  0.00000      .         .         .   
## PSEB                  2.4   0.003422  0.02956      .         .         .   
## PSQ                 100.0  -1.299253  0.17615   -1.3157   -1.3009   -1.2918
## IMA                 100.0  -0.834828  0.15059   -0.8442   -0.8039   -0.8530
## PHB                  32.4  -0.129220  0.20704      .      -0.3744      .   
## PEV                  96.6  -0.375862  0.12819   -0.4210   -0.2922   -0.4439
## ATM                   0.0   0.000000  0.00000      .         .         .   
## SIM                  93.3  -0.356105  0.14446   -0.4087   -0.4019   -0.3067
## PPA                  28.9  -0.119721  0.20887      .         .      -0.3713
## SBE                 100.0   0.610799  0.15560    0.5693    0.5401    0.7451
## EXB                 100.0  -1.255380  0.18204   -1.3008   -1.1675   -1.2763
##                                                                            
## nVar                                               7         8         8   
## BIC                                            819.9786  821.5370  822.0100
## post prob                                        0.407     0.187     0.147 
##                     model 4   model 5 
## Intercept            20.3971   19.6036
## Intercept.Notloyal   15.6208   14.8775
## CITY                                  
##     .                   .         .   
## PSSW                    .         .   
## PSSS                    .      -0.1343
## PSAB                    .         .   
## PSEB                    .         .   
## PSQ                  -1.2735   -1.2285
## IMA                  -0.8131   -0.8588
## PHB                  -0.3781      .   
## PEV                  -0.3171   -0.4009
## ATM                     .         .   
## SIM                  -0.2971   -0.4031
## PPA                  -0.3795      .   
## SBE                   0.7220    0.5827
## EXB                  -1.1409   -1.3032
##                                       
## nVar                    9         8   
## BIC                 823.3629  824.7009
## post prob             0.075     0.038 
## 
## MNL specification:
## ==================
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept      1      2      3      4      5     6     7     8
## 1      Loyal:                                                                  
## 2     Normal:   asc.Normal + CITY + PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB
## 3   Notloyal: asc.Notloyal + CITY + PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB
##       9    10    11    12    13    14
## 1                                    
## 2 + PEV + ATM + SIM + PPA + SBE + EXB
## 3 + PEV + ATM + SIM + PPA + SBE + EXB
# Multinominal Logit Model
   ## Way 1 - Use mlogit (in mlogit package) - Khong dung
   ## Way 2 - Use multinom (in nnet package)
library(nnet)
attach(DataLOY)
## The following objects are masked from DataLOY (pos = 4):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
## The following objects are masked from DataLOY (pos = 32):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
# Model - All variables - rempve: EC_Stop + WC_Stop + EC_Bus + WC_Bus + SAT and variable have cor > 0.7 - AGE, PPA
DataLOY$LOY <- relevel (DataLOY$LOY, ref = "Normal")
mlm <- multinom(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime, data = DataLOY)
## # weights:  135 (88 variable)
## initial  value 959.088528 
## iter  10 value 453.950608
## iter  20 value 352.250834
## iter  30 value 332.503203
## iter  40 value 316.998887
## iter  50 value 304.252876
## iter  60 value 295.668752
## iter  70 value 290.059617
## iter  80 value 290.007156
## final  value 290.007100 
## converged
summary(mlm)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## multinom(formula = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + 
##     PHB + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + 
##     Occupation + Education + Income + CITY + FRE + TripPurpose + 
##     Departure + TimeUseonBus + TravelTime, data = DataLOY)
## 
## Coefficients:
##          (Intercept)          PSSW        PSSS        PSAB       PSEB
## Notloyal   321.65863 -3.998656e+01 -13.2782936 32.11904148 11.5846313
## Loyal      -19.61627  2.841991e-05   0.1305778 -0.09042967 -0.1085531
##                 PSQ        IMA         PHB        PEV       ATM         PPI
## Notloyal -83.678637 -11.975128 -40.0186353 43.1496270 8.5890689 -4.78048461
## Loyal      1.124745   1.085532   0.3697361  0.4033366 0.1020622 -0.01930062
##                 SIM        SBE         EXB GenderFemale MarriedStatusMarried
## Notloyal 10.8172060 48.1616619 -85.7155032  -14.2277213          185.7306743
## Loyal     0.5259931 -0.6753868   0.9851403    0.2167796            0.5413487
##          OccupationFull.time.job OccupationPart.time.job OccupationRetirement
## Notloyal            -246.4583127             -254.311302           -131.17934
## Loyal                  0.4449424                1.367044              1.35764
##          OccupationNo.job OccupationHousewife OccupationOthers
## Notloyal         103.0764         -115.847663      -319.479805
## Loyal            265.5093            0.806828         0.446782
##          EducationUndergraduate EducationHigh.school EducationPostgraduate
## Notloyal            -32.8082866          128.9417664             30.353026
## Loyal                -0.2352182           -0.7134174             -0.719562
##          EducationOthers Income5-10millions Income10-15millions
## Notloyal      115.180634         31.3949930         157.8417421
## Loyal          -0.875494         -0.3906108           0.5066374
##          Income>15millions CITYHoChiMinh FRE2days/month-2days/week
## Notloyal      -187.4191561    32.2056836                 3.6049167
## Loyal            0.1473969     0.0112766                -0.1518838
##          FRE2days/year-1day/month FRE<2 days/year TripPurposeStudying
## Notloyal               -43.718210       -4.070659           6.7120707
## Loyal                   -1.313819       -1.240355           0.4223585
##          TripPurposeShopping TripPurposeEntertaining TripPurposeOthers
## Notloyal        137.56006575              53.3667563        53.9688266
## Loyal             0.01141173              -0.2367265         0.0153024
##          DeparturePeak-Hour TimeUseonBusReading TimeUseonBusListening
## Notloyal        -90.0779462         -63.6792007           -45.2935586
## Loyal            -0.2274571           0.9514671             0.1684674
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers TravelTime
## Notloyal        -34.47060377           49.654156       -42.99992612  0.8095944
## Loyal            -0.08913576           -0.220101         0.05227977 -0.2182342
## 
## Std. Errors:
##          (Intercept)      PSSW      PSSS       PSAB       PSEB        PSQ
## Notloyal    2.715091 7.8419680 7.1134876 11.7136338 14.1565669 12.3642321
## Loyal       1.763570 0.1571821 0.1359787  0.1251969  0.1447274  0.2257357
##                 IMA      PHB        PEV        ATM         PPI        SIM
## Notloyal 12.3830689 13.66067 14.7215674 12.2046501 11.31223342 12.4896476
## Loyal     0.1819016  0.16518  0.1199103  0.1356465  0.09432754  0.1225799
##                 SBE        EXB GenderFemale MarriedStatusMarried
## Notloyal 13.8147540 13.4473089    2.1788845            1.4150799
## Loyal     0.1586131  0.1945776    0.2375803            0.3419758
##          OccupationFull.time.job OccupationPart.time.job OccupationRetirement
## Notloyal               1.4625207                     NaN                  NaN
## Loyal                  0.5360589               0.5870125            0.6809328
##          OccupationNo.job OccupationHousewife OccupationOthers
## Notloyal     1.740837e-12        1.757861e-11      0.002632499
## Loyal        1.615448e-32        6.723880e-01      0.876885108
##          EducationUndergraduate EducationHigh.school EducationPostgraduate
## Notloyal              0.3734500             2.339009          0.0001052767
## Loyal                 0.5178708             0.525864          0.6036034852
##          EducationOthers Income5-10millions Income10-15millions
## Notloyal     0.002527222          0.8578368           0.6073165
## Loyal        0.665109294          0.3757588           0.5016978
##          Income>15millions CITYHoChiMinh FRE2days/month-2days/week
## Notloyal         0.1591323     2.0806846              0.0006658904
## Loyal            0.7389645     0.2747704              0.3037308445
##          FRE2days/year-1day/month FRE<2 days/year TripPurposeStudying
## Notloyal                0.8580611       1.2794331           0.5948624
## Loyal                   0.4262825       0.4456464           0.4168705
##          TripPurposeShopping TripPurposeEntertaining TripPurposeOthers
## Notloyal           0.5546039               1.3547296         0.1591309
## Loyal              0.5443258               0.4544956         0.4768115
##          DeparturePeak-Hour TimeUseonBusReading TimeUseonBusListening
## Notloyal          0.4870490         0.002527223          4.777538e-06
## Loyal             0.2408429         0.580925599          3.427102e-01
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers TravelTime
## Notloyal           1.0874769                 NaN       1.874612e-13  2.0575057
## Loyal              0.2768653            0.620583       8.166636e-01  0.0985532
## 
## Residual Deviance: 580.0142 
## AIC: 756.0142
exp(coef(mlm))
##            (Intercept)         PSSW         PSSS         PSAB         PSEB
## Notloyal 4.949585e+139 4.305825e-18 1.711238e-06 8.894519e+13 1.074339e+05
## Loyal     3.025259e-09 1.000028e+00 1.139487e+00 9.135386e-01 8.971313e-01
##                   PSQ          IMA          PHB          PEV         ATM
## Notloyal 4.558582e-37 6.298945e-06 4.169918e-18 5.490917e+18 5372.608999
## Loyal    3.079433e+00 2.961015e+00 1.447353e+00 1.496811e+00    1.107452
##                  PPI          SIM          SBE          EXB GenderFemale
## Notloyal 0.008391931 49871.551072 8.247912e+20 5.946069e-38 6.621847e-07
## Loyal    0.980884447     1.692138 5.089595e-01 2.678188e+00 1.242070e+00
##          MarriedStatusMarried OccupationFull.time.job OccupationPart.time.job
## Notloyal         4.589940e+80           9.215412e-108           3.581004e-111
## Loyal            1.718323e+00            1.560400e+00            3.923737e+00
##          OccupationRetirement OccupationNo.job OccupationHousewife
## Notloyal         1.070374e-57     5.827626e+44        4.875274e-51
## Loyal            3.887008e+00    2.038165e+115        2.240789e+00
##          OccupationOthers EducationUndergraduate EducationHigh.school
## Notloyal    1.785186e-139           5.643418e-15         9.970057e+55
## Loyal        1.563274e+00           7.903983e-01         4.899669e-01
##          EducationPostgraduate EducationOthers Income5-10millions
## Notloyal          1.521079e+13    1.052722e+50       4.311935e+13
## Loyal             4.869655e-01    4.166561e-01       6.766434e-01
##          Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal        3.546481e+68      4.026194e-82   9.69953e+13
## Loyal           1.659701e+00      1.158814e+00   1.01134e+00
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal                36.7786203             1.031389e-19      0.01706614
## Loyal                    0.8590881             2.687915e-01      0.28928140
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal          822.271557        5.515406e+59            1.502754e+23
## Loyal               1.525555        1.011477e+00            7.892071e-01
##          TripPurposeOthers DeparturePeak-Hour TimeUseonBusReading
## Notloyal       2.74387e+23       7.579578e-40        2.210419e-28
## Loyal          1.01542e+00       7.965566e-01        2.589506e+00
##          TimeUseonBusListening TimeUseonBusNothing TimeUseonBusTalking
## Notloyal           2.13431e-20        1.070550e-15        3.668816e+21
## Loyal              1.18349e+00        9.147214e-01        8.024378e-01
##          TimeUseonBusOthers TravelTime
## Notloyal       2.115287e-19  2.2469964
## Loyal          1.053670e+00  0.8039371
exp(confint(mlm))
## Warning in sqrt(diag(vcov(object))): NaNs produced
## , , Notloyal
## 
##                                   2.5 %        97.5 %
## (Intercept)               2.418126e+137 1.013115e+142
## PSSW                       9.098318e-25  2.037754e-11
## PSSS                       1.507644e-12  1.942325e+00
## PSAB                       9.516108e+03  8.313533e+23
## PSEB                       9.573039e-08  1.205683e+17
## PSQ                        1.362625e-47  1.525047e-26
## IMA                        1.814598e-16  2.186529e+05
## PHB                        9.820717e-30  1.770565e-06
## PEV                        1.616680e+06  1.864944e+31
## ATM                        2.195676e-07  1.314626e+14
## PPI                        1.971839e-12  3.571515e+07
## SIM                        1.165858e-06  2.133341e+15
## SBE                        1.436164e+09  4.736787e+32
## EXB                        2.127452e-49  1.661881e-26
## GenderFemale               9.253570e-09  4.738588e-05
## MarriedStatusMarried       2.866083e+79  7.350640e+81
## OccupationFull.time.job   5.243423e-109 1.619626e-106
## OccupationPart.time.job             NaN           NaN
## OccupationRetirement                NaN           NaN
## OccupationNo.job           5.827626e+44  5.827626e+44
## OccupationHousewife        4.875274e-51  4.875274e-51
## OccupationOthers          1.775999e-139 1.794420e-139
## EducationUndergraduate     2.714319e-15  1.173339e-14
## EducationHigh.school       1.017958e+54  9.764847e+57
## EducationPostgraduate      1.520766e+13  1.521393e+13
## EducationOthers            1.047521e+50  1.057950e+50
## Income5-10millions         8.025650e+12  2.316670e+14
## Income10-15millions        1.078571e+68  1.166128e+69
## Income>15millions          2.947413e-82  5.499818e-82
## CITYHoChiMinh              1.643118e+12  5.725753e+15
## FRE2days/month-2days/week  3.673065e+01  3.682665e+01
## FRE2days/year-1day/month   1.918844e-20  5.543774e-19
## FRE<2 days/year            1.390208e-03  2.095032e-01
## TripPurposeStudying        2.562521e+02  2.638536e+03
## TripPurposeShopping        1.859935e+59  1.635525e+60
## TripPurposeEntertaining    1.056185e+22  2.138138e+24
## TripPurposeOthers          2.008682e+23  3.748143e+23
## DeparturePeak-Hour         2.917885e-40  1.968892e-39
## TimeUseonBusReading        2.199497e-28  2.221395e-28
## TimeUseonBusListening      2.134290e-20  2.134330e-20
## TimeUseonBusNothing        1.270413e-16  9.021297e-15
## TimeUseonBusTalking                 NaN           NaN
## TimeUseonBusOthers         2.115287e-19  2.115287e-19
## TravelTime                 3.983367e-02  1.267519e+02
## 
## , , Loyal
## 
##                                   2.5 %        97.5 %
## (Intercept)                9.541323e-11  9.592159e-08
## PSSW                       7.348838e-01  1.360837e+00
## PSSS                       8.728989e-01  1.487491e+00
## PSAB                       7.147581e-01  1.167602e+00
## PSEB                       6.755598e-01  1.191374e+00
## PSQ                        1.978446e+00  4.793109e+00
## IMA                        2.073030e+00  4.229368e+00
## PHB                        1.047063e+00  2.000672e+00
## PEV                        1.183311e+00  1.893366e+00
## ATM                        8.489118e-01  1.444733e+00
## PPI                        8.153163e-01  1.180075e+00
## SIM                        1.330748e+00  2.151672e+00
## SBE                        3.729680e-01  6.945363e-01
## EXB                        1.829011e+00  3.921623e+00
## GenderFemale               7.796819e-01  1.978677e+00
## MarriedStatusMarried       8.790517e-01  3.358884e+00
## OccupationFull.time.job    5.456848e-01  4.462006e+00
## OccupationPart.time.job    1.241749e+00  1.239840e+01
## OccupationRetirement       1.023303e+00  1.476476e+01
## OccupationNo.job          2.038165e+115 2.038165e+115
## OccupationHousewife        5.998784e-01  8.370255e+00
## OccupationOthers           2.803038e-01  8.718483e+00
## EducationUndergraduate     2.864399e-01  2.181014e+00
## EducationHigh.school       1.748037e-01  1.373356e+00
## EducationPostgraduate      1.491798e-01  1.589595e+00
## EducationOthers            1.131451e-01  1.534334e+00
## Income5-10millions         3.239764e-01  1.413209e+00
## Income10-15millions        6.208460e-01  4.436861e+00
## Income>15millions          2.722738e-01  4.931981e+00
## CITYHoChiMinh              5.902179e-01  1.732935e+00
## FRE2days/month-2days/week  4.736980e-01  1.558023e+00
## FRE2days/year-1day/month   1.165636e-01  6.198232e-01
## FRE<2 days/year            1.207774e-01  6.928758e-01
## TripPurposeStudying        6.738872e-01  3.453574e+00
## TripPurposeShopping        3.480368e-01  2.939592e+00
## TripPurposeEntertaining    3.238349e-01  1.923350e+00
## TripPurposeOthers          3.988257e-01  2.585285e+00
## DeparturePeak-Hour         4.968334e-01  1.277093e+00
## TimeUseonBusReading        8.293391e-01  8.085403e+00
## TimeUseonBusListening      6.045733e-01  2.316754e+00
## TimeUseonBusNothing        5.316437e-01  1.573827e+00
## TimeUseonBusTalking        2.377772e-01  2.708024e+00
## TimeUseonBusOthers         2.125982e-01  5.222159e+00
## TravelTime                 6.627251e-01  9.752382e-01
z <- summary(mlm)$coefficients/summary(mlm)$standard.errors
## Warning in sqrt(diag(vc)): NaNs produced
## Warning in sqrt(diag(vc)): NaNs produced
z
##          (Intercept)          PSSW       PSSS       PSAB       PSEB       PSQ
## Notloyal   118.47065 -5.0990469034 -1.8666362  2.7420220  0.8183221 -6.767799
## Loyal      -11.12304  0.0001808088  0.9602811 -0.7222996 -0.7500523  4.982578
##                 IMA       PHB      PEV       ATM        PPI       SIM       SBE
## Notloyal -0.9670566 -2.929478 2.931048 0.7037538 -0.4225942 0.8660938  3.486248
## Loyal     5.9676874  2.238384 3.363653 0.7524136 -0.2046128 4.2910219 -4.258077
##                EXB GenderFemale MarriedStatusMarried OccupationFull.time.job
## Notloyal -6.374175   -6.5298190           131.251018            -168.5161139
## Loyal     5.062968    0.9124477             1.583003               0.8300253
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal                     NaN                  NaN     5.921080e+13
## Loyal                   2.328817             1.993794     1.643565e+34
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal       -6.590262e+12    -1.213599e+05            -87.8518845
## Loyal           1.199944e+00     5.095104e-01             -0.4542025
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal            55.126673          288316.56960    45575.979271
## Loyal               -1.356657              -1.19211       -1.316316
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal          36.597862          259.900321     -1177.7569939   15.47840727
## Loyal             -1.039525            1.009846         0.1994641    0.04104007
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal              5413.6785334               -50.949997       -3.181612
## Loyal                   -0.5000605                -3.082039       -2.783273
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal           11.283401        248.03298331              39.3929219
## Loyal               1.013165          0.02096489              -0.5208555
##          TripPurposeOthers DeparturePeak-Hour TimeUseonBusReading
## Notloyal      339.14727038       -184.9463820       -25197.305047
## Loyal           0.03209318         -0.9444209            1.637847
##          TimeUseonBusListening TimeUseonBusNothing TimeUseonBusTalking
## Notloyal         -9.480523e+06         -31.6977807                 NaN
## Loyal             4.915739e-01          -0.3219463          -0.3546681
##          TimeUseonBusOthers TravelTime
## Notloyal      -2.293804e+14  0.3934834
## Loyal          6.401628e-02 -2.2143800
pvalue <- (1-pnorm(abs(z), 0, 1))*2
pvalue
##          (Intercept)         PSSW       PSSS        PSAB      PSEB          PSQ
## Notloyal           0 3.413680e-07 0.06195241 0.006106225 0.4131733 1.307554e-11
## Loyal              0 9.998557e-01 0.33691378 0.470110290 0.4532232 6.274279e-07
##                   IMA         PHB          PEV       ATM       PPI          SIM
## Notloyal 3.335157e-01 0.003395318 0.0033782010 0.4815861 0.6725913 3.864387e-01
## Loyal    2.406398e-09 0.025196052 0.0007691808 0.4518024 0.8378747 1.778528e-05
##                   SBE          EXB GenderFemale MarriedStatusMarried
## Notloyal 4.898462e-04 1.839502e-10 6.584933e-11            0.0000000
## Loyal    2.061927e-05 4.127785e-07 3.615331e-01            0.1134208
##          OccupationFull.time.job OccupationPart.time.job OccupationRetirement
## Notloyal               0.0000000                     NaN                  NaN
## Loyal                  0.4065245              0.01986878           0.04617459
##          OccupationNo.job OccupationHousewife OccupationOthers
## Notloyal                0           0.0000000        0.0000000
## Loyal                   0           0.2301611        0.6103945
##          EducationUndergraduate EducationHigh.school EducationPostgraduate
## Notloyal              0.0000000            0.0000000             0.0000000
## Loyal                 0.6496831            0.1748901             0.2332179
##          EducationOthers Income5-10millions Income10-15millions
## Notloyal        0.000000          0.0000000           0.0000000
## Loyal           0.188068          0.2985604           0.3125691
##          Income>15millions CITYHoChiMinh FRE2days/month-2days/week
## Notloyal         0.0000000      0.000000                 0.0000000
## Loyal            0.8418997      0.967264                 0.6170325
##          FRE2days/year-1day/month FRE<2 days/year TripPurposeStudying
## Notloyal              0.000000000     0.001464581           0.0000000
## Loyal                 0.002055878     0.005381356           0.3109814
##          TripPurposeShopping TripPurposeEntertaining TripPurposeOthers
## Notloyal           0.0000000               0.0000000         0.0000000
## Loyal              0.9832737               0.6024674         0.9743977
##          DeparturePeak-Hour TimeUseonBusReading TimeUseonBusListening
## Notloyal          0.0000000           0.0000000             0.0000000
## Loyal             0.3449546           0.1014537             0.6230206
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers TravelTime
## Notloyal           0.0000000                 NaN          0.0000000 0.69396248
## Loyal              0.7474934           0.7228383          0.9489573 0.02680265
# All variables - rempve: EC_Stop + WC_Stop + EC_Bus + WC_Bus + SAT and variable have cor > 0.7 - AGE, PPA and cor > 0.6 : PHB, PSQ, PSSW, PSAB
mlm3 <- multinom(LOY ~ PSSS + PSEB + IMA + PEV + ATM + PPI + SIM + SBE + EXB + Gender + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus + TravelTime, data = DataLOY)
## # weights:  123 (80 variable)
## initial  value 959.088528 
## iter  10 value 490.718472
## iter  20 value 377.902263
## iter  30 value 352.518574
## iter  40 value 338.392823
## iter  50 value 326.169984
## iter  60 value 321.139194
## iter  70 value 312.047173
## iter  80 value 305.693354
## iter  90 value 305.680024
## final  value 305.680009 
## converged
summary(mlm3)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## multinom(formula = LOY ~ PSSS + PSEB + IMA + PEV + ATM + PPI + 
##     SIM + SBE + EXB + Gender + MarriedStatus + Occupation + Education + 
##     Income + CITY + FRE + TripPurpose + Departure + TimeUseonBus + 
##     TravelTime, data = DataLOY)
## 
## Coefficients:
##          (Intercept)         PSSS        PSEB        IMA        PEV
## Notloyal   983.98562 -174.0270435 -342.068512 -30.670326 33.4599816
## Loyal      -18.17361    0.2684894    0.131721   1.286097  0.5003621
##                   ATM          PPI         SIM         SBE         EXB
## Notloyal -392.3821864 123.21998922 261.7459918 621.0000351 -955.097695
## Loyal       0.2699704  -0.00964319   0.4885282  -0.5561363    1.133247
##          GenderFemale MarriedStatusMarried OccupationFull.time.job
## Notloyal  311.5579788          2296.638912           -3548.9250264
## Loyal       0.2860572             0.561053               0.6001944
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal            -3405.131231         -4560.650666         1205.459
## Loyal                   1.467401             1.424432         3808.448
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal       -2961.2716099    -4759.9957260            890.1436161
## Loyal              0.9033854        0.5660432             -0.2724886
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal         2188.3431334           -187.621234     504.5678333
## Loyal              -0.6833763             -0.756985      -0.8010366
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal       1638.7933664        2723.5089257     -960.65630342  -216.3973773
## Loyal            -0.4029312           0.4068685        0.03074978     0.1936299
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal              411.70301226               -71.539793      754.709339
## Loyal                  -0.02303295                -1.138717       -1.060629
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal        -1066.258889         -738.181270            -317.0859753
## Loyal               0.439192            0.121196              -0.1262873
##          TripPurposeOthers DeparturePeak-Hour TimeUseonBusReading
## Notloyal     -148.09011855       -547.9195346         322.3412650
## Loyal           0.08358628         -0.2713393           0.9524749
##          TimeUseonBusListening TimeUseonBusNothing TimeUseonBusTalking
## Notloyal          -253.8454239        -297.3637081        -292.6306714
## Loyal                0.2709124          -0.1346034          -0.1231011
##          TimeUseonBusOthers  TravelTime
## Notloyal       1.333061e+02 122.2186518
## Loyal          7.072144e-03  -0.1851648
## 
## Std. Errors:
##          (Intercept)       PSSS       PSEB       IMA        PEV        ATM
## Notloyal    3.580116 11.0561585 19.7689560 17.015055 21.4940103 13.9388656
## Loyal       1.643273  0.1106245  0.1279661  0.169772  0.1050239  0.1278413
##                  PPI        SIM        SBE        EXB GenderFemale
## Notloyal 11.62924805 14.2362260 17.3939321 14.6095279    1.0114609
## Loyal     0.09162656  0.1170518  0.1467181  0.1865282    0.2285929
##          MarriedStatusMarried OccupationFull.time.job OccupationPart.time.job
## Notloyal           0.05675354               0.0208823                     NaN
## Loyal              0.32753779               0.5181017                0.569897
##          OccupationRetirement OccupationNo.job OccupationHousewife
## Notloyal                  NaN              NaN        2.769343e-11
## Loyal               0.6668581                0        6.677160e-01
##          OccupationOthers EducationUndergraduate EducationHigh.school
## Notloyal     2.570646e-11             0.01676111            3.5633546
## Loyal        8.502461e-01             0.50223499            0.5107926
##          EducationPostgraduate EducationOthers Income5-10millions
## Notloyal          1.558077e-11    6.095908e-12          0.8100033
## Loyal             5.836837e-01    6.464915e-01          0.3662780
##          Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal         0.001223154        0.06454067     1.0754318
## Loyal            0.477556853        0.67294860     0.2569506
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal                 2.5053014             5.827012e-12       1.0359255
## Loyal                    0.2924999             4.060779e-01       0.4224086
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal           1.8874514                 NaN              0.01680792
## Loyal              0.4067056            0.525103              0.45331538
##          TripPurposeOthers DeparturePeak-Hour TimeUseonBusReading
## Notloyal          1.671735          1.7906433         0.001187232
## Loyal             0.465053          0.2350279         0.555775266
##          TimeUseonBusListening TimeUseonBusNothing TimeUseonBusTalking
## Notloyal          1.032094e-10           1.8903881                 NaN
## Loyal             3.312029e-01           0.2651796            0.602188
##          TimeUseonBusOthers TravelTime
## Notloyal          1.6454858 7.88215994
## Loyal             0.8028598 0.09742529
## 
## Residual Deviance: 611.36 
## AIC: 771.36
# Model 1 - Remove 3 variables non significant : Gender, Departure, Travel time compare to mlm
mlm1 <- multinom(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + TimeUseonBus, data = DataLOY)
## # weights:  126 (82 variable)
## initial  value 959.088528 
## iter  10 value 467.143426
## iter  20 value 353.848576
## iter  30 value 330.540175
## iter  40 value 319.814747
## iter  50 value 305.931630
## iter  60 value 295.221188
## iter  70 value 292.833987
## iter  80 value 292.822387
## final  value 292.822369 
## converged
summary(mlm1)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## multinom(formula = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + 
##     PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus + 
##     Occupation + Education + Income + CITY + FRE + TripPurpose + 
##     TimeUseonBus, data = DataLOY)
## 
## Coefficients:
##          (Intercept)        PSSW        PSSS       PSAB       PSEB         PSQ
## Notloyal   323.20808 -85.1411169 -23.9370240 57.3849388 45.8611458 -123.541324
## Loyal      -19.40988  -0.0210442   0.1286796 -0.1020307 -0.1090966    1.139398
##                 IMA        PHB        PEV          ATM         PPI        SIM
## Notloyal -20.625356 -27.352013 25.5627070 -35.45570334 -0.31313855 -3.4318447
## Loyal      1.073455   0.327174  0.3875495   0.08007645 -0.04539722  0.5287091
##                 SBE         EXB MarriedStatusMarried OccupationFull.time.job
## Notloyal 81.7652946 -106.431404          254.5549231            -421.3617298
## Loyal    -0.6628959    1.005245            0.5941146               0.4890313
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal             -523.017501          -288.366158         166.4984
## Loyal                   1.427174             1.315342         449.6795
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal        -284.2746810     -476.7155758            -49.2267281
## Loyal              0.8579015        0.4794359             -0.2958962
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal          305.9735391            12.4481264     295.2808450
## Loyal              -0.6951871            -0.8623468      -0.8138199
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal        124.0549573         284.6574730      -191.9674979   74.58257986
## Loyal            -0.3686488           0.4438381        -0.1629409   -0.06422769
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal                 34.403038               -26.108525      -22.801133
## Loyal                    -0.101386                -1.189073       -1.121525
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal          18.9090198         325.9364410             113.8412896
## Loyal              0.4558836           0.1304685              -0.1489088
##          TripPurposeOthers TimeUseonBusReading TimeUseonBusListening
## Notloyal      126.85770158         -68.1132027           -26.1397836
## Loyal           0.05640188           0.8994296             0.1686483
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers
## Notloyal           0.3955566          61.1801334        -87.1159454
## Loyal             -0.1047600          -0.1459001         -0.2573989
## 
## Std. Errors:
##          (Intercept)      PSSW      PSSS      PSAB      PSEB       PSQ
## Notloyal    1.483124 3.4161391 2.0823546 8.5970241 8.1552481 8.1531224
## Loyal       1.713274 0.1555265 0.1351471 0.1244643 0.1440654 0.2236143
##                IMA       PHB       PEV       ATM        PPI       SIM       SBE
## Notloyal 7.1155808 9.1886425 8.8952036 8.8920846 9.92818396 9.3389618 9.6337013
## Loyal    0.1813382 0.1634773 0.1188479 0.1336689 0.09343782 0.1195174 0.1574458
##                EXB MarriedStatusMarried OccupationFull.time.job
## Notloyal 8.5965310            1.4805925               1.4804611
## Loyal    0.1932893            0.3332808               0.5344822
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal            5.440314e-12                  NaN              NaN
## Loyal               5.846004e-01            0.6755306                0
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal                 NaN     1.050980e-12           4.661934e-05
## Loyal              0.6639656     8.975743e-01           5.166424e-01
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal            1.4830772          2.615932e-12             NaN
## Loyal               0.5238524          5.998233e-01       0.6560544
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal           1.480451        9.968968e-06      0.0001407498     1.4830495
## Loyal              0.378699        4.982579e-01      0.7332674044     0.2689951
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal              0.0000611189                1.4804521     0.002413144
## Loyal                 0.2972394431                0.4170424     0.433790016
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal         0.001602951        6.797734e-07               1.4814499
## Loyal            0.415162970        5.329705e-01               0.4459175
##          TripPurposeOthers TimeUseonBusReading TimeUseonBusListening
## Notloyal      2.559843e-12        8.120761e-07          3.216733e-12
## Loyal         4.759997e-01        5.726479e-01          3.402315e-01
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers
## Notloyal         0.002661274        3.398440e-14       1.466051e-13
## Loyal            0.274437661        6.134246e-01       8.040931e-01
## 
## Residual Deviance: 585.6447 
## AIC: 749.6447
mlm.chon <- multinom(LOY ~  PSQ + IMA + PHB + PEV + SIM + SBE + EXB + MarriedStatus +  FRE, data = DataLOY)
## # weights:  39 (24 variable)
## initial  value 959.088528 
## iter  10 value 447.521930
## iter  20 value 365.754637
## iter  30 value 337.634601
## iter  40 value 335.910970
## final  value 335.910128 
## converged
summary(mlm.chon)
## Call:
## multinom(formula = LOY ~ PSQ + IMA + PHB + PEV + SIM + SBE + 
##     EXB + MarriedStatus + FRE, data = DataLOY)
## 
## Coefficients:
##          (Intercept)       PSQ       IMA        PHB       PEV        SIM
## Notloyal    4.267974 -1.498441 0.1001002 -0.5211413 0.7548364 0.09905232
## Loyal     -19.555787  1.157054 0.9410593  0.3238565 0.3294089 0.48888198
##                 SBE       EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal  0.5021210 -1.605856            0.4721092                 1.0918113
## Loyal    -0.5720311  1.034042            0.8651999                -0.1551092
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                0.2989249       1.4920046
## Loyal                  -1.0257128      -0.8659766
## 
## Std. Errors:
##          (Intercept)       PSQ       IMA       PHB       PEV       SIM
## Notloyal    2.215573 0.4219775 0.4896395 0.4782836 0.4003960 0.3675357
## Loyal       1.439342 0.1836982 0.1615532 0.1504298 0.1054378 0.1076867
##                SBE       EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal 0.4193698 0.5636659            0.9377554                 1.3035991
## Loyal    0.1341555 0.1820965            0.2243892                 0.2597373
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                1.2188064       0.9797358
## Loyal                   0.3464703       0.3541791
## 
## Residual Deviance: 671.8203 
## AIC: 719.8203
# Model 2 - bma2 - 9 variables (including LOY), remove cor > 0.7: PPA
mlm2 <- multinom(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + SIM + SBE + EXB + CITY, data = DataLOY)
## # weights:  45 (28 variable)
## initial  value 959.088528 
## iter  10 value 452.411172
## iter  20 value 374.998611
## iter  30 value 355.405641
## iter  40 value 346.088394
## final  value 346.071312 
## converged
summary(mlm2)
## Call:
## multinom(formula = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + 
##     PHB + PEV + ATM + SIM + SBE + EXB + CITY, data = DataLOY)
## 
## Coefficients:
##          (Intercept)        PSSW        PSSS        PSAB       PSEB       PSQ
## Notloyal    4.732102 -0.12041084 -0.02960159  0.12566353  0.6064778 -2.009214
## Loyal     -18.932702 -0.01977747  0.17224302 -0.01347676 -0.1673042  1.096446
##                   IMA        PHB       PEV        ATM       SIM        SBE
## Notloyal -0.008939119 -0.6986138 0.6965186 0.19464308 0.1287331  0.4470136
## Loyal     0.936785582  0.3686742 0.2863793 0.04451399 0.4317126 -0.5923468
##                EXB CITYHoChiMinh
## Notloyal -1.510156   -0.22936715
## Loyal     1.101410   -0.09227602
## 
## Std. Errors:
##          (Intercept)      PSSW      PSSS      PSAB      PSEB       PSQ
## Notloyal    2.635756 0.4994537 0.5411987 0.5048315 0.4673654 0.6300213
## Loyal       1.486636 0.1451729 0.1232509 0.1147958 0.1361819 0.2028641
##                IMA       PHB       PEV       ATM       SIM       SBE       EXB
## Notloyal 0.5500393 0.5278843 0.3870319 0.4674947 0.3741817 0.4378694 0.5692588
## Loyal    0.1638865 0.1537574 0.1047847 0.1209207 0.1054288 0.1397219 0.1805568
##          CITYHoChiMinh
## Notloyal     1.0995331
## Loyal        0.2364972
## 
## Residual Deviance: 692.1426 
## AIC: 748.1426
# CHON: Model mlm1 - all varibles , removing : EC_Stop + WC_Stop + EC_Bus + WC_Bus + SAT and variable have cor > 0.7 - AGE, PPA and nonsignificant variables : Gender, Departure, Travel time
summary(mlm1)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## multinom(formula = LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + 
##     PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus + 
##     Occupation + Education + Income + CITY + FRE + TripPurpose + 
##     TimeUseonBus, data = DataLOY)
## 
## Coefficients:
##          (Intercept)        PSSW        PSSS       PSAB       PSEB         PSQ
## Notloyal   323.20808 -85.1411169 -23.9370240 57.3849388 45.8611458 -123.541324
## Loyal      -19.40988  -0.0210442   0.1286796 -0.1020307 -0.1090966    1.139398
##                 IMA        PHB        PEV          ATM         PPI        SIM
## Notloyal -20.625356 -27.352013 25.5627070 -35.45570334 -0.31313855 -3.4318447
## Loyal      1.073455   0.327174  0.3875495   0.08007645 -0.04539722  0.5287091
##                 SBE         EXB MarriedStatusMarried OccupationFull.time.job
## Notloyal 81.7652946 -106.431404          254.5549231            -421.3617298
## Loyal    -0.6628959    1.005245            0.5941146               0.4890313
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal             -523.017501          -288.366158         166.4984
## Loyal                   1.427174             1.315342         449.6795
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal        -284.2746810     -476.7155758            -49.2267281
## Loyal              0.8579015        0.4794359             -0.2958962
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal          305.9735391            12.4481264     295.2808450
## Loyal              -0.6951871            -0.8623468      -0.8138199
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal        124.0549573         284.6574730      -191.9674979   74.58257986
## Loyal            -0.3686488           0.4438381        -0.1629409   -0.06422769
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal                 34.403038               -26.108525      -22.801133
## Loyal                    -0.101386                -1.189073       -1.121525
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal          18.9090198         325.9364410             113.8412896
## Loyal              0.4558836           0.1304685              -0.1489088
##          TripPurposeOthers TimeUseonBusReading TimeUseonBusListening
## Notloyal      126.85770158         -68.1132027           -26.1397836
## Loyal           0.05640188           0.8994296             0.1686483
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers
## Notloyal           0.3955566          61.1801334        -87.1159454
## Loyal             -0.1047600          -0.1459001         -0.2573989
## 
## Std. Errors:
##          (Intercept)      PSSW      PSSS      PSAB      PSEB       PSQ
## Notloyal    1.483124 3.4161391 2.0823546 8.5970241 8.1552481 8.1531224
## Loyal       1.713274 0.1555265 0.1351471 0.1244643 0.1440654 0.2236143
##                IMA       PHB       PEV       ATM        PPI       SIM       SBE
## Notloyal 7.1155808 9.1886425 8.8952036 8.8920846 9.92818396 9.3389618 9.6337013
## Loyal    0.1813382 0.1634773 0.1188479 0.1336689 0.09343782 0.1195174 0.1574458
##                EXB MarriedStatusMarried OccupationFull.time.job
## Notloyal 8.5965310            1.4805925               1.4804611
## Loyal    0.1932893            0.3332808               0.5344822
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal            5.440314e-12                  NaN              NaN
## Loyal               5.846004e-01            0.6755306                0
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal                 NaN     1.050980e-12           4.661934e-05
## Loyal              0.6639656     8.975743e-01           5.166424e-01
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal            1.4830772          2.615932e-12             NaN
## Loyal               0.5238524          5.998233e-01       0.6560544
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal           1.480451        9.968968e-06      0.0001407498     1.4830495
## Loyal              0.378699        4.982579e-01      0.7332674044     0.2689951
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal              0.0000611189                1.4804521     0.002413144
## Loyal                 0.2972394431                0.4170424     0.433790016
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal         0.001602951        6.797734e-07               1.4814499
## Loyal            0.415162970        5.329705e-01               0.4459175
##          TripPurposeOthers TimeUseonBusReading TimeUseonBusListening
## Notloyal      2.559843e-12        8.120761e-07          3.216733e-12
## Loyal         4.759997e-01        5.726479e-01          3.402315e-01
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers
## Notloyal         0.002661274        3.398440e-14       1.466051e-13
## Loyal            0.274437661        6.134246e-01       8.040931e-01
## 
## Residual Deviance: 585.6447 
## AIC: 749.6447
 ## Calculate OR and CI
exp(coef(mlm1))
##            (Intercept)         PSSW         PSSS         PSAB         PSEB
## Notloyal 2.330691e+140 1.056046e-37 4.020523e-11 8.355304e+24 8.264994e+19
## Loyal     3.718751e-09 9.791757e-01 1.137326e+00 9.030018e-01 8.966438e-01
##                   PSQ          IMA          PHB          PEV          ATM
## Notloyal 2.221696e-54 1.102863e-09 1.321818e-12 1.263987e+11 3.997456e-16
## Loyal    3.124887e+00 2.925471e+00 1.387043e+00 1.473366e+00 1.083370e+00
##                PPI        SIM          SBE          EXB MarriedStatusMarried
## Notloyal 0.7311486 0.03232725 3.237548e+35 5.990027e-47        3.562857e+110
## Loyal    0.9556178 1.69674059 5.153568e-01 2.732576e+00         1.811426e+00
##          OccupationFull.time.job OccupationPart.time.job OccupationRetirement
## Notloyal           1.011407e-183           7.184317e-228        5.809904e-126
## Loyal               1.630736e+00            4.166908e+00         3.726025e+00
##          OccupationNo.job OccupationHousewife OccupationOthers
## Notloyal     2.038590e+72       3.475960e-124    9.226903e-208
## Loyal       1.964886e+195        2.358207e+00     1.615163e+00
##          EducationUndergraduate EducationHigh.school EducationPostgraduate
## Notloyal           4.179301e-22        7.631671e+132          2.547725e+05
## Loyal              7.438646e-01         4.989811e-01          4.221702e-01
##          EducationOthers Income5-10millions Income10-15millions
## Notloyal   1.733172e+128       7.522867e+53       4.218613e+123
## Loyal       4.431620e-01       6.916683e-01        1.558678e+00
##          Income>15millions CITYHoChiMinh FRE2days/month-2days/week
## Notloyal      4.261622e-84  2.459251e+32              8.730706e+14
## Loyal         8.496414e-01  9.377915e-01              9.035842e-01
##          FRE2days/year-1day/month FRE<2 days/year TripPurposeStudying
## Notloyal             4.583654e-12    1.251969e-10        1.629607e+08
## Loyal                3.045034e-01    3.257826e-01        1.577567e+00
##          TripPurposeShopping TripPurposeEntertaining TripPurposeOthers
## Notloyal       3.567778e+141            2.758315e+49      1.240509e+55
## Loyal           1.139362e+00            8.616477e-01      1.058023e+00
##          TimeUseonBusReading TimeUseonBusListening TimeUseonBusNothing
## Notloyal        2.623082e-30          4.442590e-12           1.4852106
## Loyal           2.458201e+00          1.183704e+00           0.9005406
##          TimeUseonBusTalking TimeUseonBusOthers
## Notloyal        3.717015e+26       1.465634e-38
## Loyal           8.642440e-01       7.730598e-01
exp(confint(mlm1))
## Warning in sqrt(diag(vcov(object))): NaNs produced
## , , Notloyal
## 
##                                   2.5 %        97.5 %
## (Intercept)               1.273642e+139 4.265030e+141
## PSSW                       1.305750e-40  8.540940e-35
## PSSS                       6.788583e-13  2.381146e-09
## PSAB                       4.019408e+17  1.736850e+32
## PSEB                       9.451108e+12  7.227737e+26
## PSQ                        2.551140e-61  1.934795e-47
## IMA                        9.676724e-16  1.256941e-03
## PHB                        1.994274e-20  8.761091e-05
## PEV                        3.389468e+03  4.713610e+18
## ATM                        1.078518e-23  1.481630e-08
## PPI                        2.588929e-09  2.064863e+08
## SIM                        3.632705e-10  2.876786e+06
## SBE                        2.041713e+27  5.133785e+43
## EXB                        2.884352e-54  1.243968e-39
## MarriedStatusMarried      1.956662e+109 6.487555e+111
## OccupationFull.time.job   5.555909e-185 1.841181e-182
## OccupationPart.time.job   7.184317e-228 7.184317e-228
## OccupationRetirement                NaN           NaN
## OccupationNo.job                    NaN           NaN
## OccupationHousewife                 NaN           NaN
## OccupationOthers          9.226903e-208 9.226903e-208
## EducationUndergraduate     4.178919e-22  4.179683e-22
## EducationHigh.school      4.170826e+131 1.396424e+134
## EducationPostgraduate      2.547725e+05  2.547725e+05
## EducationOthers                     NaN           NaN
## Income5-10millions         4.132579e+52  1.369448e+55
## Income10-15millions       4.218531e+123 4.218696e+123
## Income>15millions          4.260447e-84  4.262798e-84
## CITYHoChiMinh              1.344092e+31  4.499631e+33
## FRE2days/month-2days/week  8.729660e+14  8.731752e+14
## FRE2days/year-1day/month   2.517960e-13  8.344012e-11
## FRE<2 days/year            1.246062e-10  1.257904e-10
## TripPurposeStudying        1.624496e+08  1.634735e+08
## TripPurposeShopping       3.567773e+141 3.567782e+141
## TripPurposeEntertaining    1.512277e+48  5.031024e+50
## TripPurposeOthers          1.240509e+55  1.240509e+55
## TimeUseonBusReading        2.623078e-30  2.623087e-30
## TimeUseonBusListening      4.442590e-12  4.442590e-12
## TimeUseonBusNothing        1.477484e+00  1.492978e+00
## TimeUseonBusTalking        3.717015e+26  3.717015e+26
## TimeUseonBusOthers         1.465634e-38  1.465634e-38
## 
## , , Loyal
## 
##                                   2.5 %        97.5 %
## (Intercept)                1.294362e-10  1.068411e-07
## PSSW                       7.218987e-01  1.328143e+00
## PSSS                       8.726647e-01  1.482253e+00
## PSAB                       7.075292e-01  1.152479e+00
## PSEB                       6.760693e-01  1.189183e+00
## PSQ                        2.016013e+00  4.843676e+00
## IMA                        2.050409e+00  4.173987e+00
## PHB                        1.006787e+00  1.910918e+00
## PEV                        1.167205e+00  1.859834e+00
## ATM                        8.336765e-01  1.407849e+00
## PPI                        7.957008e-01  1.147674e+00
## SIM                        1.342400e+00  2.144612e+00
## SBE                        3.785209e-01  7.016590e-01
## EXB                        1.870872e+00  3.991172e+00
## MarriedStatusMarried       9.426090e-01  3.481046e+00
## OccupationFull.time.job    5.720468e-01  4.648744e+00
## OccupationPart.time.job    1.324955e+00  1.310469e+01
## OccupationRetirement       9.913637e-01  1.400420e+01
## OccupationNo.job          1.964886e+195 1.964886e+195
## OccupationHousewife        6.418201e-01  8.664639e+00
## OccupationOthers           2.780992e-01  9.380652e+00
## EducationUndergraduate     2.702260e-01  2.047673e+00
## EducationHigh.school       1.787229e-01  1.393118e+00
## EducationPostgraduate      1.302918e-01  1.367912e+00
## EducationOthers            1.224977e-01  1.603234e+00
## Income5-10millions         3.292674e-01  1.452938e+00
## Income10-15millions        5.870006e-01  4.138799e+00
## Income>15millions          2.018726e-01  3.575971e+00
## CITYHoChiMinh              5.535250e-01  1.588822e+00
## FRE2days/month-2days/week  5.046124e-01  1.618003e+00
## FRE2days/year-1day/month   1.344637e-01  6.895715e-01
## FRE<2 days/year            1.392147e-01  7.623785e-01
## TripPurposeStudying        6.991983e-01  3.559386e+00
## TripPurposeShopping        4.008634e-01  3.238374e+00
## TripPurposeEntertaining    3.595540e-01  2.064883e+00
## TripPurposeOthers          4.162204e-01  2.689470e+00
## TimeUseonBusReading        8.001631e-01  7.551898e+00
## TimeUseonBusListening      6.076276e-01  2.305943e+00
## TimeUseonBusNothing        5.258980e-01  1.542073e+00
## TimeUseonBusTalking        2.597098e-01  2.875970e+00
## TimeUseonBusOthers         1.598703e-01  3.738165e+00
est1 <- estimate.mlogit(LOY ~ PSSW + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB + MarriedStatus + Occupation + Education + Income + CITY + FRE + TripPurpose + TimeUseonBus, data = DataLOY)
summary(est1)
## 
## successive function values within relative tolerance limit (reltol) 
## 
## Log-Likelihood:           -355.3 
## Null Log-Likelihood:  -959.1 
## Likelihood ratio index:   0.6296 
## AIC:                  756.5488 
## BIC:                  866.3033 
## Sample size:          873 
## Iterations:               14 
## Suggested |t-value| >     2.602294 
## Convergence statistics:   2.748882e-06 
## 
## Estimated using BHHH in 0.7609339 s.
## 
## Coefficients :
##                Estimate Std. Error  t-value  Pr(>|t|)
## asc.Normal    18.636551    1.58334 11.77038 0.000e+00
## asc.Notloyal  15.286711    1.60564  9.52065 0.000e+00
## CITY           0.138567    0.25831  0.53644 5.917e-01
## FRE            0.407963    0.13732  2.97086 2.970e-03
## TripPurpose   -0.001332    0.09614 -0.01385 9.889e-01
## TimeUseonBus   0.049141    0.07977  0.61606 5.379e-01
## PSSW           0.034578    0.15418  0.22427 8.225e-01
## PSSS          -0.202934    0.13259 -1.53052 1.259e-01
## PSAB           0.115619    0.11538  1.00205 3.163e-01
## PSEB           0.115551    0.13627  0.84795 3.965e-01
## PSQ           -1.129345    0.22845 -4.94350 7.673e-07
## IMA           -0.991808    0.15201 -6.52449 6.823e-11
## PHB           -0.378955    0.16131 -2.34919 1.881e-02
## PEV           -0.309982    0.11101 -2.79249 5.230e-03
## ATM           -0.082888    0.12819 -0.64660 5.179e-01
## PPI            0.041199    0.08628  0.47750 6.330e-01
## SIM           -0.477622    0.10857 -4.39901 1.087e-05
## SBE            0.618264    0.14746  4.19275 2.756e-05
## EXB           -1.022911    0.18731 -5.46097 4.735e-08
## MarriedStatus -0.579582    0.28668 -2.02167 4.321e-02
## Occupation    -0.161793    0.09066 -1.78462 7.432e-02
## Education      0.214111    0.11939  1.79333 7.292e-02
## Income        -0.033166    0.15368 -0.21581 8.291e-01
## 
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept      1     2             3              4      5
## 1      Loyal:                                                              
## 2     Normal:   asc.Normal + CITY + FRE + TripPurpose + TimeUseonBus + PSSW
## 3   Notloyal: asc.Notloyal + CITY + FRE + TripPurpose + TimeUseonBus + PSSW
##        6      7      8     9    10    11    12    13    14    15    16    17
## 1                                                                           
## 2 + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB
## 3 + PSSS + PSAB + PSEB + PSQ + IMA + PHB + PEV + ATM + PPI + SIM + SBE + EXB
##                18           19          20       21
## 1                                                  
## 2 + MarriedStatus + Occupation + Education + Income
## 3 + MarriedStatus + Occupation + Education + Income
# so voi mlm1 (est1) bo CITY, TripPurpose, TimeUseonBus, PSSW, PSSS, PSAB, PSEB, ATM, PPI, Occupation, Education, Income  
est.chon <- estimate.mlogit(LOY ~  PSQ + IMA + PHB + PEV + SIM + SBE + EXB + MarriedStatus +  FRE, data = DataLOY)
summary(est.chon)
## 
## successive function values within relative tolerance limit (reltol) 
## 
## Log-Likelihood:           -361.1 
## Null Log-Likelihood:  -959.1 
## Likelihood ratio index:   0.6235 
## AIC:                  744.1447 
## BIC:                  796.636 
## Sample size:          873 
## Iterations:               10 
## Suggested |t-value| >     2.602294 
## Convergence statistics:   4.87819e-07 
## 
## Estimated using BHHH in 0.339057 s.
## 
## Coefficients :
##               Estimate Std. Error t-value  Pr(>|t|)
## asc.Normal     20.0251    1.35944  14.730 0.000e+00
## asc.Notloyal   16.6753    1.38317  12.056 0.000e+00
## FRE             0.3414    0.11614   2.940 3.287e-03
## PSQ            -1.1710    0.18521  -6.322 2.574e-10
## IMA            -0.9309    0.14292  -6.513 7.354e-11
## PHB            -0.3178    0.15084  -2.107 3.512e-02
## PEV            -0.3283    0.10252  -3.203 1.361e-03
## SIM            -0.4785    0.09967  -4.800 1.583e-06
## SBE             0.5710    0.12713   4.492 7.072e-06
## EXB            -1.0561    0.18229  -5.794 6.887e-09
## MarriedStatus  -0.8192    0.22476  -3.645 2.677e-04
## 
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept     1     2     3     4     5     6     7     8
## 1      Loyal:                                                             
## 2     Normal:   asc.Normal + FRE + PSQ + IMA + PHB + PEV + SIM + SBE + EXB
## 3   Notloyal: asc.Notloyal + FRE + PSQ + IMA + PHB + PEV + SIM + SBE + EXB
##                 9
## 1                
## 2 + MarriedStatus
## 3 + MarriedStatus
# THU
est.thu <- estimate.mlogit(LOY ~  PSQ + IMA + PHB + PEV + SIM + SBE + EXB + FRE + AGE, data = DataLOY)
summary(est.thu)
## 
## successive function values within relative tolerance limit (reltol) 
## 
## Log-Likelihood:           -358.4 
## Null Log-Likelihood:  -959.1 
## Likelihood ratio index:   0.6263 
## AIC:                  738.8591 
## BIC:                  791.3504 
## Sample size:          873 
## Iterations:               10 
## Suggested |t-value| >     2.602294 
## Convergence statistics:   4.304734e-07 
## 
## Estimated using BHHH in 0.360038 s.
## 
## Coefficients :
##              Estimate Std. Error t-value  Pr(>|t|)
## asc.Normal    19.1986    1.32747  14.463 0.000e+00
## asc.Notloyal  15.8488    1.35061  11.735 0.000e+00
## AGE           -0.3685    0.08599  -4.285 1.825e-05
## FRE            0.3567    0.11663   3.058 2.226e-03
## PSQ           -1.1343    0.18211  -6.228 4.716e-10
## IMA           -0.9388    0.14304  -6.563 5.260e-11
## PHB           -0.3262    0.15181  -2.149 3.164e-02
## PEV           -0.3578    0.10671  -3.353 7.986e-04
## SIM           -0.4545    0.10047  -4.524 6.075e-06
## SBE            0.5714    0.12973   4.405 1.059e-05
## EXB           -0.9889    0.18751  -5.274 1.336e-07
## 
## Response variable: LOY
## Base choice name: Loyal
## Base choice index: 1
## Frequency of alternatives:
##    Loyal   Normal Notloyal 
##      519      342       12 
## 
## Equations:
## ----------
##   alternative    intercept     1     2     3     4     5     6     7     8
## 1      Loyal:                                                             
## 2     Normal:   asc.Normal + AGE + FRE + PSQ + IMA + PHB + PEV + SIM + SBE
## 3   Notloyal: asc.Notloyal + AGE + FRE + PSQ + IMA + PHB + PEV + SIM + SBE
##       9
## 1      
## 2 + EXB
## 3 + EXB
mlm.thu <- multinom(LOY ~  PSQ + IMA + PHB + PEV + SIM + SBE + EXB + FRE + AGE, data = DataLOY)
## # weights:  48 (30 variable)
## initial  value 959.088528 
## iter  10 value 477.740893
## iter  20 value 362.737560
## iter  30 value 335.877884
## iter  40 value 330.609579
## iter  50 value 330.542482
## iter  60 value 330.536117
## final  value 330.536051 
## converged
summary(mlm.thu)
## Call:
## multinom(formula = LOY ~ PSQ + IMA + PHB + PEV + SIM + SBE + 
##     EXB + FRE + AGE, data = DataLOY)
## 
## Coefficients:
##          (Intercept)       PSQ        IMA        PHB       PEV       SIM
## Notloyal    4.114588 -1.575694 0.09199217 -0.5684943 0.7036342 0.1162092
## Loyal     -19.188824  1.138328 0.92964636  0.3295300 0.3579844 0.4664955
##                 SBE        EXB FRE2days/month-2days/week
## Notloyal  0.6517687 -1.6080943                 1.1895773
## Loyal    -0.5748037  0.9759594                -0.1522929
##          FRE2days/year-1day/month FRE<2 days/year  AGE26-35   AGE36-45
## Notloyal                0.2565518       1.7674033 1.2166689 -0.7154157
## Loyal                  -1.0947415      -0.9531502 0.2433404  1.0958006
##           AGE46-55    AGE>55
## Notloyal 1.5196208 -6.773994
## Loyal    0.7241241  1.726935
## 
## Std. Errors:
##          (Intercept)       PSQ       IMA       PHB       PEV       SIM
## Notloyal    2.285067 0.4252624 0.5129671 0.5054483 0.3798203 0.3545387
## Loyal       1.437813 0.1870156 0.1663416 0.1519978 0.1069438 0.1084361
##                SBE       EXB FRE2days/month-2days/week FRE2days/year-1day/month
## Notloyal 0.4327721 0.5579435                 1.3362777                1.2761417
## Loyal    0.1350506 0.1849188                 0.2648883                0.3557135
##          FRE<2 days/year  AGE26-35 AGE36-45  AGE46-55       AGE>55
## Notloyal       1.0272813 1.0799892 1.973501 1.8389826 0.0002228833
## Loyal          0.3628632 0.2596796 0.357309 0.3920418 0.4605939293
## 
## Residual Deviance: 661.0721 
## AIC: 721.0721
z.thu <- summary(mlm.thu)$coefficients/summary(mlm.thu)$standard.errors
z.thu
##          (Intercept)       PSQ       IMA       PHB      PEV       SIM       SBE
## Notloyal    1.800642 -3.705228 0.1793335 -1.124733 1.852545 0.3277757  1.506032
## Loyal     -13.345838  6.086806 5.5887780  2.167992 3.347408 4.3020302 -4.256209
##                EXB FRE2days/month-2days/week FRE2days/year-1day/month
## Notloyal -2.882181                 0.8902171                0.2010371
## Loyal     5.277772                -0.5749325               -3.0775936
##          FRE<2 days/year  AGE26-35   AGE36-45  AGE46-55        AGE>55
## Notloyal        1.720467 1.1265566 -0.3625109 0.8263377 -30392.565961
## Loyal          -2.626748 0.9370792  3.0668151 1.8470582      3.749366
pvalue.thu <- (1-pnorm(abs(z.thu), 0, 1))*2
pvalue.thu
##          (Intercept)          PSQ          IMA        PHB          PEV
## Notloyal  0.07175933 2.112010e-04 8.576759e-01 0.26070224 0.0639476213
## Loyal     0.00000000 1.151855e-09 2.286731e-08 0.03015932 0.0008157111
##                   SIM          SBE          EXB FRE2days/month-2days/week
## Notloyal 7.430813e-01 1.320588e-01 3.949326e-03                 0.3733493
## Loyal    1.692402e-05 2.079224e-05 1.307641e-07                 0.5653369
##          FRE2days/year-1day/month FRE<2 days/year  AGE26-35    AGE36-45
## Notloyal              0.840669599     0.085347650 0.2599300 0.716970280
## Loyal                 0.002086793     0.008620508 0.3487178 0.002163527
##            AGE46-55       AGE>55
## Notloyal 0.40861253 0.0000000000
## Loyal    0.06473871 0.0001772825
   ## Calculate p-value
z1 <- summary(mlm1)$coefficients/summary(mlm1)$standard.errors
## Warning in sqrt(diag(vc)): NaNs produced

## Warning in sqrt(diag(vc)): NaNs produced
z1
##          (Intercept)        PSSW        PSSS       PSAB       PSEB        PSQ
## Notloyal   217.92387 -24.9231995 -11.4951720  6.6749771  5.6235132 -15.152639
## Loyal      -11.32912  -0.1353095   0.9521445 -0.8197588 -0.7572714   5.095372
##                IMA       PHB      PEV        ATM         PPI       SIM
## Notloyal -2.898619 -2.976720 2.873763 -3.9873331 -0.03154036 -0.367476
## Loyal     5.919631  2.001343 3.260886  0.5990655 -0.48585487  4.423701
##                SBE        EXB MarriedStatusMarried OccupationFull.time.job
## Notloyal  8.487423 -12.380739           171.927739            -284.6152064
## Loyal    -4.210312   5.200725             1.782625               0.9149627
##          OccupationPart.time.job OccupationRetirement OccupationNo.job
## Notloyal           -9.613738e+13                  NaN              NaN
## Loyal               2.441281e+00             1.947124              Inf
##          OccupationHousewife OccupationOthers EducationUndergraduate
## Notloyal                 NaN    -4.535915e+14          -1.055929e+06
## Loyal               1.292087     5.341461e-01          -5.727293e-01
##          EducationHigh.school EducationPostgraduate EducationOthers
## Notloyal           206.309923          4.758582e+12             NaN
## Loyal               -1.327067         -1.437668e+00       -1.240476
##          Income5-10millions Income10-15millions Income>15millions CITYHoChiMinh
## Notloyal         83.7953773        2.855436e+07     -1.363892e+06     50.290015
## Loyal            -0.9734612        8.907799e-01     -2.222121e-01     -0.238769
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal             562887.079483               -17.635508     -9448.72568
## Loyal                    -0.341092                -2.851204        -2.58541
##          TripPurposeStudying TripPurposeShopping TripPurposeEntertaining
## Notloyal        11796.379061        4.794780e+08              76.8445062
## Loyal               1.098083        2.447949e-01              -0.3339379
##          TripPurposeOthers TimeUseonBusReading TimeUseonBusListening
## Notloyal      4.955682e+13       -8.387539e+07         -8.126190e+12
## Loyal         1.184914e-01        1.570650e+00          4.956869e-01
##          TimeUseonBusNothing TimeUseonBusTalking TimeUseonBusOthers
## Notloyal         148.6342737        1.800242e+15      -5.942218e+14
## Loyal             -0.3817261       -2.378453e-01      -3.201107e-01
pvalue1 <- (1-pnorm(abs(z1), 0, 1))*2
pvalue1
##          (Intercept)      PSSW      PSSS         PSAB         PSEB          PSQ
## Notloyal           0 0.0000000 0.0000000 2.472711e-11 1.871124e-08 0.000000e+00
## Loyal              0 0.8923672 0.3410237 4.123536e-01 4.488873e-01 3.480578e-07
##                   IMA         PHB         PEV          ATM       PPI
## Notloyal 3.748103e-03 0.002913502 0.004056132 6.682017e-05 0.9748386
## Loyal    3.226638e-09 0.045355492 0.001110645 5.491292e-01 0.6270701
##                   SIM          SBE          EXB MarriedStatusMarried
## Notloyal 7.132640e-01 0.000000e+00 0.000000e+00            0.0000000
## Loyal    9.702432e-06 2.550182e-05 1.985122e-07            0.0746474
##          OccupationFull.time.job OccupationPart.time.job OccupationRetirement
## Notloyal               0.0000000              0.00000000                  NaN
## Loyal                  0.3602112              0.01463525           0.05151987
##          OccupationNo.job OccupationHousewife OccupationOthers
## Notloyal              NaN                 NaN        0.0000000
## Loyal                   0           0.1963269        0.5932404
##          EducationUndergraduate EducationHigh.school EducationPostgraduate
## Notloyal               0.000000            0.0000000             0.0000000
## Loyal                  0.566828            0.1844865             0.1505283
##          EducationOthers Income5-10millions Income10-15millions
## Notloyal             NaN          0.0000000           0.0000000
## Loyal          0.2147993          0.3303242           0.3730473
##          Income>15millions CITYHoChiMinh FRE2days/month-2days/week
## Notloyal         0.0000000     0.0000000                 0.0000000
## Loyal            0.8241488     0.8112847                 0.7330343
##          FRE2days/year-1day/month FRE<2 days/year TripPurposeStudying
## Notloyal              0.000000000     0.000000000            0.000000
## Loyal                 0.004355403     0.009726336            0.272168
##          TripPurposeShopping TripPurposeEntertaining TripPurposeOthers
## Notloyal           0.0000000               0.0000000         0.0000000
## Loyal              0.8066152               0.7384264         0.9056783
##          TimeUseonBusReading TimeUseonBusListening TimeUseonBusNothing
## Notloyal           0.0000000             0.0000000           0.0000000
## Loyal              0.1162639             0.6201153           0.7026645
##          TimeUseonBusTalking TimeUseonBusOthers
## Notloyal           0.0000000          0.0000000
## Loyal              0.8120011          0.7488844
z.chon <- summary(mlm.chon)$coefficients/summary(mlm.chon)$standard.errors
z.chon
##          (Intercept)       PSQ       IMA       PHB      PEV      SIM       SBE
## Notloyal    1.926352 -3.550998 0.2044365 -1.089607 1.885224 0.269504  1.197323
## Loyal     -13.586621  6.298665 5.8250745  2.152874 3.124202 4.539857 -4.263940
##                EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal -2.848951             0.503446                 0.8375361
## Loyal     5.678538             3.855801                -0.5971770
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                0.2452604        1.522864
## Loyal                  -2.9604636       -2.445024
pvalue.chon <- (1-pnorm(abs(z.chon), 0, 1))*2
pvalue.chon
##          (Intercept)          PSQ          IMA        PHB         PEV
## Notloyal  0.05406044 3.837732e-04 8.380124e-01 0.27588622 0.059399542
## Loyal     0.00000000 3.002201e-10 5.708712e-09 0.03132854 0.001782879
##                   SIM          SBE          EXB MarriedStatusMarried
## Notloyal 7.875419e-01 2.311808e-01 4.386365e-03         0.6146507700
## Loyal    5.629247e-06 2.008535e-05 1.358511e-08         0.0001153515
##          FRE2days/month-2days/week FRE2days/year-1day/month FRE<2 days/year
## Notloyal                 0.4022913              0.806254805      0.12779269
## Loyal                    0.5503892              0.003071765      0.01448424
exp(coef(mlm.chon))
##           (Intercept)       PSQ      IMA       PHB      PEV      SIM      SBE
## Notloyal 7.137688e+01 0.2234782 1.105282 0.5938424 2.127263 1.104124 1.652222
## Loyal    3.213879e-09 3.1805481 2.562695 1.3824489 1.390146 1.630492 0.564378
##                EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal 0.2007176             1.603372                 2.9796662
## Loyal    2.8124099             2.375481                 0.8563217
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                1.3484084       4.4459992
## Loyal                   0.3585408       0.4206406
exp(confint(mlm.chon))
## , , Notloyal
## 
##                                2.5 %       97.5 %
## (Intercept)               0.92823549 5488.5417774
## PSQ                       0.09773438    0.5110026
## IMA                       0.42334173    2.8857243
## PHB                       0.23257095    1.5163064
## PEV                       0.97051792    4.6627163
## SIM                       0.53724322    2.2691584
## SBE                       0.72627346    3.7586903
## EXB                       0.06649549    0.6058690
## MarriedStatusMarried      0.25516173   10.0751910
## FRE2days/month-2days/week 0.23149521   38.3524594
## FRE2days/year-1day/month  0.12370054   14.6984423
## FRE<2 days/year           0.65165347   30.3334664
## 
## , , Loyal
## 
##                                  2.5 %       97.5 %
## (Intercept)               1.913638e-10 5.397581e-08
## PSQ                       2.218900e+00 4.558964e+00
## IMA                       1.867164e+00 3.517314e+00
## PHB                       1.029445e+00 1.856501e+00
## PEV                       1.130607e+00 1.709264e+00
## SIM                       1.320249e+00 2.013640e+00
## SBE                       4.338870e-01 7.341139e-01
## EXB                       1.968239e+00 4.018643e+00
## MarriedStatusMarried      1.530210e+00 3.687669e+00
## FRE2days/month-2days/week 5.146929e-01 1.424708e+00
## FRE2days/year-1day/month  1.818120e-01 7.070574e-01
## FRE<2 days/year           2.101035e-01 8.421490e-01
# Tinh xs uoc luong cho danh gia trung thanh cua 6 quan sat cuoi
xs <- fitted(mlm.chon)
tail(xs)
##         Normal     Notloyal      Loyal
## 868 0.45498404 2.719525e-03 0.54229643
## 869 0.34905208 3.300121e-05 0.65091492
## 870 0.09663928 2.342619e-06 0.90335838
## 871 0.02144760 5.231910e-06 0.97854717
## 872 0.04974320 5.491224e-06 0.95025131
## 873 0.97676754 5.593650e-03 0.01763881
# Uoc tinh xs uoc luong TB (averaged predicted probabilities) cua long trung thanh tuong ung voi nhom doc than va co gia dinh voi cac gia tri khac nhau cua su cam nhan ve gia tri doi voi moi truong
Data.cu <- DataLOY[1:854,]
head(Data.cu)
##   ID   AGE      CITY                    FRE  TripPurpose Departure
## 1  3 16-25 HoChiMinh          >=3 days/week     Studying    Normal
## 2  4 16-25 HoChiMinh 2days/month-2days/week Entertaining    Normal
## 3  5 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 4  6 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 5  7 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
## 6  8 16-25 HoChiMinh          >=3 days/week     Studying Peak-Hour
##      TimeUseonBus TravelTime PSSW PSSS PSAB PSEB PSQ           SAT    LOY IMA
## 1         Nothing       3.00  4.9  5.4  5.5  5.8 4.8     Satisfied  Loyal 5.6
## 2         Nothing       2.00  3.4  2.4  3.5  6.0 4.6        Normal Normal 4.8
## 3         Nothing       0.17  3.9  3.4  4.5  4.5 2.7 Not satisfied Normal 3.0
## 4 Using.telephone       4.00  4.1  4.4  5.5  6.0 4.8        Normal Normal 5.0
## 5         Nothing       2.00  3.7  2.6  3.5  4.5 4.5        Normal Normal 4.6
## 6          Others       2.00  4.6  2.7  3.8  4.0 3.9        Normal Normal 3.0
##   PHB PEV ATM PPI SIM PPA SBE EXB EC_Stop WC_Stop EC_Bus WC_Bus Gender
## 1 6.6 4.0 4.3 6.0 3.5 4.5 4.0 4.8   Never    Ever  Never   Ever Female
## 2 4.0 5.3 4.1 4.0 4.0 4.0 4.8 4.2   Never   Never   Ever  Never Female
## 3 5.0 5.8 3.1 2.7 3.5 4.5 6.0 4.0   Never   Never  Never  Never   Male
## 4 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0   Never    Ever  Never   Ever   Male
## 5 5.6 6.0 3.3 3.0 5.5 5.0 5.0 4.2   Never    Ever  Never   Ever   Male
## 6 5.4 5.3 2.7 3.0 2.0 2.5 2.0 5.0   Never    Ever  Never   Ever Female
##   MarriedStatus      Occupation     Education     Income
## 1        Single Students/Pupils Undergraduate <5millions
## 2        Single Students/Pupils Undergraduate <5millions
## 3        Single Students/Pupils Undergraduate <5millions
## 4        Single Students/Pupils Undergraduate <5millions
## 5        Single Students/Pupils Undergraduate <5millions
## 6        Single Students/Pupils   High.school <5millions
dim(Data.cu)
## [1] 854  33
str(Data.cu)
## 'data.frame':    854 obs. of  33 variables:
##  $ ID           : int  3 4 5 6 7 8 10 11 12 13 ...
##  $ AGE          : Factor w/ 5 levels "16-25","26-35",..: 1 1 1 1 1 1 3 1 1 2 ...
##  $ CITY         : Factor w/ 2 levels "DaNang","HoChiMinh": 2 2 2 2 2 2 2 2 2 2 ...
##  $ FRE          : Factor w/ 4 levels ">=3 days/week",..: 1 2 1 1 1 1 1 1 1 1 ...
##  $ TripPurpose  : Factor w/ 5 levels "Working","Studying",..: 2 4 2 2 2 2 1 2 2 2 ...
##  $ Departure    : Factor w/ 2 levels "Normal","Peak-Hour": 1 1 2 2 2 2 2 2 1 2 ...
##  $ TimeUseonBus : Factor w/ 6 levels "Using.telephone",..: 4 4 4 1 4 6 4 4 3 3 ...
##  $ TravelTime   : num  3 2 0.17 4 2 2 2 2.5 1.5 2 ...
##  $ PSSW         : num  4.9 3.4 3.9 4.1 3.7 4.6 3.9 3.4 5.3 4 ...
##  $ PSSS         : num  5.4 2.4 3.4 4.4 2.6 2.7 4 2.7 3.1 4.7 ...
##  $ PSAB         : num  5.5 3.5 4.5 5.5 3.5 3.8 6 3.5 4.8 5.5 ...
##  $ PSEB         : num  5.8 6 4.5 6 4.5 4 4.5 6.3 7 4.5 ...
##  $ PSQ          : num  4.8 4.6 2.7 4.8 4.5 3.9 4.2 4.1 6 4.5 ...
##  $ SAT          : Factor w/ 3 levels "Not satisfied",..: 3 2 1 2 2 2 3 2 3 3 ...
##  $ LOY          : Factor w/ 3 levels "Normal","Notloyal",..: 3 1 1 1 1 1 3 1 3 3 ...
##  $ IMA          : num  5.6 4.8 3 5 4.6 3 5.8 5.8 6.8 6 ...
##  $ PHB          : num  6.6 4 5 5 5.6 5.4 5.8 5.6 7 6.4 ...
##  $ PEV          : num  4 5.3 5.8 5 6 5.3 6.3 6.5 7 5.3 ...
##  $ ATM          : num  4.3 4.1 3.1 5 3.3 2.7 4 4.1 4.4 3.9 ...
##  $ PPI          : num  6 4 2.7 5 3 3 6 2 3.3 5.3 ...
##  $ SIM          : num  3.5 4 3.5 5 5.5 2 6 5.3 4.3 6 ...
##  $ PPA          : num  4.5 4 4.5 5 5 2.5 4 4 4 4.3 ...
##  $ SBE          : num  4 4.8 6 5 5 2 5.3 4 5 3.8 ...
##  $ EXB          : num  4.8 4.2 4 5 4.2 5 5.3 5.3 5.3 5 ...
##  $ EC_Stop      : Factor w/ 2 levels "Ever","Never": 2 2 2 2 2 2 2 2 2 2 ...
##  $ WC_Stop      : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ EC_Bus       : Factor w/ 2 levels "Ever","Never": 2 1 2 2 2 2 2 2 2 2 ...
##  $ WC_Bus       : Factor w/ 2 levels "Ever","Never": 1 2 2 1 1 1 2 1 2 2 ...
##  $ Gender       : Factor w/ 2 levels "Male","Female": 2 2 1 1 1 2 2 2 2 1 ...
##  $ MarriedStatus: Factor w/ 2 levels "Single","Married": 1 1 1 1 1 1 2 1 1 1 ...
##  $ Occupation   : Factor w/ 7 levels "Students/Pupils",..: 1 1 1 1 1 1 2 1 1 7 ...
##  $ Education    : Factor w/ 5 levels "Secondary.school",..: 2 2 2 2 2 3 1 2 3 5 ...
##  $ Income       : Factor w/ 4 levels "<5millions","5-10millions",..: 1 1 1 1 1 1 1 1 1 1 ...
attach(Data.cu)
## The following objects are masked from DataLOY (pos = 3):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
## The following objects are masked from DataLOY (pos = 5):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
## The following objects are masked from DataLOY (pos = 33):
## 
##     AGE, ATM, CITY, Departure, EC_Bus, EC_Stop, Education, EXB, FRE,
##     Gender, ID, IMA, Income, LOY, MarriedStatus, Occupation, PEV, PHB,
##     PPA, PPI, PSAB, PSEB, PSQ, PSSS, PSSW, SAT, SBE, SIM, TimeUseonBus,
##     TravelTime, TripPurpose, WC_Bus, WC_Stop
mlm.chon1 <- multinom(LOY ~  PSQ + IMA + PHB + PEV + SIM + SBE + EXB + MarriedStatus +  FRE, data = Data.cu)
## # weights:  39 (24 variable)
## initial  value 938.214895 
## iter  10 value 470.687536
## iter  20 value 366.514280
## iter  30 value 331.951176
## iter  40 value 329.268243
## final  value 329.265939 
## converged
summary(mlm.chon1)
## Call:
## multinom(formula = LOY ~ PSQ + IMA + PHB + PEV + SIM + SBE + 
##     EXB + MarriedStatus + FRE, data = Data.cu)
## 
## Coefficients:
##          (Intercept)       PSQ       IMA        PHB       PEV        SIM
## Notloyal    4.262732 -1.497636 0.1014050 -0.5205148 0.7516796 0.09559579
## Loyal     -19.560706  1.164437 0.9081724  0.3370220 0.3258676 0.51909665
##                 SBE       EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal  0.5057077 -1.603065            0.4625811                 1.0924135
## Loyal    -0.6033075  1.048026            0.9032797                -0.2057903
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                0.3096484       1.4882731
## Loyal                  -1.0558184      -0.9212638
## 
## Std. Errors:
##          (Intercept)       PSQ       IMA       PHB       PEV       SIM
## Notloyal    2.214285 0.4218362 0.4896842 0.4779046 0.4000302 0.3692560
## Loyal       1.455165 0.1849965 0.1621868 0.1534888 0.1083540 0.1115148
##                SBE       EXB MarriedStatusMarried FRE2days/month-2days/week
## Notloyal 0.4206059 0.5627949            0.9369001                 1.3018995
## Loyal    0.1366363 0.1846856            0.2262039                 0.2616726
##          FRE2days/year-1day/month FRE<2 days/year
## Notloyal                1.2187101       0.9795909
## Loyal                   0.3499571       0.3610208
## 
## Residual Deviance: 658.5319 
## AIC: 706.5319
MarriedStatus <- rep(c("Single", "Married"), each = 427) # Lap lai 427 lan = 854 qs , PEV gia tri 1-7 lap lai 122 lan = 854qs va bang voi Data.cu
PEV <- rep(c(1:7), 122)
Data.moi <- data.frame(MarriedStatus, PEV)
pp.PEV <- cbind(Data.moi, predict(mlm.chon1, newdata = Data.moi, type = "probs", se = TRUE))
by(pp.PEV[, 3:5], pp.PEV$MarriedStatus, colMeans)
## pp.PEV$MarriedStatus: Married
##      Normal    Notloyal       Loyal 
## 0.330183769 0.007744623 0.662071608 
## ------------------------------------------------------------ 
## pp.PEV$MarriedStatus: Single
##     Normal   Notloyal      Loyal 
## 0.56072795 0.02337454 0.41589751
library(reshape)
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:dplyr':
## 
##     rename
## The following objects are masked from 'package:tidyr':
## 
##     expand, smiths
lpp <- melt(pp.PEV, id.vars = c("MarriedStatus", "PEV"), value.name = "Prob")
library(ggplot2)
# ggplot(lpp, aes(x = PEV, y = lpp, colour = MarriedStatus)) + geom_line() + facet_grid(variable ~ ., scales = "free")