Indicador económico
Cargar datos del indicador económico
library(readxl)
library(kableExtra)
IE <- read_excel("C:/Users/Carlos/Desktop/Documentos universidad/EDD 1 Documentos UES/Repaso R studios/Datos preliminares/IndicadorEconomico.xlsx")
head(IE, 5)
## # A tibble: 5 x 13
## Años PIB FBK Gg_S X IPC IDH PIBpp Ins G_edusup Gemp_ID Invest
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2000 5497. 1259. 674. 713. 80.4 80.4 30263. 63.5 1790. 104. 3361.
## 2 2001 5659. 1267. 731. 668. 82.6 82.6 30436. 63.7 1960. 111. 3512.
## 3 2002 5847. 1253. 800. 652. 84.2 84.2 31096. 68.7 2215. 106. 3638.
## 4 2003 6175. 1328. 872. 683. 86.3 86.3 33849. 70.2 2419. 110. 3686.
## 5 2004 6618. 1459. 939. 780. 88.2 88.2 36874. 70.9 2618. 115. 3904.
## # ... with 1 more variable: PT <dbl>
Definición de indicadores.
library(printr)
## Registered S3 method overwritten by 'printr':
## method from
## knit_print.data.frame rmarkdown
Num1<- c(1,2,3,4,5,6,7,8,9,10,11,12)
Indi1 <- c("PIB", "Formación bruta de capital/PIB", "Gasto público en salud/PIB", "Exportación de bienes y servicios", "Inflación", "IDH", "PIB per cápita", "Inscripción escolar nivel terciario", "Gasto en educación superior en I + D","Gasto empresarial en I+D", "Investigadores dedicados a investigación y desarrollo", "Productividad laboral")
Fuente1 <- c("Banco Mundial", "Banco Mundial", "Banco Mundial", "Banco Mundial", "Banco Mundial", "ONU", "Banco Mundial", "Banco Mundial", "OCDE", "Banco Mundial", "Banco Mundial", "OCDE")
dataf1 <- data.frame(Num1, Indi1, Fuente1)
dataf1
Num1
|
Indi1
|
Fuente1
|
1
|
PIB
|
Banco Mundial
|
2
|
Formación bruta de capital/PIB
|
Banco Mundial
|
3
|
Gasto público en salud/PIB
|
Banco Mundial
|
4
|
Exportación de bienes y servicios
|
Banco Mundial
|
5
|
Inflación
|
Banco Mundial
|
6
|
IDH
|
ONU
|
7
|
PIB per cápita
|
Banco Mundial
|
8
|
Inscripción escolar nivel terciario
|
Banco Mundial
|
9
|
Gasto en educación superior en I + D
|
OCDE
|
10
|
Gasto empresarial en I+D
|
Banco Mundial
|
11
|
Investigadores dedicados a investigación y desarrollo
|
Banco Mundial
|
12
|
Productividad laboral
|
OCDE
|
Resumen estadístico de variables: numérico.
IE1 <- IE[,-1]
summary(IE1[,1:12])
|
PIB
|
FBK
|
Gg_S
|
X
|
IPC
|
IDH
|
PIBpp
|
Ins
|
G_edusup
|
Gemp_ID
|
Invest
|
PT
|
|
Min. : 5497
|
Min. :1253
|
Min. : 673.6
|
Min. : 651.7
|
Min. : 80.43
|
Min. : 80.43
|
Min. :30263
|
Min. :63.46
|
Min. :1790
|
Min. :103.6
|
Min. :3361
|
Min. :49.36
|
|
1st Qu.: 6982
|
1st Qu.:1501
|
1st Qu.: 988.7
|
1st Qu.: 846.7
|
1st Qu.: 90.09
|
1st Qu.: 90.09
|
1st Qu.:39361
|
1st Qu.:70.97
|
1st Qu.:2708
|
1st Qu.:118.2
|
1st Qu.:3934
|
1st Qu.:54.23
|
|
Median : 8217
|
Median :1746
|
Median :1280.7
|
Median :1172.3
|
Median : 99.17
|
Median : 99.17
|
Median :47723
|
Median :76.09
|
Median :3358
|
Median :150.7
|
Median :4268
|
Median :57.42
|
|
Mean : 8338
|
Mean :1749
|
Mean :1274.7
|
Mean :1129.5
|
Mean : 99.12
|
Mean : 99.12
|
Mean :45202
|
Mean :74.08
|
Mean :3231
|
Mean :156.2
|
Mean :4102
|
Mean :56.68
|
|
3rd Qu.: 9722
|
3rd Qu.:2013
|
3rd Qu.:1549.3
|
3rd Qu.:1389.8
|
3rd Qu.:108.18
|
3rd Qu.:108.18
|
3rd Qu.:52260
|
3rd Qu.:77.70
|
3rd Qu.:3728
|
3rd Qu.:179.8
|
3rd Qu.:4358
|
3rd Qu.:59.91
|
|
Max. :11585
|
Max. :2420
|
Max. :1865.0
|
Max. :1539.6
|
Max. :117.00
|
Max. :117.00
|
Max. :55746
|
Max. :79.21
|
Max. :4405
|
Max. :250.1
|
Max. :4404
|
Max. :62.25
|
Resumen estadístico de variables: gráfico.
library(ggplot2)
boxplot(IE1[,1], xlab= "1", ylab="Miles de millones de dólares estadounidenses", main = "Boxplot: PIB")

boxplot(IE1[,2], xlab= "2", ylab="Miles de millones de dólares estadounidenses", main = "Boxplot: FBK/PIB")

boxplot(IE1[,3], xlab= "3", ylab="Miles de millones de dólares estadounidenses", main = "Boxplot: Gasto público en salud/PIB")

boxplot(IE1[,4], xlab= "4", ylab="Miles de millones de dólares", main = "Boxplot: Exportaciónd e bienes y servicios")

boxplot(IE1[,5], xlab= "5", ylab="Tasas", main = "Boxplot: Inflación")

boxplot(IE1[,6], xlab= "6", ylab="Índice", main = "Boxplot: IDH")

boxplot(IE1[,7], xlab= "7", ylab="Dólares estadounidenses", main = "Boxplot: PIB per cápita")

boxplot(IE1[,8], xlab= "8", ylab="Porcentaje", main = "Boxplot: Inscripción escolar nivel terciario")

boxplot(IE1[,9], xlab= "9", ylab="Miles de millones de dólares estadounidenses", main = "Boxplot: Gasto en educación superior en I + D")

boxplot(IE1[,10], xlab= "10", ylab="Miles de millones de dólares estadounidenses", main = "Boxplot: Gasto empresarial en I+D")

boxplot(IE1[,11], xlab= "11", ylab="Por cada millón de personas", main = "Boxplot: Investigadores dedicados a investigación y desarrollo")

boxplot(IE1[,12], xlab= "12", ylab="Dólares estadounidenses", main = "Boxplot: Productividad laboral")

Estimacion del modelo
library(stargazer)
options(scipen = 9999)
model_eco <- lm(formula = Años~PIB+FBK+Gg_S+X+IPC+IDH+PIBpp+Ins+G_edusup+Gemp_ID+Invest+PT, data=IE)
stargazer(model_eco,title = "Modelo estimado",type = "text",digits = 8)
##
## Modelo estimado
## ==================================================
## Dependent variable:
## ------------------------------
## Años
## --------------------------------------------------
## PIB 0.00284155*
## (0.00129963)
##
## FBK -0.00327286**
## (0.00129350)
##
## Gg_S 0.00607449
## (0.00362631)
##
## X -0.00163979
## (0.00207789)
##
## IPC -21.07755000
## (19.62064000)
##
## IDH 21.39666000
## (19.61946000)
##
## PIBpp -0.00007529
## (0.00007034)
##
## Ins -0.12894910*
## (0.06064793)
##
## G_edusup 0.00079102
## (0.00093556)
##
## Gemp_ID -0.04855821**
## (0.01603287)
##
## Invest -0.00095493
## (0.00061876)
##
## PT -0.17953760
## (0.23883360)
##
## Constant 1,986.08500000***
## (12.58551000)
##
## --------------------------------------------------
## Observations 20
## R2 0.99987940
## Adjusted R2 0.99967250
## Residual Std. Error 0.10705460 (df = 7)
## F Statistic 4,834.79000000*** (df = 12; 7)
## ==================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
Jarque Bera
library(normtest)
library(nortest)
library(fitdistrplus)
fit_norm_eco<- fitdist(data = model_eco$residuals, distr = "norm")
plot(fit_norm_eco)

jb.norm.test(model_eco$residuals)
##
## Jarque-Bera test for normality
##
## data: model_eco$residuals
## JB = 0.53199, p-value = 0.712
#Pasó la prueba
Prueba de Kolmogorov Smirnov
lillie.test(model_eco$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: model_eco$residuals
## D = 0.098664, p-value = 0.8772
#Pasó raspada la prueba
Prueba de Shairo-Wilk
shapiro.test(model_eco$residuals)
##
## Shapiro-Wilk normality test
##
## data: model_eco$residuals
## W = 0.97735, p-value = 0.8955
#Pasó la prueba
Normalizacion de datos estimados
Eco.mat <- model.matrix(model_eco)
Eco.nor<- scale(Eco.mat[,-1])
stargazer(head(Eco.nor, n=6), type="text")
##
## ========================================================================================
## PIB FBK Gg_S X IPC IDH PIBpp Ins G_edusup Gemp_ID Invest PT
## ----------------------------------------------------------------------------------------
## 1 -1.548 -1.392 -1.634 -1.318 -1.670 -1.670 -1.748 -2.205 -1.902 -1.267 -2.275 -1.897
## 2 -1.460 -1.370 -1.477 -1.461 -1.478 -1.478 -1.727 -2.152 -1.678 -1.100 -1.810 -1.648
## 3 -1.358 -1.409 -1.291 -1.511 -1.336 -1.336 -1.650 -1.111 -1.341 -1.207 -1.424 -1.351
## 4 -1.179 -1.196 -1.094 -1.412 -1.147 -1.147 -1.328 -0.815 -1.072 -1.103 -1.277 -1.107
## 5 -0.937 -0.825 -0.913 -1.104 -0.972 -0.972 -0.974 -0.651 -0.810 -0.992 -0.606 -0.861
## 6 -0.673 -0.357 -0.732 -0.825 -0.752 -0.752 -0.586 -0.645 -0.650 -0.892 -0.485 -0.562
## ----------------------------------------------------------------------------------------
Construyendo la matriz de correlación
library(Hmisc)
Eco_Mat_R<-rcorr(as.matrix(Eco.nor))
stargazer(Eco_Mat_R$r,type = "text")
##
## ======================================================================================
## PIB FBK Gg_S X IPC IDH PIBpp Ins G_edusup Gemp_ID Invest PT
## --------------------------------------------------------------------------------------
## PIB 1 0.971 0.996 0.963 0.995 0.995 0.945 0.888 0.981 0.977 0.886 0.982
## FBK 0.971 1 0.950 0.915 0.944 0.944 0.893 0.792 0.919 0.964 0.799 0.922
## Gg_S 0.996 0.950 1 0.956 0.997 0.997 0.939 0.906 0.985 0.967 0.900 0.989
## X 0.963 0.915 0.956 1 0.973 0.973 0.978 0.905 0.961 0.910 0.901 0.960
## IPC 0.995 0.944 0.997 0.973 1 1.000 0.959 0.920 0.992 0.959 0.917 0.992
## IDH 0.995 0.944 0.997 0.973 1.000 1 0.959 0.920 0.992 0.959 0.917 0.992
## PIBpp 0.945 0.893 0.939 0.978 0.959 0.959 1 0.948 0.970 0.874 0.950 0.964
## Ins 0.888 0.792 0.906 0.905 0.920 0.920 0.948 1 0.955 0.796 0.969 0.947
## G_edusup 0.981 0.919 0.985 0.961 0.992 0.992 0.970 0.955 1 0.933 0.945 0.995
## Gemp_ID 0.977 0.964 0.967 0.910 0.959 0.959 0.874 0.796 0.933 1 0.792 0.928
## Invest 0.886 0.799 0.900 0.901 0.917 0.917 0.950 0.969 0.945 0.792 1 0.944
## PT 0.982 0.922 0.989 0.960 0.992 0.992 0.964 0.947 0.995 0.928 0.944 1
## --------------------------------------------------------------------------------------
library(corrplot)
corrplot(Eco_Mat_R$r, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 90, html_font = "sans-serif")

#https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html
p.mat1 <- cor.mtest(Eco.nor)$p
corrplot(Eco_Mat_R$r, type = "upper", order = "hclust",
p.mat = p.mat1, sig.level = 0.01, tl.col = "black", html_font = "sans-serif")

library(PerformanceAnalytics)
library(GGally)
chart.Correlation(as.matrix(IE[,-1]),histogram = TRUE,pch=19)

Prueba de Farrar-Glaubar, en busca de evidencias de multicolinealidad
library(mctest)
mctest(model_eco)
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0000 1
## Farrar Chi-Square: 923.6977 1
## Red Indicator: 0.9437 1
## Sum of Lambda Inverse: 159924361.2204 1
## Theil's Method: 0.9697 1
## Condition Number: 414984.2898 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
# El modelo ha identificado un valor crítico de 85.9649 menor que el valor calculado del estadístico de la prueba chi-cuadrado de 687.4918. El cual resulta, muy significativo, lo que implica la presencia de multicolinealidad en el modelo.
KMO tets
library(psych)
KMO(Eco.nor)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = Eco.nor)
## Overall MSA = 0.76
## MSA for each item =
## PIB FBK Gg_S X IPC IDH PIBpp Ins
## 0.81 0.79 0.82 0.72 0.72 0.72 0.75 0.76
## G_edusup Gemp_ID Invest PT
## 0.87 0.69 0.83 0.71
#Si el valor:
# KMO > 0.75 ► la idea de realizar análisis factorial es buena
# 0.5 < KMO < 0.75 ► la idea es aceptable
# KMO < 0.5 ► es inaceptable realizar el análisis
Metodo de ponderacion Critic
library(psych)
modelo_2<-principal(r = Eco_Mat_R$r,nfactors = 2,covar = FALSE,rotate = "varimax")
numero_de_factores<-2
modelo_2
## Principal Components Analysis
## Call: principal(r = Eco_Mat_R$r, nfactors = 2, rotate = "varimax",
## covar = FALSE)
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 h2 u2 com
## PIB 0.81 0.59 1.00 0.00052 1.8
## FBK 0.88 0.44 0.97 0.03191 1.5
## Gg_S 0.78 0.62 0.99 0.00946 1.9
## X 0.70 0.68 0.95 0.04755 2.0
## IPC 0.75 0.65 1.00 0.00351 2.0
## IDH 0.75 0.65 1.00 0.00351 2.0
## PIBpp 0.61 0.77 0.97 0.03172 1.9
## Ins 0.46 0.88 0.98 0.01828 1.5
## G_edusup 0.69 0.72 0.99 0.00626 2.0
## Gemp_ID 0.89 0.44 0.99 0.01473 1.5
## Invest 0.46 0.88 0.98 0.02314 1.5
## PT 0.69 0.72 0.99 0.00915 2.0
##
## RC1 RC2
## SS loadings 6.20 5.60
## Proportion Var 0.52 0.47
## Cumulative Var 0.52 0.98
## Proportion Explained 0.53 0.47
## Cumulative Proportion 0.53 1.00
##
## Mean item complexity = 1.8
## Test of the hypothesis that 2 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.01
##
## Fit based upon off diagonal values = 1
Al incorporar el factor 2 la varianza acumulada alcanza a explicar el 100% del modelo, pero los indicadores poseen una predominancia de explicación en el factor 1, por otra parte el 100% de los indicadores alcanza un nivel de comunalidad de explicación por encima del 95%.
Correlación de los componentes con las variables: \(rij=aj⋅λ−−√j\)
# Normalizando los datos
norm_directa <- function(x){
return((x-min(x)) / (max(x)-min(x)))
}
norm_inversa <- function(x){
return((max(x)-x) / (max(x)-min(x)))
}
IE[,-1] %>% dplyr::select(FBK, PIB, Gg_S, X, IDH, PIBpp, Ins, G_edusup, Gemp_ID, Invest, PT, IPC)%>% dplyr::transmute(FBK=norm_directa(FBK),PIB=norm_directa(PIB), Gg_S=norm_directa(Gg_S), X=norm_directa(X),
IDH=norm_directa(IDH), PIBpp=norm_directa(PIBpp), Ins=norm_directa(Ins),
G_edusup=norm_directa(G_edusup), Gemp_ID=norm_directa(Gemp_ID),
Invest=norm_directa(Invest), PT=norm_directa(PT), IPC=norm_directa(IPC) ) ->data_eco_f1
print(data_eco_f1)
## # A tibble: 20 x 12
## FBK PIB Gg_S X IDH PIBpp Ins G_edusup Gemp_ID Invest
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.00541 0 0 0.0687 0 0 0 0 0 0
## 2 0.0119 0.0266 0.0485 0.0179 0.0588 0.00679 0.0162 0.0650 0.0473 0.145
## 3 0 0.0575 0.106 0 0.102 0.0327 0.335 0.163 0.0171 0.266
## 4 0.0644 0.111 0.167 0.0354 0.160 0.141 0.425 0.241 0.0465 0.312
## 5 0.176 0.184 0.223 0.145 0.214 0.259 0.475 0.317 0.0778 0.521
## 6 0.317 0.264 0.278 0.244 0.281 0.390 0.477 0.363 0.106 0.559
## 7 0.419 0.340 0.339 0.358 0.346 0.513 0.520 0.406 0.221 0.609
## 8 0.458 0.404 0.398 0.484 0.409 0.628 0.647 0.470 0.300 0.675
## 9 0.426 0.433 0.441 0.601 0.490 0.676 0.694 0.530 0.335 0.794
## 10 0.225 0.396 0.483 0.378 0.489 0.537 0.755 0.582 0.307 0.925
## 11 0.270 0.461 0.536 0.571 0.535 0.694 0.869 0.618 0.297 0.873
## 12 0.359 0.520 0.575 0.760 0.618 0.813 0.967 0.697 0.357 0.868
## 13 0.477 0.577 0.622 0.813 0.669 0.859 0.960 0.737 0.381 1
## 14 0.541 0.627 0.657 0.862 0.703 0.888 0.862 0.740 0.444 0.909
## 15 0.641 0.685 0.719 0.924 0.754 0.891 0.868 0.746 0.509 0.955
## 16 0.681 0.722 0.782 0.821 0.773 0.783 0.850 0.735 0.553 0.971
## 17 0.703 0.760 0.844 0.791 0.813 0.780 0.900 0.802 0.617 0.992
## 18 0.801 0.836 0.902 0.895 0.869 0.877 0.958 0.870 0.698 0.909
## 19 0.926 0.928 0.971 1 0.941 0.957 1 0.945 0.856 0.967
## 20 1 1 1 0.992 1 1 0.915 1 1 0.959
## # ... with 2 more variables: PT <dbl>, IPC <dbl>
Ponderadores
funcion_critic <- function(ecofun) {
# Desviación Típica
desviacion <- apply(ecofun,MARGIN = 2,FUN = sd)
# Matriz de Correlación
coeficiente_correlacion<-cor(ecofun)
# Ponderadores Brutos
1-coeficiente_correlacion->sum_data
colSums(sum_data)->sum_vector
desviacion * sum_vector->vj
# Ponderadores netos
wj <- vj/sum(vj)
# Ponderadores
ponderadores<-round(wj*100,2)
# Resultados en lista
list(Desviacion_Estandar=desviacion,Ponderadores_Brutos=vj,Ponderadores_Netos=wj,Ponderadores=ponderadores)
}
# Probando la Función
library(kableExtra)
salida_critic<-funcion_critic(data_eco_f1)
salida_critic %>% as.data.frame() %>% kable(caption = "Prueba Función Critic",align = "c",digits = 3) %>% kable_minimal(html_font = "helvetica") %>% kable_styling(bootstrap_options = c("striped","hover"))
Prueba Función Critic
|
Desviacion_Estandar
|
Ponderadores_Brutos
|
Ponderadores_Netos
|
Ponderadores
|
FBK
|
0.302
|
0.298
|
0.127
|
12.71
|
PIB
|
0.301
|
0.127
|
0.054
|
5.43
|
Gg_S
|
0.309
|
0.130
|
0.055
|
5.53
|
X
|
0.356
|
0.215
|
0.092
|
9.16
|
IDH
|
0.306
|
0.108
|
0.046
|
4.61
|
PIBpp
|
0.335
|
0.208
|
0.089
|
8.88
|
Ins
|
0.306
|
0.323
|
0.138
|
13.79
|
G_edusup
|
0.290
|
0.108
|
0.046
|
4.61
|
Gemp_ID
|
0.283
|
0.266
|
0.114
|
11.35
|
Invest
|
0.312
|
0.337
|
0.144
|
14.39
|
PT
|
0.299
|
0.115
|
0.049
|
4.92
|
IPC
|
0.306
|
0.108
|
0.046
|
4.61
|
Indicador de pobreza
Carga de datos
IP <- read_excel("C:/Users/Carlos/Desktop/Documentos universidad/EDD 1 Documentos UES/Repaso R studios/Datos preliminares/IndicadorPobreza.xlsx")
head(IP, 5)
Año
|
Coef_arg
|
C_casa
|
Mort
|
W_prom
|
S_IN
|
Pob_A
|
2000
|
0.0265
|
17.13277
|
6.10
|
49409.66
|
1123.022
|
15.3542
|
2001
|
0.0234
|
17.13767
|
6.00
|
49550.32
|
1081.934
|
15.5186
|
2002
|
0.0232
|
17.01401
|
6.20
|
49583.81
|
1065.072
|
15.6886
|
2003
|
0.0229
|
17.18054
|
6.05
|
49932.54
|
1101.878
|
15.8284
|
2004
|
0.0220
|
17.11427
|
6.05
|
50933.33
|
1205.216
|
15.9782
|
Definición de indicadores.
Num2<- c(1,2,3,4,5,6)
Indi2 <- c("Ahorro interno bruto", "Salario promedio", "Tasa de mortalidad infantil", "Gasto de la vivienda", "Coeficiente trabajadores de la actividad agrícola", "Población anual")
Fuente2 <- c("OCDE", "OCDE", "OCDE", "Banco Mundial", "OCDE", "OCDE")
dataf2 <- data.frame(Num2, Indi2, Fuente2)
dataf2
Num2
|
Indi2
|
Fuente2
|
1
|
Ahorro interno bruto
|
OCDE
|
2
|
Salario promedio
|
OCDE
|
3
|
Tasa de mortalidad infantil
|
OCDE
|
4
|
Gasto de la vivienda
|
Banco Mundial
|
5
|
Coeficiente trabajadores de la actividad agrícola
|
OCDE
|
6
|
Población anual
|
OCDE
|
Resumen estadístico de variables: numérico.
IP2 <- IP[,-1]
summary(IP2[,1:6])
|
Coef_arg
|
C_casa
|
Mort
|
W_prom
|
S_IN
|
Pob_A
|
|
Min. :0.01770
|
Min. :16.93
|
Min. :5.035
|
Min. :49410
|
Min. :1065
|
Min. :15.35
|
|
1st Qu.:0.01887
|
1st Qu.:17.15
|
1st Qu.:5.237
|
1st Qu.:51440
|
1st Qu.:1222
|
1st Qu.:16.09
|
|
Median :0.01975
|
Median :17.29
|
Median :5.600
|
Median :54954
|
Median :1405
|
Median :16.92
|
|
Mean :0.02047
|
Mean :17.31
|
Mean :5.641
|
Mean :54386
|
Mean :1490
|
Mean :16.95
|
|
3rd Qu.:0.02205
|
3rd Qu.:17.48
|
3rd Qu.:6.013
|
3rd Qu.:56995
|
3rd Qu.:1789
|
3rd Qu.:17.76
|
|
Max. :0.02650
|
Max. :17.69
|
Max. :6.200
|
Max. :59517
|
Max. :2130
|
Max. :18.80
|
Resumen estadístico de variables: gráfico.
boxplot(IP2[,1], xlab= "1", ylab="Miles de millones de dólares", main = "Boxplot: Ahorro interno bruto")

boxplot(IP2[,2], xlab= "2", ylab="Dólares estadounidenses", main = "Boxplot: Salario promedio")

boxplot(IP2[,3], xlab= "3", ylab="Porcentaje (%)", main = "Boxplot: Tasa de mortalidad infantil")

boxplot(IP2[,4], xlab= "4", ylab="Porcentaje (%)", main = "Boxplot: Gasto de la vivienda")

boxplot(IP2[,5], xlab= "5", ylab="Porcentaje (%)", main = "Boxplot: Coeficiente trabajadores de la actividad agrícola")

boxplot(IP2[,6], xlab= "6", ylab="Millones de personas", main = "Boxplot: Población anual")

Estimación del modelo
options(scipen = 9999)
model_po <- lm(formula = Año~Coef_arg+C_casa+Mort+W_prom+S_IN+Pob_A, data=IP)
stargazer(model_po,title = "Modelo estimado",type = "text",digits = 8)
##
## Modelo estimado
## ==================================================
## Dependent variable:
## ------------------------------
## Año
## --------------------------------------------------
## Coef_arg -182.00530000
## (110.02090000)
##
## C_casa 0.06110182
## (0.42966620)
##
## Mort -0.35595460
## (0.81012350)
##
## W_prom 0.00023354*
## (0.00013003)
##
## S_IN -0.00000992
## (0.00077458)
##
## Pob_A 4.42153800***
## (0.53944560)
##
## Constant 1,926.53100000***
## (14.64667000)
##
## --------------------------------------------------
## Observations 20
## R2 0.99852620
## Adjusted R2 0.99784600
## Residual Std. Error 0.27457190 (df = 13)
## F Statistic 1,467.97200000*** (df = 6; 13)
## ==================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
Jarque Bera
fit_norm_po<- fitdist(data = model_po$residuals, distr = "norm")
plot(fit_norm_po)

jb.norm.test(model_po$residuals)
##
## Jarque-Bera test for normality
##
## data: model_po$residuals
## JB = 3.1523, p-value = 0.0595
#Pasó la prueba
Prueba de Kolmogorov Smirnov
lillie.test(model_po$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: model_po$residuals
## D = 0.15525, p-value = 0.2343
#Pasó raspada la prueba
Prueba de Shairo-Wilk
shapiro.test(model_po$residuals)
##
## Shapiro-Wilk normality test
##
## data: model_po$residuals
## W = 0.94639, p-value = 0.3156
#Pasó raspada la prueba
Normalizacion de datos estimados
po.mat <- model.matrix(model_po)
po.nor<- scale(po.mat[,-1])
stargazer(head(po.nor, n=6), type="text")
##
## ============================================
## Coef_arg C_casa Mort W_prom S_IN Pob_A
## --------------------------------------------
## 1 2.640 -0.831 1.176 -1.516 -1.113 -1.527
## 2 1.283 -0.807 0.920 -1.473 -1.238 -1.370
## 3 1.195 -1.399 1.432 -1.463 -1.289 -1.208
## 4 1.064 -0.602 1.048 -1.357 -1.177 -1.074
## 5 0.670 -0.919 1.048 -1.052 -0.864 -0.931
## 6 0.757 0.801 1.304 -0.846 -0.522 -0.788
## --------------------------------------------
Construyendo la matriz de correlación
po_Mat_R<-rcorr(as.matrix(po.nor))
stargazer(po_Mat_R$r,type = "text")
##
## ====================================================
## Coef_arg C_casa Mort W_prom S_IN Pob_A
## ----------------------------------------------------
## Coef_arg 1 -0.541 0.871 -0.945 -0.832 -0.924
## C_casa -0.541 1 -0.543 0.611 0.646 0.631
## Mort 0.871 -0.543 1 -0.956 -0.904 -0.967
## W_prom -0.945 0.611 -0.956 1 0.928 0.982
## S_IN -0.832 0.646 -0.904 0.928 1 0.953
## Pob_A -0.924 0.631 -0.967 0.982 0.953 1
## ----------------------------------------------------
library(corrplot)
corrplot(po_Mat_R$r, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 90, html_font = "sans-serif")

#https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html
p.mat2 <- cor.mtest(po.nor)$p
corrplot(po_Mat_R$r, type = "upper", order = "hclust",
p.mat = p.mat2, sig.level = 0.01, tl.col = "black", html_font = "sans-serif")

library(PerformanceAnalytics)
chart.Correlation(as.matrix(IP[,-1]),histogram = TRUE,pch=19)

Prueba de Farrar-Glaubar, en busca de evidencias de multicolinealidad
library(mctest)
mctest(model_po)
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0000 1
## Farrar Chi-Square: 192.7920 1
## Red Indicator: 0.8316 1
## Sum of Lambda Inverse: 185.9489 1
## Theil's Method: 0.3168 0
## Condition Number: 723.0641 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
# El modelo ha identificado un valor crítico de 24.99579 menor que el valor calculado del estadístico de la prueba chi-cuadrado de 192.7920. El cual resulta, muy significativo, lo que implica la presencia de multicolinealidad en el modelo.
KMO tets
library(psych)
KMO(po.nor)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = po.nor)
## Overall MSA = 0.79
## MSA for each item =
## Coef_arg C_casa Mort W_prom S_IN Pob_A
## 0.74 0.84 0.75 0.86 0.79 0.76
#Si el valor:
# KMO > 0.75 ► la idea de realizar análisis factorial es buena
# 0.5 < KMO < 0.75 ► la idea es aceptable
# KMO < 0.5 ► es inaceptable realizar el análisis
Metodologia de ponderacion Critic
modelo_P2<-principal(r = po_Mat_R$r,nfactors = 2,covar = FALSE,rotate = "varimax")
modelo_P2
## Principal Components Analysis
## Call: principal(r = po_Mat_R$r, nfactors = 2, rotate = "varimax", covar = FALSE)
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 h2 u2 com
## Coef_arg -0.91 -0.26 0.90 0.1047 1.2
## C_casa 0.31 0.95 1.00 0.0035 1.2
## Mort -0.93 -0.27 0.94 0.0562 1.2
## W_prom 0.93 0.34 0.98 0.0154 1.3
## S_IN 0.86 0.42 0.91 0.0873 1.5
## Pob_A 0.92 0.37 0.99 0.0097 1.3
##
## RC1 RC2
## SS loadings 4.25 1.47
## Proportion Var 0.71 0.25
## Cumulative Var 0.71 0.95
## Proportion Explained 0.74 0.26
## Cumulative Proportion 0.74 1.00
##
## Mean item complexity = 1.3
## Test of the hypothesis that 2 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.02
##
## Fit based upon off diagonal values = 1
Al incorporar el factor 2 la varianza acumulada alcanza a explicar el 100% del modelo, pero los indicadores poseen una predominancia de explicación en el factor 1, por otra parte el 100% de los indicadores alcanza un nivel de comunalidad de explicación por encima del 89%.
Correlación de los componentes con las variables: \(rij=aj⋅λ−−√j\)
norm_directa <- function(x){
return((x-min(x)) / (max(x)-min(x)))
}
norm_inversa <- function(x){
return((max(x)-x) / (max(x)-min(x)))
}
IP[,-1] %>% dplyr::select(Coef_arg, C_casa, Mort, W_prom, S_IN, Pob_A)%>% dplyr::transmute(Coef_arg=norm_directa(Coef_arg),C_casa=norm_inversa(C_casa), Mort=norm_directa(Mort), S_IN=norm_inversa(S_IN),W_prom=norm_inversa(W_prom), Pob_A=norm_inversa(Pob_A)) ->data_po_f1
print(data_po_f1)
## # A tibble: 20 x 6
## Coef_arg C_casa Mort S_IN W_prom Pob_A
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 0.730 0.914 0.946 1 1
## 2 0.648 0.724 0.828 0.984 0.986 0.952
## 3 0.625 0.887 1 1 0.983 0.903
## 4 0.591 0.667 0.871 0.965 0.948 0.862
## 5 0.489 0.755 0.871 0.868 0.849 0.819
## 6 0.511 0.281 0.957 0.763 0.782 0.776
## 7 0.443 0.565 0.700 0.674 0.667 0.728
## 8 0.295 0.487 0.785 0.627 0.547 0.682
## 9 0.261 0.429 0.700 0.694 0.514 0.629
## 10 0.239 0.254 0.528 0.848 0.468 0.574
## 11 0.216 0.564 0.442 0.760 0.435 0.520
## 12 0.227 0.704 0.399 0.687 0.404 0.471
## 13 0.159 1 0.313 0.548 0.347 0.418
## 14 0.136 0.630 0.399 0.419 0.335 0.364
## 15 0.125 0.473 0.185 0.323 0.260 0.312
## 16 0.136 0.456 0.142 0.285 0.166 0.274
## 17 0.114 0.00518 0.142 0.311 0.217 0.214
## 18 0.0568 0.192 0.0987 0.221 0.152 0.152
## 19 0.0227 0.228 0.123 0.0944 0.0893 0.0768
## 20 0 0 0 0 0 0
Ponderadores
funcion_critic2 <- function(pofun) {
# Desviación Típica
desviacion <- apply(pofun,MARGIN = 2,FUN = sd)
# Matriz de Correlación
coeficiente_correlacion<-cor(pofun)
# Ponderadores Brutos
1-coeficiente_correlacion->sum_data
colSums(sum_data)->sum_vector
desviacion * sum_vector->vj
# Ponderadores netos
wj <- vj/sum(vj)
# Ponderadores
ponderadores<-round(wj*100,2)
# Resultados en lista
list(Desviacion_Estandar=desviacion,Ponderadores_Brutos=vj,Ponderadores_Netos=wj,Ponderadores=ponderadores)
}
# Probando la Función
salida_critic2<-funcion_critic2(data_po_f1)
salida_critic2 %>% as.data.frame() %>% kable(caption = "Prueba Función Critic",align = "c",digits = 3) %>% kable_minimal(html_font = "helvetica") %>% kable_styling(bootstrap_options = c("striped","hover"))
Prueba Función Critic
|
Desviacion_Estandar
|
Ponderadores_Brutos
|
Ponderadores_Netos
|
Ponderadores
|
Coef_arg
|
0.260
|
0.230
|
0.142
|
14.17
|
C_casa
|
0.276
|
0.559
|
0.344
|
34.41
|
Mort
|
0.335
|
0.255
|
0.157
|
15.66
|
S_IN
|
0.310
|
0.228
|
0.140
|
14.03
|
W_prom
|
0.325
|
0.188
|
0.116
|
11.57
|
Pob_A
|
0.304
|
0.165
|
0.102
|
10.16
|
Indicador de desigualdad
Carga de datos
ID <- read_excel("C:/Users/Carlos/Desktop/Documentos universidad/EDD 1 Documentos UES/Repaso R studios/Datos preliminares/IndicadorDesigualdad.xlsx")
head(ID, 5)
Año
|
Gini
|
Agua_serv
|
Esp_vida
|
T_empleo
|
H_viv
|
2000
|
33.60
|
98.56452
|
77.88659
|
72.49728
|
33.60
|
2001
|
33.85
|
98.57089
|
78.08780
|
71.96364
|
33.85
|
2002
|
34.65
|
98.57426
|
78.21341
|
71.67298
|
34.65
|
2003
|
34.45
|
98.57765
|
78.38902
|
71.70333
|
34.45
|
2004
|
34.05
|
98.58103
|
78.69024
|
71.83624
|
34.05
|
Definición de indicadores.
Num3<- c(1,2,3,4,5)
Indi3 <- c("Índice de Gini", "Personas que utilizan servicios de agua potable", "Esperanza de vida al nacer", "Tasa de empleo", "Hacinamiento en las viviendas")
Fuente3 <- c("OCDE y WIID", "Banco Mundial", "Banco Mundial","OCDE", "OCDE")
dataf3 <- data.frame(Num3, Indi3, Fuente3)
dataf3
Num3
|
Indi3
|
Fuente3
|
1
|
Índice de Gini
|
OCDE y WIID
|
2
|
Personas que utilizan servicios de agua potable
|
Banco Mundial
|
3
|
Esperanza de vida al nacer
|
Banco Mundial
|
4
|
Tasa de empleo
|
OCDE
|
5
|
Hacinamiento en las viviendas
|
OCDE
|
Resumen estadístico de variables: numérico.
ID3 <- ID[,-1]
summary(ID3[,1:5])
|
Gini
|
Agua_serv
|
Esp_vida
|
T_empleo
|
H_viv
|
|
Min. :33.60
|
Min. :98.56
|
Min. :77.89
|
Min. :68.99
|
Min. :33.60
|
|
1st Qu.:34.65
|
1st Qu.:98.60
|
1st Qu.:78.80
|
1st Qu.:70.06
|
1st Qu.:34.65
|
|
Median :34.85
|
Median :98.73
|
Median :79.79
|
Median :71.69
|
Median :34.85
|
|
Mean :34.86
|
Mean :98.74
|
Mean :79.47
|
Mean :71.18
|
Mean :34.86
|
|
3rd Qu.:35.31
|
3rd Qu.:98.86
|
3rd Qu.:80.24
|
3rd Qu.:72.12
|
3rd Qu.:35.31
|
|
Max. :35.80
|
Max. :98.96
|
Max. :80.32
|
Max. :72.75
|
Max. :35.80
|
Resumen estadístico de variables: gráfico.
boxplot(ID3[,1], xlab= "1", ylab="Índice", main = "Boxplot: Índice de Gini")

boxplot(ID3[,2], xlab= "2", ylab="% de la Población", main = "Boxplot: Personas que utilizan servicios de agua potable")

boxplot(ID3[,3], xlab= "3", ylab="Años", main = "Boxplot: Esperanza de vida al nacer")

boxplot(ID3[,4], xlab= "4", ylab="Porcentaje", main = "Boxplot: Tasa de empleo")

boxplot(ID3[,5], xlab= "5", ylab="Total", main = "Boxplot: Hacinamiento en las viviendas")

Estimación del modelo
options(scipen = 9999)
model_des <- lm(formula = Año~Gini+Agua_serv+Esp_vida+T_empleo+H_viv, data=ID)
stargazer(model_des,title = "Modelo estimado",type = "text",digits = 8)
##
## Modelo estimado
## ================================================
## Dependent variable:
## ----------------------------
## Año
## ------------------------------------------------
## Gini 0.36005300
## (0.38025100)
##
## Agua_serv 27.08406000***
## (2.67517700)
##
## Esp_vida 2.61152900***
## (0.56363950)
##
## T_empleo 0.49828710***
## (0.13331580)
##
## H_viv
##
##
## Constant -920.34550000***
## (221.49440000)
##
## ------------------------------------------------
## Observations 20
## R2 0.99477560
## Adjusted R2 0.99338250
## Residual Std. Error 0.48126200 (df = 15)
## F Statistic 714.04170000*** (df = 4; 15)
## ================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
Jarque Bera
fit_norm_des<- fitdist(data = model_des$residuals, distr = "norm")
plot(fit_norm_des)

jb.norm.test(model_des$residuals)
##
## Jarque-Bera test for normality
##
## data: model_des$residuals
## JB = 0.62573, p-value = 0.632
#Pasó la prueba
Prueba de Kolmogorov Smirnov
lillie.test(model_des$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: model_des$residuals
## D = 0.13912, p-value = 0.394
#Pasó raspada la prueba
Prueba de Shairo-Wilk
shapiro.test(model_des$residuals)
##
## Shapiro-Wilk normality test
##
## data: model_des$residuals
## W = 0.96957, p-value = 0.7458
#Pasó raspada la prueba
Normalizacion de datos estimados
des.mat <- model.matrix(model_des)
des.nor<- scale(des.mat[,-1])
stargazer(head(des.nor, n=6), type="text")
##
## ===========================================
## Gini Agua_serv Esp_vida T_empleo H_viv
## -------------------------------------------
## 1 -2.174 -1.253 -1.851 1.051 -2.174
## 2 -1.744 -1.208 -1.616 0.624 -1.744
## 3 -0.367 -1.184 -1.470 0.391 -0.367
## 4 -0.711 -1.160 -1.264 0.415 -0.711
## 5 -1.399 -1.135 -0.912 0.522 -1.399
## 6 -0.194 -0.940 -0.737 0.642 -0.194
## -------------------------------------------
Construyendo la matriz de correlación
des_Mat_R<-rcorr(as.matrix(des.nor))
stargazer(des_Mat_R$r,type = "text")
##
## ===================================================
## Gini Agua_serv Esp_vida T_empleo H_viv
## ---------------------------------------------------
## Gini 1 0.805 0.858 -0.346 1
## Agua_serv 0.805 1 0.927 -0.273 0.805
## Esp_vida 0.858 0.927 1 -0.509 0.858
## T_empleo -0.346 -0.273 -0.509 1 -0.346
## H_viv 1 0.805 0.858 -0.346 1
## ---------------------------------------------------
corrplot(des_Mat_R$r, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 90, html_font = "sans-serif")

#https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html
p.mat3 <- cor.mtest(des.nor)$p
corrplot(des_Mat_R$r, type = "upper", order = "hclust",
p.mat = p.mat3, sig.level = 0.01, tl.col = "black", html_font = "sans-serif")

library(PerformanceAnalytics)
chart.Correlation(as.matrix(ID[,-1]),histogram = TRUE,pch=19)

Prueba de Farrar-Glaubar, en busca de evidencias de multicolinealidad
library(mctest)
mctest(model_des)
## Warning in summary.lm(lm(x[, i] ~ x[, -i])): essentially perfect fit: summary
## may be unreliable
## Warning in summary.lm(lm(x[, i] ~ x[, -i])): essentially perfect fit: summary
## may be unreliable
## Warning in summary.lm(lm(x[, i] ~ x[, -i])): essentially perfect fit: summary
## may be unreliable
## Warning in summary.lm(lm(x[, i] ~ x[, -i])): essentially perfect fit: summary
## may be unreliable
## Warning in sqrt(max(ev)/ev): Se han producido NaNs
## Warning in sqrt(ordev): Se han producido NaNs
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0000 1
## Farrar Chi-Square: Inf 1
## Red Indicator: 0.7212 1
## Sum of Lambda Inverse: 3983880259828268.5000 1
## Theil's Method: 0.4419 0
## Condition Number: NaN NA
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
# El modelo ha identificado un valor crítico de 18.30704 menor que el valor calculado del estadístico de la prueba chi-cuadrado infinito. El cual resulta, muy significativo, lo que implica la presencia de multicolinealidad en el modelo.
KMO tets
KMO(des.nor)
## Error in solve.default(r) :
## Lapack routine dgesv: system is exactly singular: U[5,5] = 0
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = des.nor)
## Overall MSA = 0.5
## MSA for each item =
## Gini Agua_serv Esp_vida T_empleo H_viv
## 0.5 0.5 0.5 0.5 0.5
#Si el valor:
# KMO > 0.75 ► la idea de realizar análisis factorial es buena
# 0.5 < KMO < 0.75 ► la idea es aceptable
# KMO < 0.5 ► es inaceptable realizar el análisis
Metodologia de ponderacion Critic
modelo_D2<-principal(r = des_Mat_R$r,nfactors = 2,covar = FALSE,rotate = "varimax")
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was done
modelo_D2
## Principal Components Analysis
## Call: principal(r = des_Mat_R$r, nfactors = 2, rotate = "varimax",
## covar = FALSE)
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 h2 u2 com
## Gini 0.95 -0.17 0.93 0.0702 1.1
## Agua_serv 0.92 -0.11 0.87 0.1335 1.0
## Esp_vida 0.90 -0.36 0.94 0.0621 1.3
## T_empleo -0.19 0.98 1.00 0.0019 1.1
## H_viv 0.95 -0.17 0.93 0.0702 1.1
##
## RC1 RC2
## SS loadings 3.51 1.16
## Proportion Var 0.70 0.23
## Cumulative Var 0.70 0.93
## Proportion Explained 0.75 0.25
## Cumulative Proportion 0.75 1.00
##
## Mean item complexity = 1.1
## Test of the hypothesis that 2 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.06
##
## Fit based upon off diagonal values = 0.99
Al incorporar el factor 2 la varianza acumulada alcanza a explicar el 100% del modelo, pero los indicadores poseen una predominancia de explicación en el factor 1, por otra parte el 100% de los indicadores alcanza un nivel de comunalidad de explicación por encima del 85%.
Correlación de los componentes con las variables: \(rij=aj⋅λ−−√j\)
# Normalizando los datos
norm_directa <- function(x){
return((x-min(x)) / (max(x)-min(x)))
}
norm_inversa <- function(x){
return((max(x)-x) / (max(x)-min(x)))
}
ID[,-1] %>% dplyr::select(Gini, Agua_serv, Esp_vida, T_empleo, H_viv)%>%dplyr::transmute(Gini=norm_directa(Gini),Agua_serv=norm_inversa(Agua_serv), Esp_vida=norm_inversa(Esp_vida), T_empleo=norm_inversa(T_empleo),H_viv=norm_inversa(H_viv)) ->data_des_f1
print(data_des_f1)
## # A tibble: 20 x 5
## Gini Agua_serv Esp_vida T_empleo H_viv
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0 1 1 0.0683 1
## 2 0.114 0.984 0.917 0.210 0.886
## 3 0.477 0.976 0.866 0.287 0.523
## 4 0.386 0.967 0.794 0.279 0.614
## 5 0.205 0.959 0.670 0.244 0.795
## 6 0.523 0.890 0.608 0.204 0.477
## 7 0.636 0.822 0.536 0.107 0.364
## 8 0.477 0.752 0.433 0.0534 0.523
## 9 0.477 0.682 0.392 0.169 0.523
## 10 0.523 0.613 0.258 0.879 0.477
## 11 0.545 0.544 0.175 1 0.455
## 12 0.682 0.475 0.113 0.949 0.318
## 13 0.773 0.409 0.0516 0.856 0.227
## 14 1 0.344 0.0311 0.778 0
## 15 0.795 0.278 0 0.694 0.205
## 16 0.818 0.212 0.0105 0.590 0.182
## 17 0.591 0.146 0.0416 0.508 0.409
## 18 0.636 0.0795 0.0316 0.298 0.364
## 19 0.892 0.0589 0.0316 0.166 0.108
## 20 0.930 0 0.0230 0 0.0701
Ponderadores
funcion_critic3 <- function(desfun) {
# Desviación Típica
desviacion <- apply(desfun,MARGIN = 2,FUN = sd)
# Matriz de Correlación
coeficiente_correlacion<-cor(desfun)
# Ponderadores Brutos
1-coeficiente_correlacion->sum_data
colSums(sum_data)->sum_vector
desviacion * sum_vector->vj
# Ponderadores netos
wj <- vj/sum(vj)
# Ponderadores
ponderadores<-round(wj*100,2)
# Resultados en lista
list(Desviacion_Estandar=desviacion,Ponderadores_Brutos=vj,Ponderadores_Netos=wj,Ponderadores=ponderadores)
}
# Probando la Función
salida_critic3<-funcion_critic3(data_des_f1)
salida_critic3 %>% as.data.frame() %>% kable(caption = "Prueba Función Critic",align = "c",digits = 3) %>% kable_minimal(html_font = "helvetica") %>% kable_styling(bootstrap_options = c("striped","hover"))
Prueba Función Critic
|
Desviacion_Estandar
|
Ponderadores_Brutos
|
Ponderadores_Netos
|
Ponderadores
|
Gini
|
0.264
|
1.668
|
0.250
|
25.04
|
Agua_serv
|
0.352
|
1.176
|
0.177
|
17.66
|
Esp_vida
|
0.352
|
1.259
|
0.189
|
18.90
|
T_empleo
|
0.332
|
1.587
|
0.238
|
23.82
|
H_viv
|
0.264
|
0.972
|
0.146
|
14.60
|