#nhập liệu
likert=file.choose()
datalikert=read.csv(likert,head=TRUE)
save(datalikert,file="datalikert.rda")
attach(datalikert)
is.data.frame(datalikert)
## [1] TRUE
#Câu 10:
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
#Nhận xét:
#Giá trị Cronbach'alpha = 0,93 > 0.6; như vậy nhân tố A đảm bảo độ tin cậy
#Hệ số tương quan biến tổng các biến/thang đo đều >0,3 (Đạt yêu cầu )
#=> nên không loại bất kỳ biến/thang đo nào

#Câu 11:
abcde=data.frame(A1,A2,A3,A4,A5,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] 5048.334
## 
## $p.value
## [1] 0
## 
## $df
## [1] 190
KMO(abcde)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = abcde)
## Overall MSA =  0.67
## MSA for each item = 
##   A1   A2   A3   A4   A5   B1   B2   B3   B4   C1   C2   C3   C4   D1   D2   D3 
## 0.77 0.70 0.61 0.75 0.68 0.78 0.81 0.53 0.56 0.58 0.53 0.86 0.84 0.72 0.74 0.88 
##   E1   E2   E3   E4 
## 0.60 0.82 0.74 0.61
#Nhận xét:
#Giá trị KMO=0.67>0.5 đảm bảo yêu cầu phân tích EFA
#Giá trị Sig. (P-Value) của Barlett's = 0.000<5%
#Do đó kếtquar EFA có thể sử dụng phân tích

#Câu12:
fitabcde1<-principal(abcde,cor=TRUE,nfactors=20,rotate="none")
fitabcde1
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 20, rotate = "none", cor = TRUE)
## Standardized loadings (pattern matrix) based upon correlation matrix
##      PC1   PC2   PC3   PC4   PC5   PC6   PC7   PC8   PC9  PC10  PC11  PC12
## A1  0.45 -0.26  0.51  0.05  0.21 -0.20 -0.25 -0.52  0.11 -0.04  0.16  0.03
## A2  0.64 -0.46  0.53  0.01 -0.06  0.09  0.09  0.07  0.02 -0.08 -0.13 -0.16
## A3  0.63 -0.47  0.53  0.03 -0.05  0.10  0.10  0.07  0.03 -0.10 -0.12 -0.16
## A4  0.56 -0.56  0.46  0.00  0.03  0.03  0.04  0.08 -0.07  0.13  0.10  0.27
## A5  0.65 -0.53  0.44  0.02  0.00 -0.06  0.11  0.16 -0.06  0.02  0.02  0.13
## B1  0.54  0.16 -0.43  0.61  0.06  0.24 -0.07 -0.02  0.08  0.00 -0.05  0.07
## B2  0.45  0.27 -0.27  0.44  0.13 -0.52  0.18  0.13 -0.24  0.03  0.18 -0.09
## B3  0.61  0.19 -0.46  0.59  0.07  0.04  0.01  0.00  0.00 -0.05  0.00  0.02
## B4  0.57  0.15 -0.41  0.61  0.08  0.24 -0.03 -0.08  0.04  0.00 -0.02 -0.03
## C1  0.51  0.59  0.03 -0.50  0.21  0.16 -0.09  0.13 -0.11  0.04  0.11 -0.11
## C2  0.44  0.52  0.09 -0.52  0.27  0.28 -0.13  0.06 -0.07  0.14  0.20 -0.01
## C3  0.38  0.64 -0.02 -0.27  0.23 -0.22  0.15  0.07  0.30  0.15 -0.27  0.22
## C4  0.48  0.57  0.08 -0.35  0.26 -0.17  0.09 -0.09  0.07 -0.26 -0.09 -0.13
## D1  0.40  0.44 -0.01 -0.13 -0.61 -0.08 -0.19  0.19  0.18 -0.29  0.20  0.12
## D2  0.53  0.33  0.08 -0.02 -0.59 -0.13 -0.11 -0.12  0.03  0.39 -0.07 -0.17
## D3  0.17  0.67  0.17 -0.15 -0.32  0.14  0.26 -0.30 -0.36 -0.11 -0.12  0.17
## E1 -0.29  0.49  0.66  0.43  0.08 -0.02 -0.15  0.08 -0.06  0.00 -0.04  0.02
## E2 -0.34  0.40  0.45  0.29 -0.05  0.16  0.50 -0.08  0.25  0.07  0.28 -0.06
## E3 -0.27  0.50  0.68  0.40  0.03  0.00 -0.12  0.10 -0.01 -0.04 -0.10 -0.05
## E4 -0.30  0.48  0.66  0.42  0.08 -0.01 -0.17  0.07 -0.05  0.03 -0.02  0.05
##     PC13  PC14  PC15  PC16  PC17  PC18  PC19  PC20 h2       u2 com
## A1 -0.11  0.01 -0.01  0.00  0.01 -0.01  0.00  0.00  1  3.3e-16 5.2
## A2 -0.10 -0.05  0.03 -0.07  0.06  0.06 -0.01 -0.02  1 -4.4e-16 3.4
## A3 -0.10  0.04  0.05  0.09 -0.06 -0.02  0.02  0.03  1  1.6e-15 3.5
## A4  0.20 -0.06  0.07  0.06  0.05  0.00 -0.02  0.00  1  4.4e-16 4.1
## A5  0.04  0.06 -0.14 -0.07 -0.05 -0.04  0.01 -0.01  1  1.0e-15 3.3
## B1  0.04  0.19  0.04  0.00  0.05  0.01  0.01  0.00  1  3.3e-16 3.8
## B2 -0.08  0.02  0.07 -0.01  0.00  0.00  0.00  0.00  1  1.3e-15 5.8
## B3 -0.02 -0.07 -0.14  0.04 -0.01  0.05 -0.03  0.02  1  4.4e-16 3.3
## B4  0.02 -0.13  0.06 -0.03 -0.05 -0.05  0.01 -0.02  1  7.8e-16 3.5
## C1 -0.07 -0.04 -0.07  0.05  0.09 -0.03  0.04 -0.01  1  3.3e-16 4.1
## C2 -0.04  0.04  0.05 -0.04 -0.07  0.03 -0.04  0.01  1  2.2e-16 5.0
## C3 -0.14 -0.02  0.02  0.00  0.00  0.00  0.00  0.00  1 -2.2e-16 4.7
## C4  0.33  0.01  0.00 -0.01 -0.01  0.00  0.00  0.00  1  7.8e-16 5.1
## D1 -0.05 -0.01  0.02  0.00  0.00  0.00  0.00  0.00  1  3.3e-16 4.6
## D2  0.11  0.01 -0.02  0.00  0.00  0.00  0.00  0.00  1  7.8e-16 4.1
## D3 -0.07  0.01  0.01  0.00  0.00  0.00  0.00  0.00  1  0.0e+00 4.1
## E1  0.02  0.01 -0.01  0.07 -0.05  0.04  0.02 -0.05  1  1.3e-15 3.4
## E2  0.01  0.00 -0.02  0.00  0.01  0.00  0.00  0.00  1  5.6e-16 6.2
## E3 -0.03  0.02 -0.01  0.00  0.04 -0.06 -0.07  0.00  1  1.3e-15 3.2
## E4  0.05 -0.05  0.02 -0.07  0.01  0.01  0.04  0.05  1  7.8e-16 3.5
## 
##                        PC1  PC2  PC3  PC4  PC5  PC6  PC7  PC8  PC9 PC10 PC11
## SS loadings           4.59 4.23 3.45 2.65 1.17 0.71 0.62 0.54 0.43 0.41 0.39
## Proportion Var        0.23 0.21 0.17 0.13 0.06 0.04 0.03 0.03 0.02 0.02 0.02
## Cumulative Var        0.23 0.44 0.61 0.75 0.80 0.84 0.87 0.90 0.92 0.94 0.96
## Proportion Explained  0.23 0.21 0.17 0.13 0.06 0.04 0.03 0.03 0.02 0.02 0.02
## Cumulative Proportion 0.23 0.44 0.61 0.75 0.80 0.84 0.87 0.90 0.92 0.94 0.96
##                       PC12 PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20
## SS loadings           0.31 0.24 0.08 0.07 0.04 0.03 0.02 0.01 0.01
## Proportion Var        0.02 0.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00
## Cumulative Var        0.98 0.99 0.99 0.99 1.00 1.00 1.00 1.00 1.00
## Proportion Explained  0.02 0.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00
## Cumulative Proportion 0.98 0.99 0.99 0.99 1.00 1.00 1.00 1.00 1.00
## 
## Mean item complexity =  4.2
## Test of the hypothesis that 20 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
fitabcde2<-principal(abcde,cor=TRUE,nfactors=5,rotate="varimax")
fitabcde2
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 5, rotate = "varimax", cor = TRUE)
## Standardized loadings (pattern matrix) based upon correlation matrix
##      RC1   RC3   RC4   RC2   RC5   h2    u2 com
## A1  0.72  0.12  0.03  0.13 -0.12 0.57 0.430 1.2
## A2  0.94 -0.05  0.02  0.00  0.12 0.90 0.099 1.0
## A3  0.94 -0.04  0.02 -0.02  0.10 0.90 0.103 1.0
## A4  0.90 -0.12 -0.01 -0.06 -0.03 0.83 0.169 1.0
## A5  0.94 -0.14  0.06 -0.02  0.04 0.90 0.095 1.1
## B1  0.02 -0.07  0.93  0.01  0.08 0.88 0.121 1.0
## B2  0.00  0.03  0.73  0.16  0.05 0.56 0.437 1.1
## B3  0.03 -0.11  0.97  0.06  0.10 0.96 0.036 1.1
## B4  0.06 -0.08  0.94  0.02  0.08 0.90 0.099 1.0
## C1  0.03 -0.06  0.04  0.92  0.21 0.89 0.110 1.1
## C2  0.06 -0.04 -0.04  0.90  0.12 0.82 0.176 1.1
## C3 -0.09  0.07  0.16  0.78  0.14 0.68 0.323 1.2
## C4  0.05  0.04  0.11  0.84  0.14 0.75 0.251 1.1
## D1 -0.01 -0.02  0.11  0.24  0.82 0.74 0.256 1.2
## D2  0.18  0.01  0.21  0.19  0.80 0.76 0.245 1.4
## D3 -0.15  0.29 -0.01  0.43  0.58 0.63 0.368 2.6
## E1 -0.01  0.98 -0.02  0.03  0.00 0.95 0.047 1.0
## E2 -0.14  0.73 -0.09 -0.04  0.07 0.56 0.440 1.1
## E3  0.01  0.97 -0.04  0.04  0.05 0.95 0.048 1.0
## E4 -0.02  0.97 -0.04  0.03 -0.01 0.94 0.055 1.0
## 
##                        RC1  RC3  RC4  RC2  RC5
## SS loadings           4.08 3.54 3.34 3.30 1.83
## Proportion Var        0.20 0.18 0.17 0.17 0.09
## Cumulative Var        0.20 0.38 0.55 0.71 0.80
## Proportion Explained  0.25 0.22 0.21 0.21 0.11
## Cumulative Proportion 0.25 0.47 0.68 0.89 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  71.75  with prob <  0.99 
## 
## Fit based upon off diagonal values = 0.99
#Nhận xét:
#Số nhân tố được trích: 5 nhóm nhân tố
#Giá trị Eigenvalue=1.83>1 (Đạt yêu cầu)
#Giá trị Tổng phương sai trích = 0.80 = 80% > 50% (Đạt yêu cầu)

#Câu 13:
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
#Nhận xét:
#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>0
#Mối tương quan giữa Ftb và các biến Atb, Btb, Ctb,Dtb,Etb có ý nghĩa thống kê vì giá trị Sig. (P-Value)có mối quan hệ này nhỏ hơn 5%