1 Input Data

knitr::opts_chunk$set(echo = TRUE)

setwd("/Users/admin/Documents/Linh-R Studio/ESS - HR/ESS")
library("readxl")
my_data <- read_excel("ESS-Nopass.xlsx")
my_data <- my_data[ -c(1) ]
my_data <- na.omit(my_data) 

test <- my_data

2 Correlation for a specific variable (means of each item)

my_data$DH <- rowMeans(my_data[,1:3]) 
my_data$NT <- rowMeans(my_data[,4:8])
my_data$KH <- rowMeans(my_data[,9:10])
my_data$TT <- rowMeans(my_data[,11:12])
my_data$CH <- rowMeans(my_data[,13:16])
my_data$CS <- rowMeans(my_data[,17:22])
my_data$DL <- rowMeans(my_data[,23:25])
my_data$QL <- rowMeans(my_data[,26:28])
my_data$QH <- rowMeans(my_data[,28:30])
my_data$HT <- rowMeans(my_data[,31:32])
my_data$DT <- rowMeans(my_data[,33:34])
my_data$CT <- rowMeans(my_data[,35:38])
my_data$CV <- rowMeans(my_data[,39:41])

olddata <- my_data[c(1:42)]
newdata <- my_data[c(43:54)]

2.1 Correlation - Solution 1

res <- cor(newdata)
round(res, 6)
##          NT       KH       TT       CH       CS       DL       QL       QH
## NT 1.000000 0.658203 0.763254 0.761008 0.626370 0.765567 0.785000 0.723536
## KH 0.658203 1.000000 0.703395 0.702533 0.662135 0.656075 0.631974 0.656916
## TT 0.763254 0.703395 1.000000 0.800307 0.685475 0.745648 0.741838 0.736005
## CH 0.761008 0.702533 0.800307 1.000000 0.726100 0.781639 0.767291 0.773907
## CS 0.626370 0.662135 0.685475 0.726100 1.000000 0.697822 0.697167 0.728828
## DL 0.765567 0.656075 0.745648 0.781639 0.697822 1.000000 0.833680 0.807846
## QL 0.785000 0.631974 0.741838 0.767291 0.697167 0.833680 1.000000 0.866301
## QH 0.723536 0.656916 0.736005 0.773907 0.728828 0.807846 0.866301 1.000000
## HT 0.627341 0.652967 0.676109 0.710886 0.694711 0.724183 0.686484 0.746677
## DT 0.709657 0.635829 0.700648 0.764910 0.673519 0.760386 0.784498 0.772733
## CT 0.734071 0.673675 0.744793 0.777538 0.715409 0.804706 0.809991 0.816244
## CV 0.668853 0.685639 0.696486 0.741451 0.700915 0.759118 0.717976 0.780533
##          HT       DT       CT       CV
## NT 0.627341 0.709657 0.734071 0.668853
## KH 0.652967 0.635829 0.673675 0.685639
## TT 0.676109 0.700648 0.744793 0.696486
## CH 0.710886 0.764910 0.777538 0.741451
## CS 0.694711 0.673519 0.715409 0.700915
## DL 0.724183 0.760386 0.804706 0.759118
## QL 0.686484 0.784498 0.809991 0.717976
## QH 0.746677 0.772733 0.816244 0.780533
## HT 1.000000 0.717074 0.759073 0.767885
## DT 0.717074 1.000000 0.810214 0.757045
## CT 0.759073 0.810214 1.000000 0.819434
## CV 0.767885 0.757045 0.819434 1.000000

2.2 Correlation - Solution 2

## Correlation plot (pie, circle, heatmap)
library(corrplot)
## corrplot 0.84 loaded
# Pie 
corrplot(res, type = "upper", order = "hclust", 
         tl.col = "black", tl.srt = 45)

corrplot(res, method = "pie")

# Correlation heatmap
col <- colorRampPalette(c("darkblue", "white", "darkorange"))(20)
M <- cor(newdata)
heatmap(x = M, col = col, symm = TRUE)

## Export into excel file
library(writexl)
upper<-res
upper[upper.tri(res)]<-""
upper<-as.data.frame(upper)
upper
##                   NT                KH                TT                CH
## NT                 1                                                      
## KH 0.658203145828389                 1                                    
## TT 0.763253559374586 0.703394575696487                 1                  
## CH 0.761007648867122 0.702532659727441 0.800307076685778                 1
## CS 0.626370214460452 0.662134525786591 0.685474528013414 0.726100413189445
## DL 0.765566762765866 0.656074811463507 0.745647757890997 0.781639250040078
## QL 0.784999551320267 0.631974065978829 0.741837737624891 0.767290681084914
## QH 0.723536178168543 0.656916207293568 0.736004971949652 0.773906636721702
## HT 0.627341427818635 0.652967467752543 0.676109486739313 0.710885743441686
## DT 0.709656698409222 0.635829075345458 0.700647859012543 0.764910137607201
## CT 0.734071287765528  0.67367496099712 0.744792621745189 0.777537606993567
## CV 0.668852613540677 0.685638858220821 0.696486066424247  0.74145080934489
##                   CS                DL                QL                QH
## NT                                                                        
## KH                                                                        
## TT                                                                        
## CH                                                                        
## CS                 1                                                      
## DL 0.697822376228962                 1                                    
## QL 0.697166621183244  0.83368007089554                 1                  
## QH  0.72882814898696  0.80784612255448 0.866300963970487                 1
## HT 0.694710634374023 0.724182549975363 0.686484144514859 0.746676985787315
## DT 0.673519123547731 0.760386016460523 0.784498361552956  0.77273287024638
## CT 0.715408820900081  0.80470646281935 0.809991382848679 0.816243645539131
## CV 0.700915114378782 0.759118443972732 0.717976078832553 0.780532872369978
##                   HT                DT                CT CV
## NT                                                         
## KH                                                         
## TT                                                         
## CH                                                         
## CS                                                         
## DL                                                         
## QL                                                         
## QH                                                         
## HT                 1                                       
## DT 0.717074112189547                 1                     
## CT  0.75907269205557 0.810213757329126                 1   
## CV 0.767885150623097  0.75704506634735 0.819433550458649  1

2.3 Correlation - Solution 3

library(psych)
# corr.test(select(my_data, DH,NT,KH,TT,CH,CS,DL,QL,QH,HT,DT,CT,CV)) 
corr.test(newdata)
## Call:corr.test(x = newdata)
## Correlation matrix 
##      NT   KH   TT   CH   CS   DL   QL   QH   HT   DT   CT   CV
## NT 1.00 0.66 0.76 0.76 0.63 0.77 0.78 0.72 0.63 0.71 0.73 0.67
## KH 0.66 1.00 0.70 0.70 0.66 0.66 0.63 0.66 0.65 0.64 0.67 0.69
## TT 0.76 0.70 1.00 0.80 0.69 0.75 0.74 0.74 0.68 0.70 0.74 0.70
## CH 0.76 0.70 0.80 1.00 0.73 0.78 0.77 0.77 0.71 0.76 0.78 0.74
## CS 0.63 0.66 0.69 0.73 1.00 0.70 0.70 0.73 0.69 0.67 0.72 0.70
## DL 0.77 0.66 0.75 0.78 0.70 1.00 0.83 0.81 0.72 0.76 0.80 0.76
## QL 0.78 0.63 0.74 0.77 0.70 0.83 1.00 0.87 0.69 0.78 0.81 0.72
## QH 0.72 0.66 0.74 0.77 0.73 0.81 0.87 1.00 0.75 0.77 0.82 0.78
## HT 0.63 0.65 0.68 0.71 0.69 0.72 0.69 0.75 1.00 0.72 0.76 0.77
## DT 0.71 0.64 0.70 0.76 0.67 0.76 0.78 0.77 0.72 1.00 0.81 0.76
## CT 0.73 0.67 0.74 0.78 0.72 0.80 0.81 0.82 0.76 0.81 1.00 0.82
## CV 0.67 0.69 0.70 0.74 0.70 0.76 0.72 0.78 0.77 0.76 0.82 1.00
## Sample Size 
## [1] 4978
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##    NT KH TT CH CS DL QL QH HT DT CT CV
## NT  0  0  0  0  0  0  0  0  0  0  0  0
## KH  0  0  0  0  0  0  0  0  0  0  0  0
## TT  0  0  0  0  0  0  0  0  0  0  0  0
## CH  0  0  0  0  0  0  0  0  0  0  0  0
## CS  0  0  0  0  0  0  0  0  0  0  0  0
## DL  0  0  0  0  0  0  0  0  0  0  0  0
## QL  0  0  0  0  0  0  0  0  0  0  0  0
## QH  0  0  0  0  0  0  0  0  0  0  0  0
## HT  0  0  0  0  0  0  0  0  0  0  0  0
## DT  0  0  0  0  0  0  0  0  0  0  0  0
## CT  0  0  0  0  0  0  0  0  0  0  0  0
## CV  0  0  0  0  0  0  0  0  0  0  0  0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
library(GGally)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
# ggpairs(select(my_data, DH,NT,KH,TT,CH,CS,DL,QL,QH,HT,DT,CT,CV))
ggpairs(newdata)

2.4 SD & SE

VARIABLE <- as.data.frame(sapply(newdata, function(x) c(mean = mean(x), var = var(x), sd = sd(x))))
ITEM <- as.data.frame(sapply(olddata, function(x) c(mean = mean(x), var = var(x), sd = sd(x))))

3 Cronbach Alpha

3.1 Alpha Calculation

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:GGally':
## 
##     nasa
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
Dinh.huong.1 <- select(my_data,1,2,3)
Niem.tin.1 <- select(my_data,4,5,6,7,8)
Chutrong.KH.CL.1 <- select(my_data,9,10)
Tontrong.Ghinhan.1 <- select(my_data, 11, 12)
Cohoi.Phattrien.1 <- select(my_data,13,14,15,16)
Chinhsach.phucloi.1 <- select(my_data,17,18,19,20,21,22)
Dongluc.lamviec.1 <- select(my_data,23,24,25)
Quanly.congviec.1 <- select(my_data,26,27,28)
Traoquyen.1 <- select(my_data,29,30)
Hotro.1 <- select(my_data,31,32)
Daotao.1 <- select(my_data,33,34)
Sucongtac.1 <- select(my_data,35,36,37,38)
Congviec.Cocau.Quytrinh.1 <- select(my_data,39,40,41)

library(psych)
library(psych)

# To do the reliability analysis, you’ll need to load the psych package and use the alpha function. However, ggplot2 also has a function called alpha. If you’ve loaded ggplot2, the alpha function in ggplot2 will be called instead. If that happens (Error in grDevices::col2rgb(colour, TRUE) : invalid color name)), you can specify the package using psych::alpha() (instead of alpha(x) only). 

psych::alpha(Dinh.huong.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Dinh.huong.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.92      0.92    0.89      0.79  11 0.002  4.3 0.69     0.78
## 
##  lower alpha upper     95% confidence boundaries
## 0.91 0.92 0.92 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r  S/N alpha se var.r med.r
## DH1      0.91      0.91    0.84      0.84 10.2   0.0025    NA  0.84
## DH2      0.86      0.86    0.75      0.75  6.1   0.0040    NA  0.75
## DH3      0.88      0.88    0.78      0.78  7.2   0.0035    NA  0.78
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## DH1 4978  0.91  0.91  0.83   0.80  4.3 0.78
## DH2 4978  0.94  0.94  0.90   0.86  4.2 0.74
## DH3 4978  0.93  0.93  0.88   0.84  4.2 0.73
## 
## Non missing response frequency for each item
##        1 2    3    4    5 miss
## DH1 0.02 0 0.05 0.53 0.39    0
## DH2 0.02 0 0.06 0.56 0.36    0
## DH3 0.02 0 0.05 0.57 0.36    0
psych::alpha(Niem.tin.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Niem.tin.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.94      0.94    0.93      0.75  15 0.0014  4.1 0.71     0.76
## 
##  lower alpha upper     95% confidence boundaries
## 0.93 0.94 0.94 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## NT1      0.92      0.92    0.91      0.75  12   0.0018 0.0058  0.74
## NT2      0.94      0.94    0.92      0.79  15   0.0014 0.0012  0.79
## NT3      0.92      0.92    0.90      0.73  11   0.0020 0.0024  0.73
## NT4      0.92      0.92    0.90      0.74  11   0.0019 0.0026  0.73
## NT5      0.92      0.92    0.91      0.75  12   0.0019 0.0044  0.74
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## NT1 4978  0.90  0.90  0.86   0.84  4.1 0.78
## NT2 4978  0.84  0.84  0.77   0.75  4.0 0.82
## NT3 4978  0.92  0.92  0.91   0.87  4.1 0.78
## NT4 4978  0.91  0.91  0.89   0.86  4.1 0.77
## NT5 4978  0.90  0.90  0.87   0.84  4.1 0.81
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## NT1 0.02 0.02 0.11 0.58 0.27    0
## NT2 0.02 0.03 0.13 0.56 0.26    0
## NT3 0.02 0.02 0.10 0.58 0.29    0
## NT4 0.02 0.02 0.11 0.60 0.26    0
## NT5 0.02 0.03 0.11 0.57 0.28    0
psych::alpha(Chutrong.KH.CL.1)
## Warning in matrix(unlist(drop.item), ncol = 10, byrow = TRUE): data length [16]
## is not a sub-multiple or multiple of the number of columns [10]
## 
## Reliability analysis   
## Call: psych::alpha(x = Chutrong.KH.CL.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.83      0.83    0.72      0.72   5 0.0047    4 0.73     0.72
## 
##  lower alpha upper     95% confidence boundaries
## 0.82 0.83 0.84 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## KH1      0.72      0.72    0.51      0.72  NA       NA  0.72  0.72
## KH2      0.51      0.72      NA        NA  NA       NA  0.51  0.72
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## KH1 4978  0.93  0.93  0.78   0.72    4 0.80
## KH2 4978  0.92  0.93  0.78   0.72    4 0.78
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## KH1 0.02 0.02 0.15 0.59 0.22    0
## KH2 0.01 0.03 0.15 0.59 0.22    0
psych::alpha(Tontrong.Ghinhan.1)
## Warning in matrix(unlist(drop.item), ncol = 10, byrow = TRUE): data length [16]
## is not a sub-multiple or multiple of the number of columns [10]
## 
## Reliability analysis   
## Call: psych::alpha(x = Tontrong.Ghinhan.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.86      0.86    0.75      0.75   6 0.0041    4 0.72     0.75
## 
##  lower alpha upper     95% confidence boundaries
## 0.85 0.86 0.86 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## TT1      0.75      0.75    0.56      0.75  NA       NA  0.75  0.75
## TT2      0.56      0.75      NA        NA  NA       NA  0.56  0.75
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## TT1 4978  0.93  0.94  0.81   0.75    4 0.75
## TT2 4978  0.94  0.94  0.81   0.75    4 0.80
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## TT1 0.02 0.02 0.14 0.61 0.21    0
## TT2 0.02 0.03 0.13 0.59 0.23    0
psych::alpha(Cohoi.Phattrien.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Cohoi.Phattrien.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##        0.9       0.9    0.87      0.69 8.8 0.0024    4 0.66     0.69
## 
##  lower alpha upper     95% confidence boundaries
## 0.89 0.9 0.9 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se   var.r med.r
## CH1      0.87      0.87    0.82      0.69 6.6   0.0033 0.00317  0.69
## CH2      0.87      0.87    0.82      0.70 6.8   0.0032 0.00227  0.70
## CH3      0.87      0.87    0.82      0.70 7.0   0.0031 0.00024  0.70
## CH4      0.86      0.86    0.80      0.66 5.9   0.0035 0.00208  0.65
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## CH1 4978  0.88  0.87  0.82   0.77  4.0 0.79
## CH2 4978  0.87  0.87  0.80   0.76  4.0 0.79
## CH3 4978  0.85  0.86  0.80   0.75  4.1 0.70
## CH4 4978  0.89  0.89  0.85   0.80  4.0 0.74
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## CH1 0.02 0.03 0.13 0.59 0.23    0
## CH2 0.02 0.03 0.14 0.59 0.22    0
## CH3 0.01 0.01 0.10 0.64 0.24    0
## CH4 0.01 0.01 0.14 0.62 0.22    0
psych::alpha(Chinhsach.phucloi.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Chinhsach.phucloi.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.94      0.94    0.93      0.72  15 0.0013  3.9 0.71     0.73
## 
##  lower alpha upper     95% confidence boundaries
## 0.94 0.94 0.94 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## CS1      0.94      0.94    0.93      0.76  15   0.0014 0.0014  0.76
## CS2      0.93      0.93    0.92      0.72  13   0.0016 0.0062  0.76
## CS3      0.93      0.93    0.91      0.71  12   0.0017 0.0042  0.71
## CS4      0.92      0.92    0.91      0.71  12   0.0017 0.0041  0.72
## CS5      0.92      0.92    0.91      0.71  12   0.0017 0.0042  0.72
## CS6      0.92      0.92    0.91      0.71  12   0.0017 0.0032  0.71
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## CS1 4978  0.80  0.81  0.75   0.72  4.0 0.76
## CS2 4978  0.87  0.87  0.84   0.81  3.9 0.80
## CS3 4978  0.89  0.89  0.86   0.84  3.8 0.88
## CS4 4978  0.89  0.90  0.88   0.85  3.9 0.78
## CS5 4978  0.89  0.89  0.87   0.84  3.9 0.81
## CS6 4978  0.90  0.90  0.88   0.85  3.8 0.85
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## CS1 0.02 0.02 0.11 0.62 0.23    0
## CS2 0.02 0.04 0.15 0.60 0.19    0
## CS3 0.02 0.06 0.21 0.54 0.17    0
## CS4 0.01 0.04 0.18 0.60 0.17    0
## CS5 0.02 0.04 0.18 0.58 0.18    0
## CS6 0.02 0.06 0.21 0.55 0.16    0
psych::alpha(Dongluc.lamviec.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Dongluc.lamviec.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.84      0.84    0.79      0.64 5.4 0.0039    4 0.65     0.67
## 
##  lower alpha upper     95% confidence boundaries
## 0.83 0.84 0.85 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## DL1      0.80      0.80    0.67      0.67 4.1   0.0056    NA  0.67
## DL2      0.73      0.73    0.58      0.58 2.7   0.0076    NA  0.58
## DL3      0.80      0.81    0.68      0.68 4.2   0.0055    NA  0.68
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## DL1 4978  0.87  0.86  0.75   0.68    4 0.78
## DL2 4978  0.89  0.90  0.83   0.76    4 0.72
## DL3 4978  0.86  0.86  0.74   0.68    4 0.75
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## DL1 0.02 0.03 0.14 0.60 0.22    0
## DL2 0.01 0.01 0.11 0.64 0.22    0
## DL3 0.02 0.02 0.11 0.62 0.24    0
psych::alpha(Quanly.congviec.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Quanly.congviec.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##       0.91      0.91    0.88      0.77  10 0.0022    4 0.7     0.77
## 
##  lower alpha upper     95% confidence boundaries
## 0.91 0.91 0.92 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## QL1      0.87      0.87    0.77      0.77 6.8   0.0036    NA  0.77
## QL2      0.84      0.84    0.72      0.72 5.2   0.0046    NA  0.72
## QL3      0.91      0.91    0.83      0.83 9.7   0.0027    NA  0.83
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## QL1 4978  0.92  0.92  0.87   0.82  4.0 0.74
## QL2 4978  0.94  0.94  0.91   0.86  4.0 0.77
## QL3 4978  0.90  0.90  0.82   0.78  3.9 0.77
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## QL1 0.01 0.02 0.13 0.63 0.21    0
## QL2 0.01 0.03 0.14 0.60 0.21    0
## QL3 0.02 0.03 0.15 0.62 0.19    0
psych::alpha(Traoquyen.1)
## Warning in matrix(unlist(drop.item), ncol = 10, byrow = TRUE): data length [16]
## is not a sub-multiple or multiple of the number of columns [10]
## 
## Reliability analysis   
## Call: psych::alpha(x = Traoquyen.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.89      0.89     0.8       0.8 7.8 0.0032    4 0.66      0.8
## 
##  lower alpha upper     95% confidence boundaries
## 0.88 0.89 0.89 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## QH1      0.80       0.8    0.63       0.8  NA       NA  0.80   0.8
## QH2      0.63       0.8      NA        NA  NA       NA  0.63   0.8
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## QH1 4978  0.95  0.95  0.85    0.8    4 0.71
## QH2 4978  0.95  0.95  0.85    0.8    4 0.68
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## QH1 0.01 0.02 0.12 0.65 0.20    0
## QH2 0.01 0.01 0.11 0.66 0.21    0
psych::alpha(Hotro.1)
## Warning in matrix(unlist(drop.item), ncol = 10, byrow = TRUE): data length [16]
## is not a sub-multiple or multiple of the number of columns [10]
## 
## Reliability analysis   
## Call: psych::alpha(x = Hotro.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.81      0.81    0.68      0.68 4.3 0.0054    4 0.69     0.68
## 
##  lower alpha upper     95% confidence boundaries
## 0.8 0.81 0.82 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## HT1      0.68      0.68    0.47      0.68  NA       NA  0.68  0.68
## HT2      0.47      0.68      NA        NA  NA       NA  0.47  0.68
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## HT1 4978  0.92  0.92  0.76   0.68  3.9 0.76
## HT2 4978  0.91  0.92  0.76   0.68  4.1 0.73
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## HT1 0.02 0.03 0.14 0.62 0.19    0
## HT2 0.02 0.01 0.09 0.61 0.27    0
psych::alpha(Daotao.1)
## Warning in matrix(unlist(drop.item), ncol = 10, byrow = TRUE): data length [16]
## is not a sub-multiple or multiple of the number of columns [10]
## 
## Reliability analysis   
## Call: psych::alpha(x = Daotao.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.86      0.86    0.75      0.75 6.1 0.004    4 0.69     0.75
## 
##  lower alpha upper     95% confidence boundaries
## 0.85 0.86 0.87 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## DT1      0.75      0.75    0.57      0.75  NA       NA  0.75  0.75
## DT2      0.57      0.75      NA        NA  NA       NA  0.57  0.75
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## DT1 4978  0.93  0.94  0.81   0.75    4 0.72
## DT2 4978  0.94  0.94  0.81   0.75    4 0.76
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## DT1 0.01 0.02 0.11 0.64 0.22    0
## DT2 0.01 0.03 0.13 0.61 0.22    0
psych::alpha(Sucongtac.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Sucongtac.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##        0.9       0.9    0.88       0.7 9.3 0.0023    4 0.67      0.7
## 
##  lower alpha upper     95% confidence boundaries
## 0.9 0.9 0.91 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se   var.r med.r
## CT1      0.88      0.88    0.84      0.71 7.5   0.0030 0.00126  0.73
## CT2      0.88      0.88    0.83      0.71 7.4   0.0029 0.00046  0.71
## CT3      0.87      0.87    0.82      0.70 6.9   0.0032 0.00130  0.69
## CT4      0.86      0.86    0.81      0.68 6.4   0.0034 0.00057  0.67
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## CT1 4978  0.87  0.87  0.80   0.76  4.0 0.75
## CT2 4978  0.88  0.87  0.81   0.77  3.8 0.83
## CT3 4978  0.88  0.88  0.83   0.79  4.0 0.74
## CT4 4978  0.89  0.90  0.86   0.81  4.0 0.71
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## CT1 0.01 0.03 0.14 0.62 0.21    0
## CT2 0.02 0.04 0.18 0.58 0.17    0
## CT3 0.01 0.02 0.11 0.63 0.23    0
## CT4 0.01 0.01 0.13 0.65 0.20    0
psych::alpha(Congviec.Cocau.Quytrinh.1)
## 
## Reliability analysis   
## Call: psych::alpha(x = Congviec.Cocau.Quytrinh.1)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd median_r
##       0.88      0.88    0.84       0.7 7.1 0.003  4.1 0.65     0.64
## 
##  lower alpha upper     95% confidence boundaries
## 0.87 0.88 0.88 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r  S/N alpha se var.r med.r
## CV1      0.91      0.91    0.84      0.84 10.3   0.0025    NA  0.84
## CV2      0.77      0.77    0.63      0.63  3.4   0.0065    NA  0.63
## CV3      0.78      0.78    0.64      0.64  3.6   0.0062    NA  0.64
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## CV1 4978  0.83  0.85  0.69   0.66  4.2 0.66
## CV2 4978  0.93  0.92  0.89   0.83  4.0 0.75
## CV3 4978  0.93  0.92  0.88   0.82  4.0 0.76
## 
## Non missing response frequency for each item
##        1    2    3    4    5 miss
## CV1 0.01 0.00 0.05 0.63 0.30    0
## CV2 0.01 0.02 0.14 0.62 0.20    0
## CV3 0.01 0.02 0.14 0.61 0.21    0
psych::alpha(my_data)
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was done
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was done
## In smc, smcs < 0 were set to .0
## 
## Reliability analysis   
## Call: psych::alpha(x = my_data)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N     ase mean   sd median_r
##       0.99      0.99    0.99      0.61  86 0.00024    4 0.59      0.6
## 
##  lower alpha upper     95% confidence boundaries
## 0.99 0.99 0.99 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## DH1      0.99      0.99    0.99      0.62  86  0.00024 0.0083  0.61
## DH2      0.99      0.99    0.99      0.62  86  0.00024 0.0088  0.61
## DH3      0.99      0.99    0.99      0.62  85  0.00024 0.0088  0.61
## NT1      0.99      0.99    0.99      0.61  85  0.00025 0.0091  0.60
## NT2      0.99      0.99    0.99      0.62  85  0.00025 0.0092  0.60
## NT3      0.99      0.99    0.99      0.61  85  0.00025 0.0090  0.60
## NT4      0.99      0.99    0.99      0.61  85  0.00025 0.0090  0.60
## NT5      0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## KH1      0.99      0.99    0.99      0.62  85  0.00024 0.0091  0.61
## KH2      0.99      0.99    0.99      0.62  85  0.00024 0.0091  0.61
## TT1      0.99      0.99    0.99      0.61  84  0.00025 0.0092  0.60
## TT2      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## CH1      0.99      0.99    0.99      0.61  84  0.00025 0.0092  0.60
## CH2      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## CH3      0.99      0.99    0.99      0.62  85  0.00025 0.0092  0.60
## CH4      0.99      0.99    0.99      0.61  84  0.00025 0.0092  0.60
## CS1      0.99      0.99    0.99      0.62  85  0.00024 0.0092  0.61
## CS2      0.99      0.99    0.99      0.62  85  0.00024 0.0091  0.61
## CS3      0.99      0.99    0.99      0.62  85  0.00024 0.0089  0.61
## CS4      0.99      0.99    0.99      0.62  85  0.00024 0.0090  0.60
## CS5      0.99      0.99    0.99      0.62  85  0.00024 0.0090  0.61
## CS6      0.99      0.99    0.99      0.62  85  0.00024 0.0088  0.61
## DL1      0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## DL2      0.99      0.99    0.99      0.61  84  0.00025 0.0092  0.60
## DL3      0.99      0.99    0.99      0.62  85  0.00024 0.0092  0.60
## QL1      0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## QL2      0.99      0.99    0.99      0.61  84  0.00025 0.0089  0.60
## QL3      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## QH1      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## QH2      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## HT1      0.99      0.99    0.99      0.61  85  0.00025 0.0091  0.60
## HT2      0.99      0.99    0.99      0.62  85  0.00025 0.0091  0.60
## DT1      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## DT2      0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## CT1      0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## CT2      0.99      0.99    0.99      0.61  85  0.00025 0.0091  0.60
## CT3      0.99      0.99    0.99      0.61  85  0.00025 0.0091  0.60
## CT4      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## CV1      0.99      0.99    0.99      0.62  85  0.00024 0.0091  0.60
## CV2      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## CV3      0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## DH       0.99      0.99    0.99      0.62  85  0.00024 0.0088  0.61
## NT       0.99      0.99    0.99      0.61  84  0.00025 0.0088  0.60
## KH       0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## TT       0.99      0.99    0.99      0.61  84  0.00025 0.0090  0.60
## CH       0.99      0.99    0.99      0.61  83  0.00025 0.0089  0.60
## CS       0.99      0.99    0.99      0.61  84  0.00025 0.0089  0.60
## DL       0.99      0.99    0.99      0.61  83  0.00025 0.0088  0.60
## QL       0.99      0.99    0.99      0.61  83  0.00025 0.0087  0.60
## QH       0.99      0.99    0.99      0.61  83  0.00025 0.0088  0.60
## HT       0.99      0.99    0.99      0.61  84  0.00025 0.0091  0.60
## DT       0.99      0.99    0.99      0.61  84  0.00025 0.0089  0.60
## CT       0.99      0.99    0.99      0.61  83  0.00025 0.0087  0.60
## CV       0.99      0.99    0.99      0.61  83  0.00025 0.0089  0.60
## 
##  Item statistics 
##        n raw.r std.r r.cor r.drop mean   sd
## DH1 4978  0.62  0.62  0.62   0.60  4.3 0.78
## DH2 4978  0.68  0.68  0.68   0.67  4.2 0.74
## DH3 4978  0.69  0.69  0.69   0.68  4.2 0.73
## NT1 4978  0.77  0.77  0.76   0.76  4.1 0.78
## NT2 4978  0.76  0.76  0.75   0.75  4.0 0.82
## NT3 4978  0.78  0.78  0.78   0.77  4.1 0.78
## NT4 4978  0.77  0.77  0.77   0.76  4.1 0.77
## NT5 4978  0.78  0.78  0.78   0.77  4.1 0.81
## KH1 4978  0.73  0.73  0.72   0.72  4.0 0.80
## KH2 4978  0.75  0.74  0.74   0.73  4.0 0.78
## TT1 4978  0.81  0.81  0.81   0.81  4.0 0.75
## TT2 4978  0.79  0.79  0.79   0.78  4.0 0.80
## CH1 4978  0.78  0.78  0.78   0.77  4.0 0.79
## CH2 4978  0.81  0.81  0.81   0.80  4.0 0.79
## CH3 4978  0.75  0.75  0.75   0.74  4.1 0.70
## CH4 4978  0.80  0.80  0.79   0.79  4.0 0.74
## CS1 4978  0.74  0.74  0.74   0.73  4.0 0.76
## CS2 4978  0.75  0.74  0.74   0.73  3.9 0.80
## CS3 4978  0.73  0.72  0.72   0.71  3.8 0.88
## CS4 4978  0.75  0.75  0.75   0.74  3.9 0.78
## CS5 4978  0.74  0.74  0.74   0.73  3.9 0.81
## CS6 4978  0.72  0.71  0.71   0.71  3.8 0.85
## DL1 4978  0.79  0.79  0.79   0.78  4.0 0.78
## DL2 4978  0.79  0.79  0.79   0.78  4.0 0.72
## DL3 4978  0.75  0.75  0.74   0.74  4.0 0.75
## QL1 4978  0.82  0.82  0.82   0.81  4.0 0.74
## QL2 4978  0.81  0.81  0.81   0.80  4.0 0.77
## QL3 4978  0.82  0.82  0.81   0.81  3.9 0.77
## QH1 4978  0.79  0.80  0.79   0.78  4.0 0.71
## QH2 4978  0.78  0.78  0.78   0.77  4.0 0.68
## HT1 4978  0.77  0.77  0.77   0.76  3.9 0.76
## HT2 4978  0.75  0.75  0.75   0.74  4.1 0.73
## DT1 4978  0.80  0.80  0.80   0.79  4.0 0.72
## DT2 4978  0.81  0.81  0.81   0.80  4.0 0.76
## CT1 4978  0.81  0.81  0.81   0.80  4.0 0.75
## CT2 4978  0.77  0.77  0.77   0.76  3.8 0.83
## CT3 4978  0.77  0.78  0.77   0.76  4.0 0.74
## CT4 4978  0.82  0.82  0.82   0.81  4.0 0.71
## CV1 4978  0.73  0.74  0.73   0.72  4.2 0.66
## CV2 4978  0.80  0.80  0.80   0.79  4.0 0.75
## CV3 4978  0.80  0.80  0.80   0.79  4.0 0.76
## DH  4978  0.71  0.72  0.70   0.70  4.3 0.69
## NT  4978  0.86  0.86  0.84   0.86  4.1 0.71
## KH  4978  0.80  0.79  0.78   0.79  4.0 0.73
## TT  4978  0.86  0.86  0.84   0.85  4.0 0.72
## CH  4978  0.90  0.90  0.88   0.89  4.0 0.66
## CS  4978  0.84  0.84  0.82   0.83  3.9 0.71
## DL  4978  0.89  0.89  0.88   0.89  4.0 0.65
## QL  4978  0.88  0.88  0.87   0.88  4.0 0.70
## QH  4978  0.89  0.89  0.88   0.89  4.0 0.65
## HT  4978  0.83  0.83  0.81   0.82  4.0 0.69
## DT  4978  0.86  0.86  0.84   0.85  4.0 0.69
## CT  4978  0.90  0.90  0.89   0.90  4.0 0.67
## CV  4978  0.87  0.87  0.85   0.86  4.1 0.65

3.2 Variance & Standard Deviation - Solution 1

# Variance & Standard Deviation for variable
MEAN <- as.data.frame(sapply(newdata, function(x) mean(as.numeric(x)) ))
VAR <- as.data.frame(sapply(newdata, function(x) var(as.numeric(x)) )) 
SD <- as.data.frame(sapply(newdata, function(x) sd(as.numeric(x)) )) 
# Variance & Standard Deviation for each items
mean <- as.data.frame(sapply(olddata, function(x) mean(as.numeric(x)) ))
var <- as.data.frame(sapply(olddata, function(x) var(as.numeric(x)) )) 
sd <- as.data.frame(sapply(olddata, function(x) sd(as.numeric(x)) )) 

# Export result to excel with row and column name 
library("xlsx")
write.xlsx(MEAN, file = "Trungbinh-NEWDATA.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)
write.xlsx(mean, file = "Trungbinh-OLDDATA.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)
write.xlsx(VAR, file = "PhuongSai-Bien.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)
write.xlsx(SD, file = "Dolechchuan-Bien.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)
write.xlsx(var, file = "PhuongSai-Item.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)
write.xlsx(sd, file = "Dolechchuan-Item.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE) 

3.3 Variance & Standard Deviation - Solution 2

VARIABLE <- as.data.frame(sapply(newdata, function(x) c(mean = mean(x), var = var(x), sd = sd(x))))
ITEM <- as.data.frame(sapply(olddata, function(x) c(mean = mean(x), var = var(x), sd = sd(x))))


write.xlsx(VARIABLE, file = "VARIABLE.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE) 

write.xlsx(ITEM, file = "ITEM.xlsx", sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)