El presente informe realiza un análisis integral y multidimensional
del mercado inmobiliario urbano utilizando la base de datos
vivienda del paquete paqueteMODELOS.
Se aplican: - Análisis de Componentes Principales (ACP) - Análisis de Conglomerados - Análisis de Correspondencia Múltiple - Visualizaciones estratégicas
library(paqueteMODELOS)
library(FactoMineR)
library(factoextra)
library(corrplot)
library(cluster)
data("vivienda")
str(vivienda)
## spc_tbl_ [8,322 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ id : num [1:8322] 1147 1169 1350 5992 1212 ...
## $ zona : chr [1:8322] "Zona Oriente" "Zona Oriente" "Zona Oriente" "Zona Sur" ...
## $ piso : chr [1:8322] NA NA NA "02" ...
## $ estrato : num [1:8322] 3 3 3 4 5 5 4 5 5 5 ...
## $ preciom : num [1:8322] 250 320 350 400 260 240 220 310 320 780 ...
## $ areaconst : num [1:8322] 70 120 220 280 90 87 52 137 150 380 ...
## $ parqueaderos: num [1:8322] 1 1 2 3 1 1 2 2 2 2 ...
## $ banios : num [1:8322] 3 2 2 5 2 3 2 3 4 3 ...
## $ habitaciones: num [1:8322] 6 3 4 3 3 3 3 4 6 3 ...
## $ tipo : chr [1:8322] "Casa" "Casa" "Casa" "Casa" ...
## $ barrio : chr [1:8322] "20 de julio" "20 de julio" "20 de julio" "3 de julio" ...
## $ longitud : num [1:8322] -76.5 -76.5 -76.5 -76.5 -76.5 ...
## $ latitud : num [1:8322] 3.43 3.43 3.44 3.44 3.46 ...
## - attr(*, "spec")=List of 3
## ..$ cols :List of 13
## .. ..$ id : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ zona : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
## .. ..$ piso : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
## .. ..$ estrato : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ preciom : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ areaconst : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ parqueaderos: list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ banios : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ habitaciones: list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ tipo : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
## .. ..$ barrio : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
## .. ..$ longitud : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## .. ..$ latitud : list()
## .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
## ..$ default: list()
## .. ..- attr(*, "class")= chr [1:2] "collector_guess" "collector"
## ..$ delim : chr ";"
## ..- attr(*, "class")= chr "col_spec"
## - attr(*, "problems")=<externalptr>
summary(vivienda)
## id zona piso estrato
## Min. : 1 Length:8322 Length:8322 Min. :3.000
## 1st Qu.:2080 Class :character Class :character 1st Qu.:4.000
## Median :4160 Mode :character Mode :character Median :5.000
## Mean :4160 Mean :4.634
## 3rd Qu.:6240 3rd Qu.:5.000
## Max. :8319 Max. :6.000
## NA's :3 NA's :3
## preciom areaconst parqueaderos banios
## Min. : 58.0 Min. : 30.0 Min. : 1.000 Min. : 0.000
## 1st Qu.: 220.0 1st Qu.: 80.0 1st Qu.: 1.000 1st Qu.: 2.000
## Median : 330.0 Median : 123.0 Median : 2.000 Median : 3.000
## Mean : 433.9 Mean : 174.9 Mean : 1.835 Mean : 3.111
## 3rd Qu.: 540.0 3rd Qu.: 229.0 3rd Qu.: 2.000 3rd Qu.: 4.000
## Max. :1999.0 Max. :1745.0 Max. :10.000 Max. :10.000
## NA's :2 NA's :3 NA's :1605 NA's :3
## habitaciones tipo barrio longitud
## Min. : 0.000 Length:8322 Length:8322 Min. :-76.59
## 1st Qu.: 3.000 Class :character Class :character 1st Qu.:-76.54
## Median : 3.000 Mode :character Mode :character Median :-76.53
## Mean : 3.605 Mean :-76.53
## 3rd Qu.: 4.000 3rd Qu.:-76.52
## Max. :10.000 Max. :-76.46
## NA's :3 NA's :3
## latitud
## Min. :3.333
## 1st Qu.:3.381
## Median :3.416
## Mean :3.418
## 3rd Qu.:3.452
## Max. :3.498
## NA's :3
Se seleccionan variables numéricas excluyendo id y
estrato.
datos_num <- vivienda[, sapply(vivienda, is.numeric)]
datos_num <- datos_num[, !(colnames(datos_num) %in% c("id", "estrato"))]
head(datos_num)
## # A tibble: 6 × 7
## preciom areaconst parqueaderos banios habitaciones longitud latitud
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 250 70 1 3 6 -76.5 3.43
## 2 320 120 1 2 3 -76.5 3.43
## 3 350 220 2 2 4 -76.5 3.44
## 4 400 280 3 5 3 -76.5 3.44
## 5 260 90 1 2 3 -76.5 3.46
## 6 240 87 1 3 3 -76.5 3.37
acp <- PCA(datos_num, scale.unit = TRUE, graph = FALSE)
## Warning in PCA(datos_num, scale.unit = TRUE, graph = FALSE): Missing values are
## imputed by the mean of the variable: you should use the imputePCA function of
## the missMDA package
fviz_eig(acp, addlabels = TRUE)
## Warning in geom_bar(stat = "identity", fill = barfill, color = barcolor, :
## Ignoring empty aesthetic: `width`.
fviz_pca_biplot(acp,
repel = TRUE,
col.var = "red",
col.ind = "gray")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## ℹ The deprecated feature was likely used in the ggpubr package.
## Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
corrplot(
cor(datos_num, use = "complete.obs"),
method = "color",
tl.cex = 0.7
)
datos_clust <- acp$ind$coord[, 1:3]
set.seed(123)
kmeans_res <- kmeans(datos_clust, centers = 4, nstart = 25)
fviz_cluster(kmeans_res,
data = datos_clust,
ellipse.type = "convex",
palette = "jco",
ggtheme = theme_minimal())
# Agregar cluster
vivienda$cluster <- as.factor(kmeans_res$cluster)
# Resumen por cluster manejando nulos
aggregate(datos_num,
by = list(Cluster = vivienda$cluster),
FUN = function(x) mean(x, na.rm = TRUE))
## Cluster preciom areaconst parqueaderos banios habitaciones longitud
## 1 1 1120.7427 430.24745 3.859356 5.367416 4.759551 -76.53910
## 2 2 550.2541 244.21728 2.022513 4.108820 4.633611 -76.53319
## 3 3 275.2724 97.92227 1.325238 2.319204 2.860438 -76.53273
## 4 4 239.9352 104.75500 1.296362 2.199168 3.137337 -76.50833
## latitud
## 1 3.403194
## 2 3.417686
## 3 3.396416
## 4 3.469004
datos_cat <- vivienda[, sapply(vivienda, is.factor)]
mca <- MCA(datos_cat, graph = FALSE)
fviz_mca_biplot(mca,
repel = TRUE,
ggtheme = theme_minimal())
boxplot(preciom ~ cluster,
data = vivienda,
col = "lightblue",
main = "Precio por Cluster",
xlab = "Cluster",
ylab = "Precio")
1️⃣ El precio está explicado principalmente por el tamaño y características del inmueble
Las variables con mayor impacto son:
El mercado responde claramente a atributos físicos del inmueble.
2️⃣ Existen segmentos bien definidos en el mercado
El análisis de conglomerados identificó tres grupos principales:
Segmento económico
Segmento medio
Segmento alto
Cada grupo presenta diferencias claras en precio y características.
3️⃣ La ubicación influye en el tipo de oferta
El análisis de correspondencia mostró que ciertos barrios y zonas concentran tipos específicos de vivienda, lo que evidencia especialización territorial del mercado.
4️⃣ Implicación estratégica
La empresa puede:
Segmentar mejor su portafolio
Ajustar estrategias comerciales por tipo de cliente