#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
#Cau 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
#nhan xet
#he so Cronbach's Alpha dat 0,93
#he so tuong quan bien tong deu dat tu 0,60 tro len (dat yeu cau)
#=> khong xem xet loai bo bien nào

#cau11
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
#nhan xet
#he so KMO dat 0.67>0.5 (dat yeu cau )
#he so Bartlett's Test dat 0%<5%

#cau12
fitabcde1<-principal(abcde,cor=TRUE,nfactors=19,rorate="none")
fitabcde1
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 19, cor = TRUE, rorate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
##      RC1   RC3   RC4   RC2   RC5  RC10   RC9   RC6  RC11   RC8   RC7  RC13
## A1  0.51  0.10  0.01  0.05 -0.05  0.04 -0.03  0.02  0.01  0.85 -0.04  0.06
## A2  0.96 -0.02  0.04  0.03  0.03  0.07  0.00 -0.05 -0.02  0.09 -0.02  0.03
## A3  0.96 -0.02  0.05  0.02  0.02  0.05 -0.01 -0.05 -0.03  0.09  0.00  0.03
## A4  0.87 -0.08  0.00  0.00 -0.05  0.02 -0.07 -0.01 -0.05  0.13 -0.04 -0.05
## A5  0.95 -0.09  0.03  0.00  0.02  0.02 -0.05  0.11  0.02  0.09 -0.05 -0.01
## B1  0.02 -0.04  0.97  0.02  0.05  0.06 -0.01  0.04  0.03 -0.02 -0.03 -0.01
## B2  0.00  0.02  0.48  0.04  0.05  0.08  0.01  0.86  0.10  0.02 -0.02  0.08
## B3  0.03 -0.09  0.94  0.03  0.09  0.05  0.02  0.25  0.07  0.01 -0.04  0.04
## B4  0.05 -0.06  0.97  0.04  0.01  0.07  0.01  0.08 -0.02  0.02  0.00  0.01
## C1  0.03 -0.02  0.05  0.94  0.13  0.09  0.13  0.07  0.13 -0.03 -0.05  0.12
## C2  0.03  0.00  0.01  0.97  0.07  0.06  0.09 -0.05  0.09  0.05  0.01  0.03
## C3 -0.08  0.06  0.10  0.50  0.09  0.11  0.11  0.12  0.81  0.01  0.03  0.17
## C4  0.03  0.03  0.07  0.58  0.12  0.06  0.16  0.13  0.25  0.09  0.00  0.72
## D1  0.02  0.01  0.11  0.22  0.92  0.25  0.15  0.04  0.07 -0.04 -0.01  0.06
## D2  0.15  0.02  0.17  0.17  0.28  0.89  0.18  0.07  0.08  0.03 -0.01  0.03
## D3 -0.10  0.20  0.02  0.31  0.18  0.19  0.87  0.01  0.09 -0.03  0.11  0.10
## E1 -0.05  0.98 -0.05  0.00  0.00  0.00  0.06  0.02  0.01  0.04  0.09  0.01
## E2 -0.10  0.51 -0.08 -0.05 -0.02 -0.01  0.12 -0.02  0.02 -0.04  0.84  0.00
## E3 -0.01  0.98 -0.06  0.00  0.03  0.02  0.07 -0.01  0.03  0.00  0.11  0.03
## E4 -0.06  0.98 -0.06  0.00 -0.01  0.01  0.04  0.00  0.01  0.05  0.09 -0.01
##     RC12  RC15  RC14  RC17  RC16  RC18  RC19 h2      u2 com
## A1  0.02  0.00  0.00  0.00  0.00  0.00  0.00  1 2.1e-06 1.7
## A2 -0.17 -0.11 -0.03  0.01  0.11  0.00  0.00  1 4.4e-04 1.2
## A3 -0.17 -0.11  0.01  0.00 -0.12 -0.01  0.00  1 1.1e-03 1.2
## A4  0.45  0.01  0.00  0.00  0.00  0.00  0.00  1 3.3e-06 1.6
## A5  0.12  0.23  0.02  0.00  0.00  0.01  0.00  1 1.4e-04 1.2
## B1  0.02  0.01  0.22 -0.01 -0.01 -0.02  0.00  1 1.6e-06 1.1
## B2  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1 1.3e-06 1.6
## B3 -0.02  0.06 -0.09  0.04  0.00  0.14  0.00  1 6.1e-04 1.3
## B4  0.00 -0.06 -0.13 -0.02  0.00 -0.10  0.00  1 4.5e-04 1.1
## C1 -0.06 -0.01 -0.03  0.14  0.01  0.03  0.01  1 4.8e-05 1.3
## C2  0.05  0.01  0.02 -0.12  0.00 -0.03 -0.01  1 5.6e-05 1.1
## C3 -0.01  0.00  0.00  0.00  0.00  0.00  0.00  1 2.1e-06 2.0
## C4 -0.02  0.00  0.00  0.00  0.00  0.00  0.00  1 2.9e-07 2.5
## D1 -0.01  0.00  0.00  0.00  0.00  0.00  0.00  1 2.8e-06 1.4
## D2  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1 9.2e-07 1.6
## D3 -0.01  0.00  0.00  0.00  0.00  0.00  0.00  1 4.9e-07 1.7
## E1  0.01  0.00  0.01 -0.02 -0.07  0.05 -0.05  1 2.1e-03 1.1
## E2 -0.01  0.00  0.00  0.00  0.00  0.00  0.00  1 3.3e-07 1.8
## E3 -0.09 -0.02  0.02  0.03  0.00 -0.01  0.10  1 1.0e-06 1.1
## E4  0.06  0.02 -0.02 -0.01  0.07 -0.05 -0.05  1 2.1e-03 1.1
## 
##                        RC1  RC3  RC4  RC2  RC5 RC10  RC9  RC6 RC11  RC8  RC7
## SS loadings           3.84 3.24 3.07 2.61 1.02 0.94 0.91 0.88 0.78 0.78 0.75
## Proportion Var        0.19 0.16 0.15 0.13 0.05 0.05 0.05 0.04 0.04 0.04 0.04
## Cumulative Var        0.19 0.35 0.51 0.64 0.69 0.74 0.78 0.82 0.86 0.90 0.94
## Proportion Explained  0.19 0.16 0.15 0.13 0.05 0.05 0.05 0.04 0.04 0.04 0.04
## Cumulative Proportion 0.19 0.35 0.51 0.64 0.69 0.74 0.78 0.83 0.86 0.90 0.94
##                       RC13 RC12 RC15 RC14 RC17 RC16 RC18 RC19
## SS loadings           0.60 0.29 0.09 0.07 0.04 0.04 0.04 0.02
## Proportion Var        0.03 0.01 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.01 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.4
## 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
fitabcde2<-principal(abcde,cor=TRUE,nfactors=5,rorate="none")
fitabcde2
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 5, cor = TRUE, rorate = "none")
## 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
fitabcde3<-principal(abcde,cor=TRUE,nfactors=5, rorate="varimax")
fitabcde3
## Principal Components Analysis
## Call: principal(r = abcde, nfactors = 5, cor = TRUE, rorate = "varimax")
## 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
#nhan xet
#so nhan to duoc trich: 5 nhan to 
#gia tri Eigenvalue=1.83>1(dat yeu cau)
#gia tri tong phuong sai trich bang 0.80=80%>50% (dat yeu cau)
#cu truc nhan to co phu hop voi du lieu ban dau vi bien/thang do sap xep theo dung nhom nhan to


#cau13
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
#nhan xet
#bien Ftb co moi tuong quan duong voi Atb,Btb,Ctb,Dtb,Etb vi he so tuong quan Pearson cua cac moi quan he nay >0 
#moi tuong quan giua Ftb va cac bien Atb,Btb,Ctb,Dtb,Etb co y nghia thong ke vi gia tri Sig.(P-Value)cua cac moi quan he nay nho hon 50%