La base de datos contiene información sobre el tipo de contrato de los profesores de educación superior del año 2007 al 2013. La variables son:
distancia <- get_dist(datos, stand = TRUE, method = "euclidean")
round(distancia,2)
## AMAZONAS ANTIOQUIA ARAUCA ATLANTICO BOGOTA D.C.
## ANTIOQUIA 3.63
## ARAUCA 0.00 3.63
## ATLANTICO 1.10 2.69 1.10
## BOGOTA D.C. 10.45 7.14 10.46 9.47
## BOLIVAR 0.59 3.09 0.60 0.52 9.92
## BOYACA 0.63 3.14 0.63 0.63 9.94
## CALDAS 0.63 3.12 0.63 0.53 9.88
## CAQUETA 0.11 3.53 0.11 1.01 10.37
## CASANARE 0.03 3.61 0.03 1.09 10.43
## CAUCA 0.38 3.34 0.38 0.81 10.14
## CESAR 0.15 3.49 0.15 0.96 10.33
## CHOCO 0.17 3.47 0.17 0.97 10.32
## CORDOBA 0.26 3.39 0.26 0.88 10.22
## CUNDINAMARCA 0.42 3.21 0.43 0.77 10.07
## HUILA 0.22 3.43 0.22 0.95 10.25
## LA GUAJIRA 0.10 3.53 0.11 1.03 10.37
## MAGDALENA 0.26 3.38 0.27 0.90 10.24
## META 0.10 3.54 0.10 1.02 10.37
## NARIÑO 0.35 3.35 0.35 0.76 10.17
## NORTE DE SANTANDER 0.69 3.07 0.69 0.83 9.84
## PUTUMAYO 0.02 3.62 0.02 1.10 10.45
## QUINDIO 0.31 3.35 0.31 0.80 10.16
## RISARALDA 0.39 3.27 0.39 0.75 10.11
## SAN ANDRES Y PROVIDENCIA 0.00 3.63 0.01 1.10 10.45
## SANTANDER 1.32 2.38 1.32 0.57 9.14
## SUCRE 0.11 3.52 0.12 1.00 10.36
## TOLIMA 0.29 3.38 0.30 0.92 10.20
## VALLE DEL CAUCA 5.65 5.74 5.65 5.47 10.41
## BOLIVAR BOYACA CALDAS CAQUETA CASANARE CAUCA CESAR
## ANTIOQUIA
## ARAUCA
## ATLANTICO
## BOGOTA D.C.
## BOLIVAR
## BOYACA 0.35
## CALDAS 0.25 0.23
## CAQUETA 0.50 0.53 0.54
## CASANARE 0.58 0.62 0.62 0.10
## CAUCA 0.38 0.26 0.31 0.29 0.37
## CESAR 0.45 0.51 0.51 0.06 0.14 0.28
## CHOCO 0.46 0.50 0.53 0.08 0.16 0.28 0.07
## CORDOBA 0.38 0.39 0.41 0.15 0.24 0.16 0.13
## CUNDINAMARCA 0.29 0.36 0.38 0.33 0.41 0.25 0.29
## HUILA 0.44 0.48 0.48 0.15 0.20 0.24 0.14
## LA GUAJIRA 0.52 0.55 0.57 0.05 0.09 0.31 0.09
## MAGDALENA 0.38 0.46 0.48 0.17 0.25 0.27 0.14
## META 0.51 0.53 0.54 0.03 0.09 0.28 0.08
## NARIÑO 0.27 0.38 0.33 0.27 0.34 0.24 0.22
## NORTE DE SANTANDER 0.53 0.48 0.48 0.61 0.67 0.45 0.60
## PUTUMAYO 0.59 0.62 0.63 0.10 0.02 0.38 0.14
## QUINDIO 0.31 0.35 0.33 0.22 0.30 0.14 0.18
## RISARALDA 0.27 0.29 0.32 0.28 0.38 0.16 0.25
## SAN ANDRES Y PROVIDENCIA 0.59 0.63 0.63 0.10 0.02 0.38 0.15
## SANTANDER 0.82 0.85 0.79 1.23 1.30 1.01 1.19
## SUCRE 0.49 0.53 0.54 0.02 0.10 0.29 0.05
## TOLIMA 0.44 0.41 0.44 0.21 0.27 0.17 0.21
## VALLE DEL CAUCA 5.52 5.52 5.53 5.62 5.65 5.57 5.61
## CHOCO CORDOBA CUNDINAMARCA HUILA LA GUAJIRA MAGDALENA
## ANTIOQUIA
## ARAUCA
## ATLANTICO
## BOGOTA D.C.
## BOLIVAR
## BOYACA
## CALDAS
## CAQUETA
## CASANARE
## CAUCA
## CESAR
## CHOCO
## CORDOBA 0.12
## CUNDINAMARCA 0.26 0.19
## HUILA 0.13 0.11 0.24
## LA GUAJIRA 0.08 0.17 0.32 0.13
## MAGDALENA 0.10 0.11 0.17 0.14 0.17
## META 0.10 0.16 0.34 0.14 0.05 0.19
## NARIÑO 0.26 0.20 0.27 0.27 0.30 0.23
## NORTE DE SANTANDER 0.58 0.49 0.40 0.48 0.60 0.52
## PUTUMAYO 0.16 0.25 0.41 0.21 0.09 0.25
## QUINDIO 0.20 0.09 0.20 0.17 0.24 0.17
## RISARALDA 0.24 0.14 0.12 0.24 0.30 0.18
## SAN ANDRES Y PROVIDENCIA 0.17 0.25 0.42 0.22 0.10 0.26
## SANTANDER 1.18 1.08 0.93 1.11 1.23 1.10
## SUCRE 0.06 0.15 0.31 0.14 0.04 0.16
## TOLIMA 0.19 0.12 0.22 0.11 0.20 0.19
## VALLE DEL CAUCA 5.60 5.58 5.54 5.59 5.62 5.58
## META NARIÑO NORTE DE SANTANDER PUTUMAYO QUINDIO
## ANTIOQUIA
## ARAUCA
## ATLANTICO
## BOGOTA D.C.
## BOLIVAR
## BOYACA
## CALDAS
## CAQUETA
## CASANARE
## CAUCA
## CESAR
## CHOCO
## CORDOBA
## CUNDINAMARCA
## HUILA
## LA GUAJIRA
## MAGDALENA
## META
## NARIÑO 0.28
## NORTE DE SANTANDER 0.61 0.58
## PUTUMAYO 0.10 0.34 0.68
## QUINDIO 0.22 0.13 0.48 0.30
## RISARALDA 0.29 0.18 0.46 0.38 0.12
## SAN ANDRES Y PROVIDENCIA 0.10 0.35 0.69 0.01 0.31
## SANTANDER 1.23 1.05 0.75 1.31 1.03
## SUCRE 0.04 0.26 0.61 0.11 0.21
## TOLIMA 0.20 0.29 0.41 0.29 0.17
## VALLE DEL CAUCA 5.62 5.58 5.51 5.65 5.57
## RISARALDA SAN ANDRES Y PROVIDENCIA SANTANDER SUCRE
## ANTIOQUIA
## ARAUCA
## ATLANTICO
## BOGOTA D.C.
## BOLIVAR
## BOYACA
## CALDAS
## CAQUETA
## CASANARE
## CAUCA
## CESAR
## CHOCO
## CORDOBA
## CUNDINAMARCA
## HUILA
## LA GUAJIRA
## MAGDALENA
## META
## NARIÑO
## NORTE DE SANTANDER
## PUTUMAYO
## QUINDIO
## RISARALDA
## SAN ANDRES Y PROVIDENCIA 0.39
## SANTANDER 0.97 1.32
## SUCRE 0.28 0.11 1.22
## TOLIMA 0.21 0.29 1.06 0.21
## VALLE DEL CAUCA 5.55 5.65 5.42 5.62
## TOLIMA
## ANTIOQUIA
## ARAUCA
## ATLANTICO
## BOGOTA D.C.
## BOLIVAR
## BOYACA
## CALDAS
## CAQUETA
## CASANARE
## CAUCA
## CESAR
## CHOCO
## CORDOBA
## CUNDINAMARCA
## HUILA
## LA GUAJIRA
## MAGDALENA
## META
## NARIÑO
## NORTE DE SANTANDER
## PUTUMAYO
## QUINDIO
## RISARALDA
## SAN ANDRES Y PROVIDENCIA
## SANTANDER
## SUCRE
## TOLIMA
## VALLE DEL CAUCA 5.58
class(distancia)
## [1] "dist"
as.matrix(distancia)[1:5,1:5]
## AMAZONAS ANTIOQUIA ARAUCA ATLANTICO BOGOTA D.C.
## AMAZONAS 0.00000000 3.629990 0.00415787 1.101763 10.453496
## ANTIOQUIA 3.62999041 0.000000 3.63232589 2.693064 7.139938
## ARAUCA 0.00415787 3.632326 0.00000000 1.104310 10.455808
## ATLANTICO 1.10176257 2.693064 1.10430951 0.000000 9.473014
## BOGOTA D.C. 10.45349574 7.139938 10.45580759 9.473014 0.000000
fviz_dist(distancia, gradient = list(low = "#00AFBB", mid = "white", high = "#FC4E07"))
hc1 = hclust(distancia, method = "single")
plot(hc1, hang = -1)
abline(h=0.5,col="red",lty=2)
fviz_dend (hc1, k = 4, cex = 0.5, k_colors = "npg", color_labels_by_k = TRUE, rect = TRUE )
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
hc2 = hclust(distancia, method = "complete")
plot(hc2, hang = -1)
abline(h=0.5,col="red",lty=2)
fviz_dend (hc2, k = 4, cex = 0.5, k_colors = "npg", color_labels_by_k = TRUE, rect = TRUE )
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
hc3 = hclust(distancia, method = "average")
plot(hc3, hang = -1)
abline(h=0.5,col="red",lty=2)
fviz_dend (hc3, k = 4, cex = 0.5, k_colors = "npg", color_labels_by_k = TRUE, rect = TRUE )
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
Bajo los tres métodos se identifican los conglomerados de manera clara, en este caso Bogotá, Valle del cauca, antioquia y el resto de departamentos conforman los conglomerados más adecuados, por sus marcadas diferencias.
fviz_nbclust(datos,kmeans,method = "wss")+
geom_vline(xintercept = NULL, linetype=2)
set.seed(123) ## Semilla
km.res=kmeans(datos,4,nstart = 25)
print(km.res)
## K-means clustering with 4 clusters of sizes 1, 3, 1, 24
##
## Cluster means:
## Cátedra Medio tiempo No informa Parcial Tiempo completo
## 1 20830.0000 4918.00000 0.000000 2775.00000 11526.000
## 2 3307.0000 547.00000 1.333333 218.00000 1758.667
## 3 11014.0000 1339.00000 0.000000 573.00000 3830.000
## 4 529.9583 90.16667 0.000000 34.29167 373.250
##
## Clustering vector:
## AMAZONAS ANTIOQUIA ARAUCA
## 4 3 4
## ATLANTICO BOGOTA D.C. BOLIVAR
## 2 1 4
## BOYACA CALDAS CAQUETA
## 4 4 4
## CASANARE CAUCA CESAR
## 4 4 4
## CHOCO CORDOBA CUNDINAMARCA
## 4 4 4
## HUILA LA GUAJIRA MAGDALENA
## 4 4 4
## META NARIÑO NORTE DE SANTANDER
## 4 4 4
## PUTUMAYO QUINDIO RISARALDA
## 4 4 4
## SAN ANDRES Y PROVIDENCIA SANTANDER SUCRE
## 4 2 4
## TOLIMA VALLE DEL CAUCA
## 4 2
##
## Within cluster sum of squares by cluster:
## [1] 0 5129755 0 6849080
## (between_SS / total_SS = 98.2 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
km.res$size
## [1] 1 3 1 24
dd=cbind(datos,cluster=km.res$cluster) ## Agregar la clasificación
head(dd)
## Cátedra Medio tiempo No informa Parcial Tiempo completo cluster
## AMAZONAS 2 0 0 0 11 4
## ANTIOQUIA 11014 1339 0 573 3830 3
## ARAUCA 0 0 0 0 2 4
## ATLANTICO 1989 708 0 66 1371 2
## BOGOTA D.C. 20830 4918 0 2775 11526 1
## BOLIVAR 1385 365 0 29 653 4
fviz_cluster(km.res, data = datos, palette=c("#2E9FDF","#00AFBB","#E7B800","#FC4E07"),ellipse.type = "euclide", star.plot= TRUE, repel = TRUE,
ggtheme = theme_minimal())
## Warning: ggrepel: 26 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
Los conglomerados formados siendo: 1. Bogotá; 2. Valle del cauca, Atlantico y Santander; 3. Antioquia; 4. El resto de departamentos del pais.
Las diferencias entre estos 4 grupos son marcadas, por ejemplo en la variable tiempo completo la diferencia es casi un tercera parte en entre el grupo 1 y 3.
Lo que muestran los grupos conformados son las grandes diferencias que tenemos respecto a la contratación de profesores en las diferentes regiones del país con marcadas diferencias en la ciudades principales y las llamadas intermedias.