library(rio)
dataprincipal=import("criminal_eap.xlsx")
str(dataprincipal)
## 'data.frame': 140 obs. of 10 variables:
## $ Country : chr "Afghanistan" "Albania" "Algeria" "Angola" ...
## $ Year : chr "2022" "2022" "2022" "2022" ...
## $ Factor 8: Criminal Justice : num 0.261 0.4 0.397 0.346 0.519 ...
## $ 8.1 Criminal investigation system is effective : num 0.298 0.424 0.266 0.354 0.456 ...
## $ 8.2 Criminal adjudication system is timely and effective : num 0.412 0.362 0.438 0.353 0.503 ...
## $ 8.3 Correctional system is effective in reducing criminal behavior: num 0.212 0.37 0.466 0.235 0.408 ...
## $ 8.4 Criminal system is impartial : num 0.169 0.493 0.567 0.376 0.457 ...
## $ 8.5 Criminal system is free of corruption : num 0.27 0.334 0.42 0.497 0.692 ...
## $ 8.6 Criminal system is free of improper government influence : num 0.186 0.303 0.153 0.292 0.546 ...
## $ 8.7. Due process of the law and rights of the accused : num 0.278 0.515 0.471 0.316 0.574 ...
set.seed(123)
names(dataprincipal)
## [1] "Country"
## [2] "Year"
## [3] "Factor 8: Criminal Justice"
## [4] "8.1 Criminal investigation system is effective"
## [5] "8.2 Criminal adjudication system is timely and effective"
## [6] "8.3 Correctional system is effective in reducing criminal behavior"
## [7] "8.4 Criminal system is impartial"
## [8] "8.5 Criminal system is free of corruption"
## [9] "8.6 Criminal system is free of improper government influence"
## [10] "8.7. Due process of the law and rights of the accused"
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
dontselect=c("Country","Year","Factor 8: Criminal Justice")
select=setdiff(names(dataprincipal),dontselect)
data=dataprincipal[,select]
# usaremos:
library(magrittr)
head(data,10)%>%
rmarkdown::paged_table()
library(psych)
library(corpcor)
corMatrix=polycor::hetcor(data)$correlations
round(corMatrix,2)
## 8.1 Criminal investigation system is effective
## 8.1 Criminal investigation system is effective 1.00
## 8.2 Criminal adjudication system is timely and effective 0.82
## 8.3 Correctional system is effective in reducing criminal behavior 0.79
## 8.4 Criminal system is impartial 0.62
## 8.5 Criminal system is free of corruption 0.80
## 8.6 Criminal system is free of improper government influence 0.65
## 8.7. Due process of the law and rights of the accused 0.78
## 8.2 Criminal adjudication system is timely and effective
## 8.1 Criminal investigation system is effective 0.82
## 8.2 Criminal adjudication system is timely and effective 1.00
## 8.3 Correctional system is effective in reducing criminal behavior 0.84
## 8.4 Criminal system is impartial 0.68
## 8.5 Criminal system is free of corruption 0.78
## 8.6 Criminal system is free of improper government influence 0.66
## 8.7. Due process of the law and rights of the accused 0.79
## 8.3 Correctional system is effective in reducing criminal behavior
## 8.1 Criminal investigation system is effective 0.79
## 8.2 Criminal adjudication system is timely and effective 0.84
## 8.3 Correctional system is effective in reducing criminal behavior 1.00
## 8.4 Criminal system is impartial 0.72
## 8.5 Criminal system is free of corruption 0.79
## 8.6 Criminal system is free of improper government influence 0.64
## 8.7. Due process of the law and rights of the accused 0.85
## 8.4 Criminal system is impartial
## 8.1 Criminal investigation system is effective 0.62
## 8.2 Criminal adjudication system is timely and effective 0.68
## 8.3 Correctional system is effective in reducing criminal behavior 0.72
## 8.4 Criminal system is impartial 1.00
## 8.5 Criminal system is free of corruption 0.71
## 8.6 Criminal system is free of improper government influence 0.69
## 8.7. Due process of the law and rights of the accused 0.80
## 8.5 Criminal system is free of corruption
## 8.1 Criminal investigation system is effective 0.80
## 8.2 Criminal adjudication system is timely and effective 0.78
## 8.3 Correctional system is effective in reducing criminal behavior 0.79
## 8.4 Criminal system is impartial 0.71
## 8.5 Criminal system is free of corruption 1.00
## 8.6 Criminal system is free of improper government influence 0.82
## 8.7. Due process of the law and rights of the accused 0.87
## 8.6 Criminal system is free of improper government influence
## 8.1 Criminal investigation system is effective 0.65
## 8.2 Criminal adjudication system is timely and effective 0.66
## 8.3 Correctional system is effective in reducing criminal behavior 0.64
## 8.4 Criminal system is impartial 0.69
## 8.5 Criminal system is free of corruption 0.82
## 8.6 Criminal system is free of improper government influence 1.00
## 8.7. Due process of the law and rights of the accused 0.81
## 8.7. Due process of the law and rights of the accused
## 8.1 Criminal investigation system is effective 0.78
## 8.2 Criminal adjudication system is timely and effective 0.79
## 8.3 Correctional system is effective in reducing criminal behavior 0.85
## 8.4 Criminal system is impartial 0.80
## 8.5 Criminal system is free of corruption 0.87
## 8.6 Criminal system is free of improper government influence 0.81
## 8.7. Due process of the law and rights of the accused 1.00
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggcorrplot(corMatrix)
library(psych)
psych::KMO(corMatrix)
## Kaiser-Meyer-Olkin factor adequacy
## Call: psych::KMO(r = corMatrix)
## Overall MSA = 0.91
## MSA for each item =
## 8.1 Criminal investigation system is effective
## 0.92
## 8.2 Criminal adjudication system is timely and effective
## 0.92
## 8.3 Correctional system is effective in reducing criminal behavior
## 0.90
## 8.4 Criminal system is impartial
## 0.95
## 8.5 Criminal system is free of corruption
## 0.91
## 8.6 Criminal system is free of improper government influence
## 0.90
## 8.7. Due process of the law and rights of the accused
## 0.89
correlation_matrix <- cor(data, use = "pairwise.complete.obs")
#valor KMO
kmo_result <- KMO(correlation_matrix)
kmo_result
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = correlation_matrix)
## Overall MSA = 0.91
## MSA for each item =
## 8.1 Criminal investigation system is effective
## 0.92
## 8.2 Criminal adjudication system is timely and effective
## 0.92
## 8.3 Correctional system is effective in reducing criminal behavior
## 0.90
## 8.4 Criminal system is impartial
## 0.95
## 8.5 Criminal system is free of corruption
## 0.91
## 8.6 Criminal system is free of improper government influence
## 0.90
## 8.7. Due process of the law and rights of the accused
## 0.89
#BARRET
cortest.bartlett(corMatrix,n=nrow(data))$p.value>0.05
## [1] FALSE
library(matrixcalc)
##
## Attaching package: 'matrixcalc'
## The following object is masked from 'package:corpcor':
##
## is.positive.definite
is.singular.matrix(corMatrix)
## [1] FALSE
fa.parallel(data, fa = 'fa',correct = T,plot = F)
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Parallel analysis suggests that the number of factors = 1 and the number of components = NA
efa_result <- fa(data, nfactors = 1, rotate = "varimax", fm = "ml")
print(efa_result)
## Factor Analysis using method = ml
## Call: fa(r = data, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
## ML1 h2
## 8.1 Criminal investigation system is effective 0.85 0.73
## 8.2 Criminal adjudication system is timely and effective 0.86 0.75
## 8.3 Correctional system is effective in reducing criminal behavior 0.89 0.80
## 8.4 Criminal system is impartial 0.81 0.65
## 8.5 Criminal system is free of corruption 0.92 0.84
## 8.6 Criminal system is free of improper government influence 0.82 0.67
## 8.7. Due process of the law and rights of the accused 0.95 0.90
## u2 com
## 8.1 Criminal investigation system is effective 0.27 1
## 8.2 Criminal adjudication system is timely and effective 0.25 1
## 8.3 Correctional system is effective in reducing criminal behavior 0.20 1
## 8.4 Criminal system is impartial 0.35 1
## 8.5 Criminal system is free of corruption 0.16 1
## 8.6 Criminal system is free of improper government influence 0.33 1
## 8.7. Due process of the law and rights of the accused 0.10 1
##
## ML1
## SS loadings 5.33
## Proportion Var 0.76
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## df null model = 21 with the objective function = 7.87 with Chi Square = 1068.41
## df of the model are 14 and the objective function was 0.65
##
## The root mean square of the residuals (RMSR) is 0.04
## The df corrected root mean square of the residuals is 0.05
##
## The harmonic n.obs is 140 with the empirical chi square 11.45 with prob < 0.65
## The total n.obs was 140 with Likelihood Chi Square = 87.5 with prob < 1.1e-12
##
## Tucker Lewis Index of factoring reliability = 0.894
## RMSEA index = 0.194 and the 90 % confidence intervals are 0.156 0.234
## BIC = 18.32
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## ML1
## Correlation of (regression) scores with factors 0.98
## Multiple R square of scores with factors 0.97
## Minimum correlation of possible factor scores 0.93
library(GPArotation)
## Warning: package 'GPArotation' was built under R version 4.3.3
##
## Attaching package: 'GPArotation'
## The following objects are masked from 'package:psych':
##
## equamax, varimin
resfa <- fa(data,
nfactors = 1,
cor = 'mixed',
rotate = "varimax", #oblimin?
fm="minres")
print(resfa$loadings)
##
## Loadings:
## MR1
## 8.1 Criminal investigation system is effective 0.852
## 8.2 Criminal adjudication system is timely and effective 0.874
## 8.3 Correctional system is effective in reducing criminal behavior 0.892
## 8.4 Criminal system is impartial 0.797
## 8.5 Criminal system is free of corruption 0.922
## 8.6 Criminal system is free of improper government influence 0.807
## 8.7. Due process of the law and rights of the accused 0.952
##
## MR1
## SS loadings 5.328
## Proportion Var 0.761
fa.diagram(resfa,main = "Resultados del EFA")
#valores que aportaron más
sort(resfa$communality)
## 8.4 Criminal system is impartial
## 0.6350573
## 8.6 Criminal system is free of improper government influence
## 0.6518719
## 8.1 Criminal investigation system is effective
## 0.7266429
## 8.2 Criminal adjudication system is timely and effective
## 0.7638836
## 8.3 Correctional system is effective in reducing criminal behavior
## 0.7953470
## 8.5 Criminal system is free of corruption
## 0.8494171
## 8.7. Due process of the law and rights of the accused
## 0.9056341
# Realizar EFA y determinar el número óptimo de factores
efa_result <- fa(data, nfactors = 2, rotate = "varimax")
print(efa_result)
## Factor Analysis using method = minres
## Call: fa(r = data, nfactors = 2, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR1 MR2
## 8.1 Criminal investigation system is effective 0.75 0.45
## 8.2 Criminal adjudication system is timely and effective 0.80 0.43
## 8.3 Correctional system is effective in reducing criminal behavior 0.81 0.45
## 8.4 Criminal system is impartial 0.52 0.61
## 8.5 Criminal system is free of corruption 0.60 0.71
## 8.6 Criminal system is free of improper government influence 0.36 0.83
## 8.7. Due process of the law and rights of the accused 0.63 0.71
## h2 u2
## 8.1 Criminal investigation system is effective 0.77 0.234
## 8.2 Criminal adjudication system is timely and effective 0.83 0.170
## 8.3 Correctional system is effective in reducing criminal behavior 0.85 0.146
## 8.4 Criminal system is impartial 0.64 0.362
## 8.5 Criminal system is free of corruption 0.86 0.143
## 8.6 Criminal system is free of improper government influence 0.82 0.176
## 8.7. Due process of the law and rights of the accused 0.91 0.093
## com
## 8.1 Criminal investigation system is effective 1.6
## 8.2 Criminal adjudication system is timely and effective 1.5
## 8.3 Correctional system is effective in reducing criminal behavior 1.6
## 8.4 Criminal system is impartial 2.0
## 8.5 Criminal system is free of corruption 1.9
## 8.6 Criminal system is free of improper government influence 1.4
## 8.7. Due process of the law and rights of the accused 2.0
##
## MR1 MR2
## SS loadings 3.02 2.66
## Proportion Var 0.43 0.38
## Cumulative Var 0.43 0.81
## Proportion Explained 0.53 0.47
## Cumulative Proportion 0.53 1.00
##
## Mean item complexity = 1.7
## Test of the hypothesis that 2 factors are sufficient.
##
## df null model = 21 with the objective function = 7.87 with Chi Square = 1068.41
## df of the model are 8 and the objective function was 0.25
##
## The root mean square of the residuals (RMSR) is 0.02
## The df corrected root mean square of the residuals is 0.03
##
## The harmonic n.obs is 140 with the empirical chi square 2.69 with prob < 0.95
## The total n.obs was 140 with Likelihood Chi Square = 34.1 with prob < 3.9e-05
##
## Tucker Lewis Index of factoring reliability = 0.934
## RMSEA index = 0.152 and the 90 % confidence intervals are 0.103 0.208
## BIC = -5.43
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## MR1 MR2
## Correlation of (regression) scores with factors 0.90 0.89
## Multiple R square of scores with factors 0.81 0.80
## Minimum correlation of possible factor scores 0.63 0.60
# Visualizar los valores propios (eigenvalues)
fa_parallel <- fa.parallel(data, fm = "ml", fa = "fa")
## Parallel analysis suggests that the number of factors = 1 and the number of components = NA
# matriz de correlación
correlation_matrix1 <- cor(data, use = "pairwise.complete.obs")
# Redondear la matriz de correlación a 2 decimales
rounded_correlation_matrix1 <- round(correlation_matrix1, 2)
#matriz redondeada
print(rounded_correlation_matrix1)
## 8.1 Criminal investigation system is effective
## 8.1 Criminal investigation system is effective 1.00
## 8.2 Criminal adjudication system is timely and effective 0.82
## 8.3 Correctional system is effective in reducing criminal behavior 0.79
## 8.4 Criminal system is impartial 0.62
## 8.5 Criminal system is free of corruption 0.80
## 8.6 Criminal system is free of improper government influence 0.65
## 8.7. Due process of the law and rights of the accused 0.78
## 8.2 Criminal adjudication system is timely and effective
## 8.1 Criminal investigation system is effective 0.82
## 8.2 Criminal adjudication system is timely and effective 1.00
## 8.3 Correctional system is effective in reducing criminal behavior 0.84
## 8.4 Criminal system is impartial 0.68
## 8.5 Criminal system is free of corruption 0.78
## 8.6 Criminal system is free of improper government influence 0.66
## 8.7. Due process of the law and rights of the accused 0.79
## 8.3 Correctional system is effective in reducing criminal behavior
## 8.1 Criminal investigation system is effective 0.79
## 8.2 Criminal adjudication system is timely and effective 0.84
## 8.3 Correctional system is effective in reducing criminal behavior 1.00
## 8.4 Criminal system is impartial 0.72
## 8.5 Criminal system is free of corruption 0.79
## 8.6 Criminal system is free of improper government influence 0.64
## 8.7. Due process of the law and rights of the accused 0.85
## 8.4 Criminal system is impartial
## 8.1 Criminal investigation system is effective 0.62
## 8.2 Criminal adjudication system is timely and effective 0.68
## 8.3 Correctional system is effective in reducing criminal behavior 0.72
## 8.4 Criminal system is impartial 1.00
## 8.5 Criminal system is free of corruption 0.71
## 8.6 Criminal system is free of improper government influence 0.69
## 8.7. Due process of the law and rights of the accused 0.80
## 8.5 Criminal system is free of corruption
## 8.1 Criminal investigation system is effective 0.80
## 8.2 Criminal adjudication system is timely and effective 0.78
## 8.3 Correctional system is effective in reducing criminal behavior 0.79
## 8.4 Criminal system is impartial 0.71
## 8.5 Criminal system is free of corruption 1.00
## 8.6 Criminal system is free of improper government influence 0.82
## 8.7. Due process of the law and rights of the accused 0.87
## 8.6 Criminal system is free of improper government influence
## 8.1 Criminal investigation system is effective 0.65
## 8.2 Criminal adjudication system is timely and effective 0.66
## 8.3 Correctional system is effective in reducing criminal behavior 0.64
## 8.4 Criminal system is impartial 0.69
## 8.5 Criminal system is free of corruption 0.82
## 8.6 Criminal system is free of improper government influence 1.00
## 8.7. Due process of the law and rights of the accused 0.81
## 8.7. Due process of the law and rights of the accused
## 8.1 Criminal investigation system is effective 0.78
## 8.2 Criminal adjudication system is timely and effective 0.79
## 8.3 Correctional system is effective in reducing criminal behavior 0.85
## 8.4 Criminal system is impartial 0.80
## 8.5 Criminal system is free of corruption 0.87
## 8.6 Criminal system is free of improper government influence 0.81
## 8.7. Due process of the law and rights of the accused 1.00
#valor KMO
kmo_result <- KMO(correlation_matrix1)
print(kmo_result)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = correlation_matrix1)
## Overall MSA = 0.91
## MSA for each item =
## 8.1 Criminal investigation system is effective
## 0.92
## 8.2 Criminal adjudication system is timely and effective
## 0.92
## 8.3 Correctional system is effective in reducing criminal behavior
## 0.90
## 8.4 Criminal system is impartial
## 0.95
## 8.5 Criminal system is free of corruption
## 0.91
## 8.6 Criminal system is free of improper government influence
## 0.90
## 8.7. Due process of the law and rights of the accused
## 0.89
fa_parallel <- fa.parallel(data, fa = 'fa', correct = TRUE, plot = FALSE)
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Parallel analysis suggests that the number of factors = 1 and the number of components = NA
n_factors <- fa_parallel$nfact
efa_result <- fa(data, nfactors = n_factors, rotate = "varimax", fm = "ml", scores = "regression")
print(efa_result)
## Factor Analysis using method = ml
## Call: fa(r = data, nfactors = n_factors, rotate = "varimax", scores = "regression",
## fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
## ML1 h2
## 8.1 Criminal investigation system is effective 0.85 0.73
## 8.2 Criminal adjudication system is timely and effective 0.86 0.75
## 8.3 Correctional system is effective in reducing criminal behavior 0.89 0.80
## 8.4 Criminal system is impartial 0.81 0.65
## 8.5 Criminal system is free of corruption 0.92 0.84
## 8.6 Criminal system is free of improper government influence 0.82 0.67
## 8.7. Due process of the law and rights of the accused 0.95 0.90
## u2 com
## 8.1 Criminal investigation system is effective 0.27 1
## 8.2 Criminal adjudication system is timely and effective 0.25 1
## 8.3 Correctional system is effective in reducing criminal behavior 0.20 1
## 8.4 Criminal system is impartial 0.35 1
## 8.5 Criminal system is free of corruption 0.16 1
## 8.6 Criminal system is free of improper government influence 0.33 1
## 8.7. Due process of the law and rights of the accused 0.10 1
##
## ML1
## SS loadings 5.33
## Proportion Var 0.76
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## df null model = 21 with the objective function = 7.87 with Chi Square = 1068.41
## df of the model are 14 and the objective function was 0.65
##
## The root mean square of the residuals (RMSR) is 0.04
## The df corrected root mean square of the residuals is 0.05
##
## The harmonic n.obs is 140 with the empirical chi square 11.45 with prob < 0.65
## The total n.obs was 140 with Likelihood Chi Square = 87.5 with prob < 1.1e-12
##
## Tucker Lewis Index of factoring reliability = 0.894
## RMSEA index = 0.194 and the 90 % confidence intervals are 0.156 0.234
## BIC = 18.32
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## ML1
## Correlation of (regression) scores with factors 0.98
## Multiple R square of scores with factors 0.97
## Minimum correlation of possible factor scores 0.93