# NHẬP LIỆU
likert=file.choose()
datalikert=read.csv(likert,header=TRUE)
save(datalikert,file = "datalikert.rda")
attach(datalikert)
is.data.frame(datalikert)
## [1] TRUE
#câu 10

## Hệ số Cronbach's alpha của thang đo A là 0.93. Được coi là rất tốt có độ tin cậy cao 
## Hệ số tương quan biến tổng lớn hơn 0,3 
## Không loại b# Câu 10
## Cronbach's alpha
library(psych)
fa=data.frame(A1,A2,A3,A4,A5)
alpha(fa)
## 
## Reliability analysis   
## Call: alpha(x = fa)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.93      0.94    0.95      0.74  14 0.0083  4.1 0.72     0.78
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.91  0.93  0.95
## Duhachek  0.92  0.93  0.95
## 
##  Reliability if an item is dropped:
##    raw_alpha std.alpha G6(smc) average_r  S/N alpha se  var.r med.r
## A1      0.96      0.96    0.97      0.86 25.2   0.0049 0.0057  0.87
## A2      0.90      0.91    0.91      0.71  9.7   0.0125 0.0270  0.67
## A3      0.90      0.91    0.91      0.71  9.7   0.0125 0.0270  0.67
## A4      0.91      0.92    0.92      0.73 11.1   0.0111 0.0361  0.72
## A5      0.90      0.91    0.91      0.70  9.5   0.0121 0.0277  0.67
## 
##  Item statistics 
##      n raw.r std.r r.cor r.drop mean   sd
## A1 198  0.74  0.73  0.60   0.60  4.1 0.89
## A2 198  0.94  0.94  0.95   0.90  4.0 0.83
## A3 198  0.94  0.94  0.95   0.90  4.0 0.83
## A4 198  0.89  0.90  0.89   0.84  4.1 0.74
## A5 198  0.94  0.94  0.95   0.90  4.0 0.73
## 
## Non missing response frequency for each item
##       2    3    4    5 miss
## A1 0.00 0.33 0.20 0.47    0
## A2 0.02 0.30 0.35 0.33    0
## A3 0.02 0.30 0.35 0.33    0
## A4 0.01 0.21 0.45 0.33    0
## A5 0.01 0.24 0.48 0.28    0
#Câu 11
##Phân tích EFA cho nhóm từ A1 đến E4, kiểm tra KMO và Bartlett's Test
abcde=data.frame(A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4,D1,D2,D3,E1,E2,E3,E4)
library(psych)
cortest.bartlett(abcde)
## R was not square, finding R from data
## $chisq
## [1] 4503.252
## 
## $p.value
## [1] 0
## 
## $df
## [1] 171
KMO(abcde)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = abcde)
## Overall MSA =  0.67
## MSA for each item = 
##   A1   A2   A3   A4   B1   B2   B3   B4   C1   C2   C3   C4   D1   D2   D3   E1 
## 0.76 0.59 0.54 0.71 0.75 0.74 0.59 0.64 0.60 0.55 0.84 0.84 0.71 0.73 0.88 0.63 
##   E2   E3   E4 
## 0.81 0.71 0.60
# KMO 0,67 lớn hơn 0,5 điều kiện đủ để phân tích nhân tố thích hợp
#p.value là 0 bé hơn 0,05 cho thấy các biến có tương quan với nhau và dữ liệu là phù hợp 
# Câu 12
## Phân tích EFA cho nhóm A1 đến E4, xác định các nhân tố, Eigenvalue, tổng phương sai trích
principal(abcde,cor=TRUE,nfactors=19,rorate="none")
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 19, cor = TRUE, rorate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      RC2   RC4   RC3   RC1   RC5  RC10   RC9   RC6   RC8  RC11   RC7  RC13
## A1  0.09  0.01  0.48  0.05 -0.04  0.04 -0.03  0.02  0.86  0.01 -0.04  0.06
## A2 -0.03  0.04  0.98  0.03  0.03  0.07 -0.01 -0.01  0.11 -0.02 -0.03  0.02
## A3 -0.03  0.05  0.98  0.01  0.02  0.05 -0.02 -0.01  0.11 -0.02 -0.01  0.02
## A4 -0.09  0.00  0.80  0.00 -0.04  0.03 -0.08  0.01  0.18 -0.05 -0.05 -0.05
## B1 -0.04  0.97  0.02  0.02  0.05  0.06 -0.01  0.05 -0.02  0.03 -0.03 -0.01
## B2  0.02  0.48 -0.03  0.04  0.05  0.08  0.01  0.86  0.02  0.10 -0.02  0.08
## B3 -0.09  0.94  0.02  0.03  0.09  0.05  0.02  0.25  0.01  0.07 -0.04  0.04
## B4 -0.06  0.97  0.06  0.04  0.01  0.07  0.01  0.08  0.02 -0.01  0.00  0.01
## C1 -0.02  0.05  0.04  0.94  0.14  0.09  0.13  0.07 -0.03  0.14 -0.05  0.12
## C2  0.00  0.01  0.02  0.97  0.07  0.06  0.09 -0.05  0.05  0.10  0.00  0.04
## C3  0.06  0.10 -0.09  0.49  0.09  0.11  0.11  0.12  0.01  0.81  0.03  0.17
## C4  0.03  0.06  0.03  0.57  0.12  0.06  0.16  0.13  0.09  0.25  0.00  0.73
## D1  0.01  0.11  0.02  0.22  0.92  0.25  0.15  0.04 -0.04  0.07 -0.01  0.06
## D2  0.02  0.17  0.15  0.17  0.28  0.89  0.18  0.08  0.04  0.09 -0.01  0.03
## D3  0.20  0.02 -0.08  0.30  0.18  0.19  0.87  0.01 -0.04  0.09  0.11  0.10
## E1  0.98 -0.05 -0.04  0.00  0.00  0.00  0.06  0.02  0.04  0.01  0.10  0.01
## E2  0.51 -0.08 -0.08 -0.05 -0.02 -0.01  0.12 -0.02 -0.05  0.02  0.84  0.00
## E3  0.98 -0.06  0.01  0.00  0.03  0.02  0.07 -0.01  0.00  0.03  0.12  0.02
## E4  0.98 -0.06 -0.06  0.00 -0.01  0.01  0.04  0.00  0.05  0.01  0.10  0.00
##     RC12  RC14  RC15  RC17  RC16  RC18  RC19 h2       u2 com
## A1  0.05  0.00  0.00  0.00  0.00  0.00  0.00  1  0.0e+00 1.6
## A2 -0.06 -0.02  0.00  0.01  0.12  0.00 -0.01  1 -2.7e-15 1.1
## A3 -0.06  0.02  0.00 -0.01 -0.12  0.00  0.01  1 -4.4e-16 1.1
## A4  0.55  0.00  0.00  0.00  0.00  0.00  0.00  1 -4.4e-16 2.0
## B1  0.02  0.21 -0.04 -0.01 -0.01  0.00  0.00  1  1.3e-15 1.1
## B2  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1 -2.2e-16 1.6
## B3 -0.01 -0.07  0.17  0.03  0.00  0.00  0.01  1  2.0e-15 1.3
## B4 -0.01 -0.14 -0.10 -0.01  0.00  0.00 -0.01  1  1.9e-15 1.1
## C1 -0.05 -0.02  0.04  0.13  0.01  0.01  0.00  1  8.9e-16 1.3
## C2  0.05  0.02 -0.04 -0.12 -0.01 -0.01  0.00  1  7.8e-16 1.1
## C3 -0.02  0.00  0.00  0.00  0.00  0.00  0.00  1  1.1e-16 2.0
## C4 -0.02  0.00  0.00  0.00  0.00  0.00  0.00  1  0.0e+00 2.5
## D1 -0.01  0.00  0.00  0.00  0.00  0.00  0.00  1 -8.9e-16 1.4
## D2  0.01  0.00  0.00  0.00  0.00  0.00  0.00  1  0.0e+00 1.6
## D3 -0.02  0.00  0.00  0.00  0.00  0.00  0.00  1 -6.7e-16 1.7
## E1  0.00  0.01  0.03 -0.01 -0.05 -0.06  0.08  1 -6.7e-16 1.1
## E2 -0.02  0.00  0.00  0.00  0.00  0.00  0.00  1 -8.9e-16 1.8
## E3 -0.09  0.02  0.00  0.02  0.00  0.10  0.01  1 -4.4e-16 1.1
## E4  0.06 -0.02 -0.03 -0.01  0.05 -0.04 -0.08  1 -4.4e-16 1.1
## 
##                        RC2  RC4  RC3  RC1  RC5 RC10  RC9  RC6  RC8 RC11  RC7
## SS loadings           3.23 3.07 2.85 2.58 1.02 0.95 0.91 0.86 0.82 0.79 0.76
## Proportion Var        0.17 0.16 0.15 0.14 0.05 0.05 0.05 0.05 0.04 0.04 0.04
## Cumulative Var        0.17 0.33 0.48 0.62 0.67 0.72 0.77 0.81 0.86 0.90 0.94
## Proportion Explained  0.17 0.16 0.15 0.14 0.05 0.05 0.05 0.05 0.04 0.04 0.04
## Cumulative Proportion 0.17 0.33 0.48 0.62 0.67 0.72 0.77 0.81 0.86 0.90 0.94
##                       RC13 RC12 RC14 RC15 RC17 RC16 RC18 RC19
## SS loadings           0.61 0.33 0.07 0.04 0.04 0.03 0.02 0.01
## Proportion Var        0.03 0.02 0.00 0.00 0.00 0.00 0.00 0.00
## Cumulative Var        0.97 0.99 0.99 0.99 1.00 1.00 1.00 1.00
## Proportion Explained  0.03 0.02 0.00 0.00 0.00 0.00 0.00 0.00
## Cumulative Proportion 0.97 0.99 0.99 0.99 1.00 1.00 1.00 1.00
## 
## Mean item complexity =  1.5
## Test of the hypothesis that 19 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0 
##  with the empirical chi square  0  with prob <  NA 
## 
## Fit based upon off diagonal values = 1
principal(abcde,cor=TRUE,nfactors=5,rorate="varimax")
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 5, cor = TRUE, rorate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      RC2   RC4   RC1   RC3   RC5   h2    u2 com
## A1  0.11  0.04  0.12  0.76 -0.12 0.61 0.386 1.2
## A2 -0.06  0.02 -0.01  0.94  0.12 0.90 0.096 1.0
## A3 -0.06  0.03 -0.02  0.94  0.11 0.90 0.100 1.0
## A4 -0.13 -0.01 -0.06  0.88 -0.02 0.80 0.203 1.1
## B1 -0.07  0.93  0.01  0.02  0.09 0.88 0.121 1.0
## B2  0.03  0.73  0.16 -0.02  0.05 0.56 0.436 1.1
## B3 -0.11  0.97  0.06  0.02  0.10 0.96 0.037 1.1
## B4 -0.08  0.94  0.01  0.07  0.08 0.90 0.097 1.0
## C1 -0.06  0.04  0.92  0.04  0.21 0.89 0.110 1.1
## C2 -0.04 -0.04  0.90  0.07  0.12 0.82 0.176 1.1
## C3  0.08  0.16  0.78 -0.10  0.14 0.68 0.320 1.2
## C4  0.04  0.11  0.84  0.06  0.14 0.75 0.251 1.1
## D1 -0.02  0.11  0.24 -0.02  0.82 0.74 0.256 1.2
## D2  0.01  0.21  0.18  0.18  0.81 0.76 0.241 1.4
## D3  0.29 -0.01  0.43 -0.15  0.58 0.63 0.367 2.6
## E1  0.98 -0.02  0.03  0.00  0.00 0.95 0.047 1.0
## E2  0.73 -0.10 -0.04 -0.13  0.07 0.56 0.438 1.1
## E3  0.97 -0.04  0.04  0.02  0.05 0.95 0.048 1.0
## E4  0.97 -0.04  0.03  0.00 -0.01 0.95 0.055 1.0
## 
##                        RC2  RC4  RC1  RC3  RC5
## SS loadings           3.53 3.33 3.30 3.21 1.84
## Proportion Var        0.19 0.18 0.17 0.17 0.10
## Cumulative Var        0.19 0.36 0.53 0.70 0.80
## Proportion Explained  0.23 0.22 0.22 0.21 0.12
## Cumulative Proportion 0.23 0.45 0.67 0.88 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 5 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.03 
##  with the empirical chi square  68.74  with prob <  0.91 
## 
## Fit based upon off diagonal values = 0.99
# Số nhân tố được trích 5 nhóm nhân tố 
# Gía trị Eigenvalue = 1.83 > 1 ( đạt yêu cầu)
# Gía trị tổng phương sai trích = 0.80 = 80% > 50% (đạt yêu cầu)
# Cấu trúc nhân tố có phù hợp với dữ liệu ban đầu vì các biến/thang đo sắp xếp theo đúng nhóm nhân tố
# Câu 13
## Phân tích tương quan Pearson 
library(psych)
vars=cbind(Atb,Btb,Ctb,Dtb,Etb,Ftb)
pairs.panels(vars)

library(Hmisc)
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:base':
## 
##     format.pval, units
result=rcorr(as.matrix(vars),type="pearson")
result$r
##             Atb         Btb        Ctb        Dtb         Etb       Ftb
## Atb  1.00000000  0.06221638 0.03185639 0.04014488 -0.08600054 0.2222299
## Btb  0.06221638  1.00000000 0.16097635 0.22801725 -0.10776531 0.2511952
## Ctb  0.03185639  0.16097635 1.00000000 0.50335736  0.02399959 0.5915879
## Dtb  0.04014488  0.22801725 0.50335736 1.00000000  0.13044247 0.5733869
## Etb -0.08600054 -0.10776531 0.02399959 0.13044247  1.00000000 0.2096923
## Ftb  0.22222985  0.25119517 0.59158791 0.57338686  0.20969230 1.0000000
result$P
##             Atb          Btb          Ctb          Dtb         Etb          Ftb
## Atb          NA 0.3838835582 6.559338e-01 5.744306e-01 0.228316785 0.0016512737
## Btb 0.383883558           NA 2.347636e-02 1.234270e-03 0.130738634 0.0003574484
## Ctb 0.655933822 0.0234763641           NA 4.085621e-14 0.737161764 0.0000000000
## Dtb 0.574430580 0.0012342702 4.085621e-14           NA 0.066996016 0.0000000000
## Etb 0.228316785 0.1307386340 7.371618e-01 6.699602e-02          NA 0.0030269715
## Ftb 0.001651274 0.0003574484 0.000000e+00 0.000000e+00 0.003026971           NA
# biến Ftb có mối tương quan dương với Atb,Btb,Ctb,Dtb,Etb vì hệ số tương quan Pearson của các mối quan hệ này lớn hơn 0
# Mối tương quan giữa Ftb và các biến Atb,Btb,Ctb,Dtb,Etb vì có ý nghĩa thống kê vì giá trị Sig.(P-value)của các mối quan hệ này lớn hơn 5%