library(readr)
data2<- read_csv("~/SA projects 2019/Kudzanai Mutendadzamera/confirmatory.csv")
## Parsed with column specification:
## cols(
## .default = col_double()
## )
## See spec(...) for full column specifications.
View(data2)
attach(data2)
names(data2)
## [1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "B11"
## [12] "B12" "B13" "B14" "C15" "C16" "C17" "C18" "C19" "C20" "C21" "C22"
## [23] "C23" "C24" "C25"
library(sem)
library(lavaan)
## This is lavaan 0.6-3
## lavaan is BETA software! Please report any bugs.
##
## Attaching package: 'lavaan'
## The following objects are masked from 'package:sem':
##
## cfa, sem
library(semPlot)
library(foreign)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
The confirmatory factor model treats organizational Innovation as a latent variable which can be measured on the basis of test scores in four areas (& point likert scale. Thus, only the first four variables in the file are needed. The data can be subset as follows:
HS.model <- ' Political_capital=~ A1+A2+A3+A4
Alliance_Ties=~A5+A6+A7+A8
Reputational_Capital=~A9+A10
Organizational_innovation=~B11+B12+B13+B14
Hostility=~C15+C16+C17+C18+C19+C20
Dynamism=~C21+C22+C23+C24+C25'
This creates a new object, dataCov, which is the covariance matrix of the subsetted data file.
fit <- cfa(HS.model, data=data2)
summary(fit, fit.measures=TRUE)
## lavaan 0.6-3 ended normally after 59 iterations
##
## Optimization method NLMINB
## Number of free parameters 65
##
## Number of observations 104
##
## Estimator ML
## Model Fit Test Statistic 573.897
## Degrees of freedom 260
## P-value (Chi-square) 0.000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 2171.979
## Degrees of freedom 300
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.832
## Tucker-Lewis Index (TLI) 0.807
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -4203.338
## Loglikelihood unrestricted model (H1) -3916.389
##
## Number of free parameters 65
## Akaike (AIC) 8536.675
## Bayesian (BIC) 8708.561
## Sample-size adjusted Bayesian (BIC) 8503.225
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.108
## 90 Percent Confidence Interval 0.096 0.120
## P-value RMSEA <= 0.05 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.121
##
## Parameter Estimates:
##
## Information Expected
## Information saturated (h1) model Structured
## Standard Errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## Political_capital =~
## A1 1.000
## A2 0.927 0.126 7.345 0.000
## A3 0.923 0.113 8.148 0.000
## A4 0.704 0.130 5.438 0.000
## Alliance_Ties =~
## A5 1.000
## A6 1.428 0.220 6.495 0.000
## A7 1.898 0.265 7.157 0.000
## A8 1.750 0.251 6.982 0.000
## Reputational_Capital =~
## A9 1.000
## A10 1.080 0.074 14.686 0.000
## Organizational_innovation =~
## B11 1.000
## B12 0.969 0.082 11.789 0.000
## B13 0.732 0.088 8.328 0.000
## B14 0.875 0.083 10.530 0.000
## Hostility =~
## C15 1.000
## C16 1.077 0.096 11.267 0.000
## C17 1.217 0.102 11.947 0.000
## C18 0.890 0.093 9.586 0.000
## C19 0.948 0.094 10.084 0.000
## C20 0.833 0.091 9.105 0.000
## Dynamism =~
## C21 1.000
## C22 0.811 0.231 3.515 0.000
## C23 1.175 0.266 4.416 0.000
## C24 1.223 0.273 4.473 0.000
## C25 0.530 0.243 2.181 0.029
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## Political_capital ~~
## Alliance_Ties -0.191 0.137 -1.392 0.164
## Reputatnl_Cptl 0.075 0.231 0.326 0.745
## Orgnztnl_nnvtn -0.382 0.222 -1.722 0.085
## Hostility -0.455 0.224 -2.033 0.042
## Dynamism -0.132 0.108 -1.228 0.219
## Alliance_Ties ~~
## Reputatnl_Cptl 1.504 0.310 4.852 0.000
## Orgnztnl_nnvtn 1.190 0.264 4.508 0.000
## Hostility 1.157 0.261 4.440 0.000
## Dynamism -0.059 0.082 -0.725 0.469
## Reputational_Capital ~~
## Orgnztnl_nnvtn 2.023 0.377 5.371 0.000
## Hostility 2.091 0.384 5.446 0.000
## Dynamism -0.034 0.140 -0.245 0.806
## Organizational_innovation ~~
## Hostility 1.821 0.354 5.145 0.000
## Dynamism 0.110 0.133 0.826 0.409
## Hostility ~~
## Dynamism -0.014 0.131 -0.107 0.914
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .A1 0.649 0.156 4.159 0.000
## .A2 1.217 0.208 5.841 0.000
## .A3 0.710 0.148 4.787 0.000
## .A4 1.727 0.259 6.672 0.000
## .A5 1.697 0.244 6.963 0.000
## .A6 1.137 0.177 6.440 0.000
## .A7 0.524 0.126 4.165 0.000
## .A8 0.761 0.141 5.407 0.000
## .A9 0.695 0.137 5.071 0.000
## .A10 0.550 0.137 4.019 0.000
## .B11 0.851 0.162 5.242 0.000
## .B12 0.671 0.138 4.871 0.000
## .B13 1.347 0.205 6.563 0.000
## .B14 0.913 0.157 5.820 0.000
## .C15 0.953 0.162 5.897 0.000
## .C16 1.118 0.189 5.913 0.000
## .C17 1.095 0.199 5.514 0.000
## .C18 1.368 0.211 6.492 0.000
## .C19 1.313 0.206 6.360 0.000
## .C20 1.405 0.213 6.598 0.000
## .C21 1.266 0.200 6.337 0.000
## .C22 1.164 0.177 6.597 0.000
## .C23 0.734 0.150 4.905 0.000
## .C24 0.447 0.130 3.435 0.001
## .C25 1.937 0.274 7.058 0.000
## Political_cptl 1.484 0.309 4.799 0.000
## Alliance_Ties 0.975 0.293 3.326 0.001
## Reputatnl_Cptl 2.890 0.497 5.812 0.000
## Orgnztnl_nnvtn 2.522 0.466 5.410 0.000
## Hostility 2.580 0.481 5.366 0.000
## Dynamism 0.492 0.194 2.535 0.011
The output consists of three parts. The first six lines are called the header. The header contains the following information: the lavaan version number did lavaan converge normally or not, and how many iterations were needed the number of observations that were effectively used in the analysis the estimator that was used to obtain the parameter values (here: ML) the model test statistic, the degrees of freedom, and a corresponding p-value The next section contains additional fit measures, and is only shown because we use the optional argument fit.measures = TRUE. It starts with the line Model test baseline model and ends with the value for the SRMR. The last section contains the parameter estimates. It starts with information about the standard errors (if the information matrix is expected or observed, and if the standard errors are standard, robust, or based on the bootstrap). Then, it tabulates all free (and fixed) parameters that were included in the model. Typically, first the latent variables are shown, followed by covariances and (residual) variances. The first column (Estimate) contains the (estimated or fixed) parameter value for each model parameter; the second column (Std.err) contains the standard error for each estimated parameter; the third column (Z-value) contains the Wald statistic (which is simply obtained by dividing the parameter value by its standard error), and the last column (P(>|z|)) contains the p-value for testing the null hypothesis that the parameter equals zero in the population.
library(factoextra)
## Loading required package: ggplot2
## Welcome! Related Books: `Practical Guide To Cluster Analysis in R` at https://goo.gl/13EFCZ
library(FactoMineR)
library(ggplot2)
Explanatory factor analysis
##screen plot , determining the number of factors or components in form of dimensions to be considered
res.pca <- prcomp(data2, scale = TRUE)
fviz_eig(res.pca)
fviz_pca_var(res.pca,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
fviz_pca_ind(res.pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
eig.val <- get_eigenvalue(res.pca)
eig.val
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 9.83255524 39.3302210 39.33022
## Dim.2 2.95550693 11.8220277 51.15225
## Dim.3 2.37705521 9.5082209 60.66047
## Dim.4 1.43799197 5.7519679 66.41244
## Dim.5 1.17817415 4.7126966 71.12513
## Dim.6 0.96788693 3.8715477 74.99668
## Dim.7 0.80312217 3.2124887 78.20917
## Dim.8 0.71140649 2.8456259 81.05480
## Dim.9 0.67103313 2.6841325 83.73893
## Dim.10 0.55388077 2.2155231 85.95445
## Dim.11 0.44812451 1.7924980 87.74695
## Dim.12 0.43138763 1.7255505 89.47250
## Dim.13 0.37624383 1.5049753 90.97748
## Dim.14 0.32888640 1.3155456 92.29302
## Dim.15 0.30346792 1.2138717 93.50689
## Dim.16 0.25582489 1.0232996 94.53019
## Dim.17 0.24988692 0.9995477 95.52974
## Dim.18 0.21147585 0.8459034 96.37564
## Dim.19 0.18830281 0.7532112 97.12885
## Dim.20 0.18149974 0.7259989 97.85485
## Dim.21 0.16466098 0.6586439 98.51350
## Dim.22 0.13402971 0.5361188 99.04962
## Dim.23 0.09692849 0.3877140 99.43733
## Dim.24 0.07420646 0.2968258 99.73416
## Dim.25 0.06646088 0.2658435 100.00000
library(nFactors)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: psych
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## The following object is masked from 'package:lavaan':
##
## cor2cov
## Loading required package: boot
##
## Attaching package: 'boot'
## The following object is masked from 'package:psych':
##
## logit
## Loading required package: lattice
##
## Attaching package: 'lattice'
## The following object is masked from 'package:boot':
##
## melanoma
##
## Attaching package: 'nFactors'
## The following object is masked from 'package:lattice':
##
## parallel
library(psych)
Non graphical solution to screen test
ev<-eigen(cor(data2))
ap<-parallel(subject=nrow(data2),var=ncol(data2),rep=100,cent=.05)
nS<-nScree(x=ev$values,parallel=ap$eigen$qevpea)
plotnScree(nS)
fac<-factanal(data2,5,rotation="varimax")
print(fac,digits = 2,cutoff=.3,sort=TRUE)
##
## Call:
## factanal(x = data2, factors = 5, rotation = "varimax")
##
## Uniquenesses:
## A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 B11 B12 B13 B14 C15
## 0.35 0.30 0.29 0.64 0.58 0.35 0.11 0.19 0.26 0.20 0.24 0.20 0.48 0.27 0.25
## C16 C17 C18 C19 C20 C21 C22 C23 C24 C25
## 0.21 0.19 0.40 0.30 0.38 0.72 0.67 0.54 0.34 0.68
##
## Loadings:
## Factor1 Factor2 Factor3 Factor4 Factor5
## C15 0.69 0.47
## C16 0.83
## C17 0.80 0.34
## C18 0.67 0.31
## C19 0.69
## C20 0.68 0.37
## A5 0.51
## A6 0.65 0.41
## A7 0.31 0.83
## A8 0.38 0.79
## A9 0.43 0.65 0.35
## A10 0.47 0.69
## B11 0.32 0.40 0.70
## B12 0.42 0.31 0.72
## B13 0.30 0.59
## B14 0.42 0.70
## A1 0.80
## A2 0.78
## A3 0.78
## A4 0.56
## C22 0.52
## C23 0.67
## C24 0.80
## C21 0.49
## C25 -0.45
##
## Factor1 Factor2 Factor3 Factor4 Factor5
## SS loadings 4.64 4.10 2.85 2.47 1.82
## Proportion Var 0.19 0.16 0.11 0.10 0.07
## Cumulative Var 0.19 0.35 0.46 0.56 0.63
##
## Test of the hypothesis that 5 factors are sufficient.
## The chi square statistic is 331.87 on 185 degrees of freedom.
## The p-value is 1.95e-10
fa<-factanal(~.,8,data=data2)
varimax(loadings(fa),normalize = FALSE)
## $loadings
##
## Loadings:
## Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 Factor7 Factor8
## A1 -0.104 0.810 0.116
## A2 0.221 0.113 0.773 -0.182
## A3 -0.199 -0.189 -0.160 0.799
## A4 -0.130 0.149 0.563 -0.248
## A5 0.204 0.531 0.166 0.113 0.128 -0.127 0.481
## A6 0.201 0.681 0.338 0.394
## A7 0.269 0.830 0.270 -0.141
## A8 0.339 0.825 0.141 -0.187
## A9 0.353 0.777 0.232 0.379
## A10 0.399 0.754 0.254 0.168 -0.117
## B11 0.317 0.457 0.573 0.202 0.169 0.259
## B12 0.411 0.369 0.611 -0.121 0.218 0.218
## B13 0.305 0.245 0.691
## B14 0.159 0.407 0.822 0.134
## C15 0.674 0.494 0.223 -0.119 -0.148 0.120
## C16 0.799 0.344 -0.177 0.121
## C17 0.776 0.388 0.124 -0.150
## C18 0.708 0.270 0.255 0.291
## C19 0.714 0.292 0.219 -0.224 -0.161 0.188 -0.131
## C20 0.679 0.220 0.269 0.142 0.130 0.127
## C21 0.154 0.514 0.472
## C22 0.165 0.177 0.551 0.121
## C23 -0.120 0.665 0.151
## C24 0.109 -0.139 0.785
## C25 -0.412 -0.248 -0.135 0.210 0.262
##
## Factor1 Factor2 Factor3 Factor4 Factor5 Factor6 Factor7
## SS loadings 4.356 4.797 2.564 2.454 1.806 0.441 0.588
## Proportion Var 0.174 0.192 0.103 0.098 0.072 0.018 0.024
## Cumulative Var 0.174 0.366 0.469 0.567 0.639 0.657 0.680
## Factor8
## SS loadings 0.652
## Proportion Var 0.026
## Cumulative Var 0.706
##
## $rotmat
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.990333547 0.13102964 -0.004612867 0.029315323 0.005593269
## [2,] -0.095951881 0.85554167 0.015159347 -0.042779986 -0.013189571
## [3,] -0.005373355 0.04800376 0.991473475 -0.012229271 -0.007220363
## [4,] -0.032715059 0.02898973 0.012027762 0.996859351 -0.002886528
## [5,] 0.001088083 -0.02599790 0.020270983 0.005592508 0.992863118
## [6,] -0.079525701 0.43422898 -0.089173874 0.036084265 0.030076442
## [7,] 0.002867021 0.05130078 0.006278843 -0.008316862 -0.036373454
## [8,] 0.050988357 -0.23637354 0.090455958 0.045053784 -0.108302782
## [,6] [,7] [,8]
## [1,] 0.0025692114 -0.013834210 -0.03099616
## [2,] -0.1452344494 0.019976295 0.48488730
## [3,] -0.0005012001 -0.027231484 -0.11706246
## [4,] -0.0638549527 0.004315973 0.01056757
## [5,] 0.0518429583 0.054587931 0.08623242
## [6,] 0.6848670801 -0.063400709 -0.56736200
## [7,] -0.0637312359 0.984333115 -0.15150920
## [8,] 0.7064208148 0.150791935 0.63072779
fa<-factanal(~.,5,data=data2)
varimax(loadings(fa),normalize = FALSE)
## $loadings
##
## Loadings:
## Factor1 Factor2 Factor3 Factor4 Factor5
## A1 0.799
## A2 0.207 0.783 -0.187
## A3 -0.196 -0.190 -0.167 0.783
## A4 -0.136 0.174 0.552
## A5 0.226 0.537 0.199 0.143 0.137
## A6 0.211 0.681 0.380
## A7 0.260 0.861 0.243 -0.135
## A8 0.337 0.821 0.133
## A9 0.388 0.691 0.316
## A10 0.421 0.729 0.231 0.180
## B11 0.296 0.453 0.680
## B12 0.399 0.368 0.700 -0.103
## B13 0.287 0.291 0.580 0.117
## B14 0.156 0.458 0.682 0.170
## C15 0.663 0.520 0.202
## C16 0.813 0.334 0.122
## C17 0.789 0.388 0.114 -0.149
## C18 0.662 0.260 0.301
## C19 0.687 0.283 0.247 -0.240 -0.160
## C20 0.670 0.185 0.363
## C21 0.211 0.476
## C22 0.131 0.182 0.529
## C23 -0.107 0.664
## C24 -0.138 0.801
## C25 -0.422 -0.272 -0.148 0.209
##
## Factor1 Factor2 Factor3 Factor4 Factor5
## SS loadings 4.285 4.749 2.613 2.437 1.788
## Proportion Var 0.171 0.190 0.105 0.097 0.072
## Cumulative Var 0.171 0.361 0.466 0.563 0.635
##
## $rotmat
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.997321870 0.05891457 0.0008258695 0.04040540 -0.01564872
## [2,] -0.057460466 0.99640826 -0.0526535328 -0.02513361 0.02155892
## [3,] -0.004536193 0.05334614 0.9974834132 -0.00413534 -0.04629634
## [4,] -0.041539696 0.02262117 0.0035172884 0.99873481 0.01670786
## [5,] 0.017356830 -0.01849676 0.0473433461 -0.01572868 0.99843269
fa<-factanal(~.,5,data=data2)
varimax(loadings(fa),normalize =TRUE)
## $loadings
##
## Loadings:
## Factor1 Factor2 Factor3 Factor4 Factor5
## A1 -0.101 0.798
## A2 0.175 0.111 0.782 -0.197
## A3 -0.175 -0.188 -0.180 0.785
## A4 -0.104 0.169 0.562
## A5 0.261 0.511 0.220 0.149 0.138
## A6 0.251 0.646 0.416
## A7 0.306 0.832 0.292 -0.126
## A8 0.385 0.791 0.179
## A9 0.432 0.646 0.354
## A10 0.470 0.686 0.265 0.181
## B11 0.320 0.399 0.700
## B12 0.416 0.307 0.719 -0.109
## B13 0.302 0.244 0.588 0.144
## B14 0.179 0.415 0.697 0.197
## C15 0.691 0.469 0.226
## C16 0.831 0.280 0.134
## C17 0.802 0.340 0.129 -0.171
## C18 0.672 0.207 0.312 -0.112
## C19 0.695 0.231 0.268 -0.263 -0.138
## C20 0.677 0.127 0.370
## C21 0.189 0.487
## C22 0.141 0.196 0.522
## C23 0.669
## C24 -0.126 0.804
## C25 -0.447 -0.238 -0.133 0.208
##
## Factor1 Factor2 Factor3 Factor4 Factor5
## SS loadings 4.640 4.085 2.855 2.470 1.821
## Proportion Var 0.186 0.163 0.114 0.099 0.073
## Cumulative Var 0.186 0.349 0.463 0.562 0.635
##
## $rotmat
## [,1] [,2] [,3] [,4] [,5]
## [1,] 9.999999e-01 -3.956736e-04 6.665802e-05 -3.007850e-05 2.808374e-05
## [2,] 3.955590e-04 9.999984e-01 1.769369e-03 1.085044e-04 -2.517190e-05
## [3,] -6.735329e-05 -1.769350e-03 9.999984e-01 4.692674e-05 -1.175867e-04
## [4,] 3.003870e-05 -1.084331e-04 -4.711648e-05 1.000000e+00 1.418587e-06
## [5,] -2.808174e-05 2.497507e-05 1.176292e-04 -1.409493e-06 1.000000e+00
EFA seperately
political capital
pol<-data2[,1:4]
names(pol)
## [1] "A1" "A2" "A3" "A4"
##screen plot , determining the number of factors or components in form of dimensions to be considered
res.pca <- prcomp(pol, scale = TRUE)
fviz_eig(res.pca)
fviz_pca_var(res.pca,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
fviz_pca_ind(res.pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)
eig.val <- get_eigenvalue(res.pca)
eig.val
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 2.5883995 64.70999 64.70999
## Dim.2 0.6404846 16.01211 80.72210
## Dim.3 0.4784912 11.96228 92.68438
## Dim.4 0.2926248 7.31562 100.00000
Non graphical solution to screen test
ev<-eigen(cor(pol))
ap<-parallel(subject=nrow(pol),var=ncol(pol),rep=100,cent=.05)
nS<-nScree(x=ev$values,parallel=ap$eigen$qevpea)
plotnScree(nS)
fac<-factanal(pol,1,rotation="varimax")
print(fac,digits = 2,cutoff=.3,sort=TRUE)
##
## Call:
## factanal(x = pol, factors = 1, rotation = "varimax")
##
## Uniquenesses:
## A1 A2 A3 A4
## 0.31 0.50 0.35 0.68
##
## Loadings:
## [1] 0.83 0.71 0.80 0.56
##
## Factor1
## SS loadings 2.15
## Proportion Var 0.54
##
## Test of the hypothesis that 1 factor is sufficient.
## The chi square statistic is 5.31 on 2 degrees of freedom.
## The p-value is 0.0702