1 1. Librerías

# Instalar solo la primera vez
# install.packages("devtools")
# install.packages("leaflet")
# install.packages("plotly")
# install.packages("lmtest")
# install.packages("car")
# install.packages("dplyr")

library(devtools)
## Warning: package 'devtools' was built under R version 4.5.2
## Cargando paquete requerido: usethis
## Warning: package 'usethis' was built under R version 4.5.2
library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.5.2
library(plotly)
## Cargando paquete requerido: ggplot2
## Warning: package 'ggplot2' was built under R version 4.5.2
## 
## Adjuntando el paquete: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.5.2
## Cargando paquete requerido: zoo
## 
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(car)
## Cargando paquete requerido: carData
## 
## Adjuntando el paquete: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
devtools::install_github("centromagis/paqueteMODELOS", force = TRUE)
## WARNING: Rtools is required to build R packages, but is not currently installed.
## 
## Please download and install Rtools 4.5 from https://cran.r-project.org/bin/windows/Rtools/.
## Downloading GitHub repo centromagis/paqueteMODELOS@HEAD
## vctrs        (0.6.5        -> 0.7.1       ) [CRAN]
## tibble       (3.3.0        -> 3.3.1       ) [CRAN]
## rlang        (1.1.6        -> 1.1.7       ) [CRAN]
## purrr        (1.0.4        -> 1.2.1       ) [CRAN]
## magrittr     (2.0.3        -> 2.0.4       ) [CRAN]
## dplyr        (1.1.4        -> 1.2.0       ) [CRAN]
## Rcpp         (1.0.14       -> 1.1.1       ) [CRAN]
## digest       (0.6.37       -> 0.6.39      ) [CRAN]
## reshape2     (1.4.4        -> 1.4.5       ) [CRAN]
## curl         (6.4.0        -> 7.0.0       ) [CRAN]
## timechange   (0.3.0        -> 0.4.0       ) [CRAN]
## base64enc    (0.1-3        -> 0.1-6       ) [CRAN]
## xfun         (0.52         -> 0.56        ) [CRAN]
## tidyr        (1.3.1        -> 1.3.2       ) [CRAN]
## magick       (2.8.7        -> 2.9.1       ) [CRAN]
## lubridate    (1.9.4        -> 1.9.5       ) [CRAN]
## htmltools    (0.5.8.1      -> 0.5.9       ) [CRAN]
## checkmate    (2.3.2        -> 2.3.4       ) [CRAN]
## yaml         (2.3.10       -> 2.3.12      ) [CRAN]
## summarytools (99f53a2b7... -> 2b613cfb9...) [GitHub]
## Installing 19 packages: vctrs, tibble, rlang, purrr, magrittr, dplyr, Rcpp, digest, reshape2, curl, timechange, base64enc, xfun, tidyr, magick, lubridate, htmltools, checkmate, yaml
## Warning: package 'dplyr' is in use and will not be installed
## Installing packages into 'C:/Users/bohor/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'vctrs' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'vctrs'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\vctrs\libs\x64\vctrs.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\vctrs\libs\x64\vctrs.dll:
## Permission denied
## Warning: restored 'vctrs'
## package 'tibble' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'tibble'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\tibble\libs\x64\tibble.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\tibble\libs\x64\tibble.dll:
## Permission denied
## Warning: restored 'tibble'
## package 'rlang' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'rlang'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\rlang\libs\x64\rlang.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\rlang\libs\x64\rlang.dll:
## Permission denied
## Warning: restored 'rlang'
## package 'purrr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'purrr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\purrr\libs\x64\purrr.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\purrr\libs\x64\purrr.dll:
## Permission denied
## Warning: restored 'purrr'
## package 'magrittr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'magrittr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\magrittr\libs\x64\magrittr.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\magrittr\libs\x64\magrittr.dll:
## Permission denied
## Warning: restored 'magrittr'
## package 'Rcpp' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'Rcpp'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\Rcpp\libs\x64\Rcpp.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\Rcpp\libs\x64\Rcpp.dll:
## Permission denied
## Warning: restored 'Rcpp'
## package 'digest' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'digest'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\digest\libs\x64\digest.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\digest\libs\x64\digest.dll:
## Permission denied
## Warning: restored 'digest'
## package 'reshape2' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'reshape2'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\reshape2\libs\x64\reshape2.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\reshape2\libs\x64\reshape2.dll:
## Permission denied
## Warning: restored 'reshape2'
## package 'curl' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'curl'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\curl\libs\x64\curl.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\curl\libs\x64\curl.dll:
## Permission denied
## Warning: restored 'curl'
## package 'timechange' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'timechange'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\timechange\libs\x64\timechange.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\timechange\libs\x64\timechange.dll:
## Permission denied
## Warning: restored 'timechange'
## package 'base64enc' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'base64enc'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\base64enc\libs\x64\base64enc.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\base64enc\libs\x64\base64enc.dll:
## Permission denied
## Warning: restored 'base64enc'
## package 'xfun' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'xfun'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\xfun\libs\x64\xfun.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\xfun\libs\x64\xfun.dll:
## Permission denied
## Warning: restored 'xfun'
## package 'tidyr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'tidyr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\tidyr\libs\x64\tidyr.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\tidyr\libs\x64\tidyr.dll:
## Permission denied
## Warning: restored 'tidyr'
## package 'magick' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'magick'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\magick\libs\x64\magick.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\magick\libs\x64\magick.dll:
## Permission denied
## Warning: restored 'magick'
## package 'lubridate' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'lubridate'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\lubridate\libs\x64\lubridate.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\lubridate\libs\x64\lubridate.dll:
## Permission denied
## Warning: restored 'lubridate'
## package 'htmltools' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'htmltools'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\htmltools\libs\x64\htmltools.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\htmltools\libs\x64\htmltools.dll:
## Permission denied
## Warning: restored 'htmltools'
## package 'checkmate' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'checkmate'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\checkmate\libs\x64\checkmate.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\checkmate\libs\x64\checkmate.dll:
## Permission denied
## Warning: restored 'checkmate'
## package 'yaml' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'yaml'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\yaml\libs\x64\yaml.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\yaml\libs\x64\yaml.dll:
## Permission denied
## Warning: restored 'yaml'
## 
## The downloaded binary packages are in
##  C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\downloaded_packages
## Downloading GitHub repo dcomtois/summarytools@HEAD
## rlang      (1.1.6   -> 1.1.7 ) [CRAN]
## vctrs      (0.6.5   -> 0.7.1 ) [CRAN]
## magrittr   (2.0.3   -> 2.0.4 ) [CRAN]
## tibble     (3.3.0   -> 3.3.1 ) [CRAN]
## Rcpp       (1.0.14  -> 1.1.1 ) [CRAN]
## digest     (0.6.37  -> 0.6.39) [CRAN]
## purrr      (1.0.4   -> 1.2.1 ) [CRAN]
## dplyr      (1.1.4   -> 1.2.0 ) [CRAN]
## reshape2   (1.4.4   -> 1.4.5 ) [CRAN]
## curl       (6.4.0   -> 7.0.0 ) [CRAN]
## timechange (0.3.0   -> 0.4.0 ) [CRAN]
## base64enc  (0.1-3   -> 0.1-6 ) [CRAN]
## tidyr      (1.3.1   -> 1.3.2 ) [CRAN]
## magick     (2.8.7   -> 2.9.1 ) [CRAN]
## lubridate  (1.9.4   -> 1.9.5 ) [CRAN]
## htmltools  (0.5.8.1 -> 0.5.9 ) [CRAN]
## checkmate  (2.3.2   -> 2.3.4 ) [CRAN]
## Installing 17 packages: rlang, vctrs, magrittr, tibble, Rcpp, digest, purrr, dplyr, reshape2, curl, timechange, base64enc, tidyr, magick, lubridate, htmltools, checkmate
## Warning: package 'dplyr' is in use and will not be installed
## Installing packages into 'C:/Users/bohor/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'rlang' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'rlang'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\rlang\libs\x64\rlang.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\rlang\libs\x64\rlang.dll:
## Permission denied
## Warning: restored 'rlang'
## package 'vctrs' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'vctrs'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\vctrs\libs\x64\vctrs.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\vctrs\libs\x64\vctrs.dll:
## Permission denied
## Warning: restored 'vctrs'
## package 'magrittr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'magrittr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\magrittr\libs\x64\magrittr.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\magrittr\libs\x64\magrittr.dll:
## Permission denied
## Warning: restored 'magrittr'
## package 'tibble' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'tibble'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\tibble\libs\x64\tibble.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\tibble\libs\x64\tibble.dll:
## Permission denied
## Warning: restored 'tibble'
## package 'Rcpp' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'Rcpp'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\Rcpp\libs\x64\Rcpp.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\Rcpp\libs\x64\Rcpp.dll:
## Permission denied
## Warning: restored 'Rcpp'
## package 'digest' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'digest'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\digest\libs\x64\digest.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\digest\libs\x64\digest.dll:
## Permission denied
## Warning: restored 'digest'
## package 'purrr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'purrr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\purrr\libs\x64\purrr.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\purrr\libs\x64\purrr.dll:
## Permission denied
## Warning: restored 'purrr'
## package 'reshape2' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'reshape2'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\reshape2\libs\x64\reshape2.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\reshape2\libs\x64\reshape2.dll:
## Permission denied
## Warning: restored 'reshape2'
## package 'curl' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'curl'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\curl\libs\x64\curl.dll a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\curl\libs\x64\curl.dll:
## Permission denied
## Warning: restored 'curl'
## package 'timechange' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'timechange'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\timechange\libs\x64\timechange.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\timechange\libs\x64\timechange.dll:
## Permission denied
## Warning: restored 'timechange'
## package 'base64enc' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'base64enc'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\base64enc\libs\x64\base64enc.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\base64enc\libs\x64\base64enc.dll:
## Permission denied
## Warning: restored 'base64enc'
## package 'tidyr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'tidyr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\tidyr\libs\x64\tidyr.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\tidyr\libs\x64\tidyr.dll:
## Permission denied
## Warning: restored 'tidyr'
## package 'magick' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'magick'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\magick\libs\x64\magick.dll
## a C:\Users\bohor\AppData\Local\R\win-library\4.5\magick\libs\x64\magick.dll:
## Permission denied
## Warning: restored 'magick'
## package 'lubridate' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'lubridate'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\lubridate\libs\x64\lubridate.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\lubridate\libs\x64\lubridate.dll:
## Permission denied
## Warning: restored 'lubridate'
## package 'htmltools' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'htmltools'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\htmltools\libs\x64\htmltools.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\htmltools\libs\x64\htmltools.dll:
## Permission denied
## Warning: restored 'htmltools'
## package 'checkmate' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'checkmate'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\bohor\AppData\Local\R\win-library\4.5\00LOCK\checkmate\libs\x64\checkmate.dll
## a
## C:\Users\bohor\AppData\Local\R\win-library\4.5\checkmate\libs\x64\checkmate.dll:
## Permission denied
## Warning: restored 'checkmate'
## 
## The downloaded binary packages are in
##  C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\downloaded_packages
## ── R CMD build ─────────────────────────────────────────────────────────────────
## WARNING: Rtools is required to build R packages, but is not currently installed.
## 
## Please download and install Rtools 4.5 from https://cran.r-project.org/bin/windows/Rtools/.
##          checking for file 'C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\remotes2f0c52992b28\dcomtois-summarytools-2b613cf/DESCRIPTION' ...  ✔  checking for file 'C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\remotes2f0c52992b28\dcomtois-summarytools-2b613cf/DESCRIPTION' (340ms)
##       ─  preparing 'summarytools': (3.7s)
##    checking DESCRIPTION meta-information ...  ✔  checking DESCRIPTION meta-information
##       ─  checking for LF line-endings in source and make files and shell scripts (340ms)
##   ─  checking for empty or unneeded directories
##       ─  building 'summarytools_1.1.5.tar.gz' (514ms)
##      
## 
## Installing package into 'C:/Users/bohor/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## ── R CMD build ─────────────────────────────────────────────────────────────────
## WARNING: Rtools is required to build R packages, but is not currently installed.
## 
## Please download and install Rtools 4.5 from https://cran.r-project.org/bin/windows/Rtools/.
##          checking for file 'C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\remotes2f0c15cd7e89\Centromagis-paqueteMODELOS-3b06257/DESCRIPTION' ...  ✔  checking for file 'C:\Users\bohor\AppData\Local\Temp\RtmpI9ZjE4\remotes2f0c15cd7e89\Centromagis-paqueteMODELOS-3b06257/DESCRIPTION' (343ms)
##       ─  preparing 'paqueteMODELOS': (6.2s)
##    checking DESCRIPTION meta-information ...  ✔  checking DESCRIPTION meta-information
##       ─  checking for LF line-endings in source and make files and shell scripts
##   ─  checking for empty or unneeded directories
##       ─  building 'paqueteMODELOS_0.1.0.tar.gz'
##      
## 
## Installing package into 'C:/Users/bohor/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
library(paqueteMODELOS)
## Cargando paquete requerido: boot
## 
## Adjuntando el paquete: 'boot'
## The following object is masked from 'package:car':
## 
##     logit
## Cargando paquete requerido: broom
## Warning: package 'broom' was built under R version 4.5.2
## Cargando paquete requerido: GGally
## Warning: package 'GGally' was built under R version 4.5.2
## Cargando paquete requerido: gridExtra
## 
## Adjuntando el paquete: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
## Cargando paquete requerido: knitr
## Warning: package 'knitr' was built under R version 4.5.2
## Cargando paquete requerido: summarytools

2 2. Carga de la base de datos

data("vivienda")

# Estructura de la base
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>

La base contiene información sobre diferentes características de viviendas como área construida, estrato socioeconómico, número de habitaciones, baños, parqueaderos y ubicación geográfica. Con 8322 datos y 13 variables.

3 3. Filtrado de la base de datos

Se seleccionan únicamente las casas ubicadas en la zona norte de la ciudad.

base_norte <- subset(vivienda, tipo == "Casa" & zona == "Zona Norte")

nrow(base_norte)
## [1] 722

Se identifican 722 viviendas tipo casa ubicadas en la zona norte.

head(base_norte,3)
## # A tibble: 3 × 13
##      id zona    piso  estrato preciom areaconst parqueaderos banios habitaciones
##   <dbl> <chr>   <chr>   <dbl>   <dbl>     <dbl>        <dbl>  <dbl>        <dbl>
## 1  1209 Zona N… 02          5     320       150            2      4            6
## 2  1592 Zona N… 02          5     780       380            2      3            3
## 3  4057 Zona N… 02          6     750       445           NA      7            6
## # ℹ 4 more variables: tipo <chr>, barrio <chr>, longitud <dbl>, latitud <dbl>

Primeros registros

Verificacion de los registros

table(base_norte$tipo)
## 
## Casa 
##  722
table(base_norte$zona)
## 
## Zona Norte 
##        722

Casa 722 Zona Norte 722 Estas tablas permiten confirmar que el filtro fue aplicado correctamente.

4 4. Visualización geográfica

leaflet(base_norte) %>%
  addTiles() %>%
  addCircleMarkers(
    lng = ~longitud,
    lat = ~latitud,
    radius = 5,
    color = 'blue',
    popup = ~barrio
  )

Discusión

El filtro aplicado permitió seleccionar únicamente las viviendas tipo casa ubicadas en la zona norte. Al visualizar los puntos en el mapa, se observa que la mayoría se concentran en esta zona, lo cual confirma la coherencia del filtro aplicado.

Sin embargo, en algunos casos podrían aparecer puntos fuera del área esperada. Esto puede deberse a errores en la georreferenciación, inconsistencias en la clasificación de la zona o errores en el registro de las coordenadas.

5 5. Análisis Exploratorio de Datos

Precio vs Área Construida

plot_ly(base_norte,
        x = ~areaconst,
        y = ~preciom,
        type = "scatter",
        mode = "markers",
        color = ~estrato,
        text = ~barrio) %>%
  layout(title = "Precio vs Área Construida",
         xaxis = list(title = "Área Construida"),
         yaxis = list(title = "Precio (millones)"))

Se observa una relación positiva entre el área construida y el precio de la vivienda. A medida que aumenta el tamaño de la vivienda, el precio tiende a incrementarse.

plot_ly(base_norte,
        x = ~as.factor(estrato),
        y = ~preciom,
        type = "box") %>%
  layout(title = "Precio según Estrato",
         xaxis = list(title = "Estrato"),
         yaxis = list(title = "Precio (millones)"))

Se observa que las viviendas en estratos más altos presentan precios promedio mayores.

Precio vs Número de Baños

plot_ly(base_norte,
        x = ~banios,
        y = ~preciom,
        type = "scatter",
        mode = "markers",
        color = ~banios) %>%
  layout(title = "Precio vs Número de Baños",
         xaxis = list(title = "Número de Baños"),
         yaxis = list(title = "Precio (millones)"))

Se observa una tendencia creciente entre el número de baños y el precio.

Precio vs Número de Habitaciones

plot_ly(base_norte,
        x = ~habitaciones,
        y = ~preciom,
        type = "scatter",
        mode = "markers",
        color = ~habitaciones) %>%
  layout(title = "Precio vs Número de Habitaciones",
         xaxis = list(title = "Habitaciones"),
         yaxis = list(title = "Precio (millones)"))

Las viviendas con más habitaciones tienden a presentar precios más altos.

#6. Modelo de regresión lineal múltiple

modelo <- lm(preciom ~ areaconst + estrato + habitaciones + parqueaderos + banios,
             data = base_norte)

summary(modelo)
## 
## Call:
## lm(formula = preciom ~ areaconst + estrato + habitaciones + parqueaderos + 
##     banios, data = base_norte)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -784.29  -77.56  -16.03   47.67  978.61 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -238.17090   44.40551  -5.364 1.34e-07 ***
## areaconst       0.67673    0.05281  12.814  < 2e-16 ***
## estrato        80.63495    9.82632   8.206 2.70e-15 ***
## habitaciones    7.64511    5.65873   1.351    0.177    
## parqueaderos   24.00598    5.86889   4.090 5.14e-05 ***
## banios         18.89938    7.48800   2.524    0.012 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 155.1 on 429 degrees of freedom
##   (287 observations deleted due to missingness)
## Multiple R-squared:  0.6041, Adjusted R-squared:  0.5995 
## F-statistic: 130.9 on 5 and 429 DF,  p-value: < 2.2e-16

Interpretación del modelo

Los resultados muestran que:

El área construida tiene un efecto positivo y significativo sobre el precio.

El estrato socioeconómico también influye de manera importante en el valor de la vivienda.

El número de parqueaderos y baños incrementa el precio.

El número de habitaciones no resulta estadísticamente significativo.

El modelo presenta un R² cercano a 0.60, lo cual significa que aproximadamente el 60% de la variación en el precio de las viviendas es explicada por las variables incluidas.

6 7. Validación de supuestos del modelo

plot(modelo,1)

Linealidad

plot(modelo,1)

Normalidad de residuos

plot(modelo,2)

shapiro.test(residuals(modelo))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(modelo)
## W = 0.85246, p-value < 2.2e-16

Homocedasticidad

plot(modelo,3)

bptest(modelo)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo
## BP = 80.281, df = 5, p-value = 7.33e-16

Multicolinealidad

vif(modelo)
##    areaconst      estrato habitaciones parqueaderos       banios 
##     1.460998     1.307757     1.721015     1.226334     1.967421

Estas pruebas permiten evaluar si el modelo cumple los supuestos de regresión lineal. En caso de observar problemas, se podrían aplicar transformaciones de variables o incluir nuevas variables explicativas.

7 8. Predicción para solicitud 1

solicitud1 <- data.frame(
  areaconst = 120,
  estrato = 4,
  habitaciones = 3,
  parqueaderos = 1,
  banios = 2
)
prediccion1 <- predict(modelo, newdata = solicitud1)
prediccion1
##        1 
## 250.3171

La predicicion muestra que la vivienda con esas condiciones valdria 250 millones de pesos

Ofertas potenciales (máximo 350 millones)

ofertas1 <- vivienda %>%
  filter(preciom <= 350)

ofertas1_potenciales <- head(ofertas1,5)

ofertas1_potenciales
## # A tibble: 5 × 13
##      id zona    piso  estrato preciom areaconst parqueaderos banios habitaciones
##   <dbl> <chr>   <chr>   <dbl>   <dbl>     <dbl>        <dbl>  <dbl>        <dbl>
## 1  1147 Zona O… <NA>        3     250        70            1      3            6
## 2  1169 Zona O… <NA>        3     320       120            1      2            3
## 3  1350 Zona O… <NA>        3     350       220            2      2            4
## 4  1212 Zona N… 01          5     260        90            1      2            3
## 5  1724 Zona N… 01          5     240        87            1      3            3
## # ℹ 4 more variables: tipo <chr>, barrio <chr>, longitud <dbl>, latitud <dbl>
leaflet(ofertas1_potenciales) %>%
  addTiles() %>%
  addCircleMarkers(
    lng = ~longitud,
    lat = ~latitud,
    radius = 6,
    color = "red",
    popup = ~paste("Barrio:", barrio,
                   "<br>Precio:", preciom, "millones")
  )

#9. Predicción para solicitud 2

solicitud2 <- data.frame(
  areaconst = 200,
  estrato = 5,
  habitaciones = 4,
  parqueaderos = 2,
  banios = 3
)
prediccion2 <- predict(modelo, newdata = solicitud2)
prediccion2
##        1 
## 435.6413

Con la predccion anterior estariamos hablando de 435 millones Ofertas potenciales (máximo 850 millones)

ofertas2 <- vivienda %>%
  filter(preciom <= 850)

ofertas2_potenciales <- head(ofertas2,5)

ofertas2_potenciales
## # A tibble: 5 × 13
##      id zona    piso  estrato preciom areaconst parqueaderos banios habitaciones
##   <dbl> <chr>   <chr>   <dbl>   <dbl>     <dbl>        <dbl>  <dbl>        <dbl>
## 1  1147 Zona O… <NA>        3     250        70            1      3            6
## 2  1169 Zona O… <NA>        3     320       120            1      2            3
## 3  1350 Zona O… <NA>        3     350       220            2      2            4
## 4  5992 Zona S… 02          4     400       280            3      5            3
## 5  1212 Zona N… 01          5     260        90            1      2            3
## # ℹ 4 more variables: tipo <chr>, barrio <chr>, longitud <dbl>, latitud <dbl>
leaflet(ofertas2_potenciales) %>%
  addTiles() %>%
  addCircleMarkers(
    lng = ~longitud,
    lat = ~latitud,
    radius = 6,
    color = "blue",
    popup = ~paste("Barrio:", barrio,
                   "<br>Precio:", preciom, "millones")
  )

#10. Conclusiones

El análisis realizado permite identificar los principales factores que influyen en el precio de las viviendas en la zona norte.

El análisis exploratorio muestra que variables como área construida, estrato, número de baños y parqueaderos presentan una relación positiva con el precio de las viviendas.

El modelo de regresión lineal múltiple confirma estos resultados, mostrando que el área construida y el estrato socioeconómico son los factores más influyentes en el valor de las viviendas.

El modelo explica aproximadamente el 60% de la variabilidad del precio, lo cual indica un ajuste moderadamente bueno. Sin embargo, existen otros factores no incluidos en el modelo que también pueden influir en el valor de las viviendas, como la ubicación específica del barrio, la antigüedad del inmueble o la calidad de los acabados.

Las predicciones realizadas permiten estimar el precio esperado de viviendas con determinadas características y facilitan la identificación de ofertas potenciales dentro de un presupuesto específico.

Finalmente, la visualización geográfica mediante mapas permite identificar las zonas donde se concentran las ofertas disponibles, lo cual resulta útil para la toma de decisiones en el mercado inmobiliario.