####Primer Ejemplo####
#Cargar librería necesaria
library(boot)
#Datos originales
salarios <- c(2000, 2500, 2800, 3200, 4000, 4500, 5000, 6000, 6500, 7000)
#Función para calcular la media (para el bootstrap)
bootstrap_media <- function(data, indices) {
return(mean(data[indices])) # Calcula la media de la muestra remuestreada
}
#Aplicar Bootstrap con 1000 repeticiones
set.seed(616) # Fijamos seed para reproducibilidad
bootstrap_result <- boot(data = salarios, statistic = bootstrap_media, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = salarios, statistic = bootstrap_media, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 4350 -6.14 513.2681
#Calcular Intervalo de Confianza del 95%
intervalo_confianza <- boot.ci(bootstrap_result, type = "perc")
print(intervalo_confianza)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (3380, 5379 )
## Calculations and Intervals on Original Scale
hist(bootstrap_result$t, main = "Distribución Bootstrap de la Media",
xlab = "Media Remuestreada", col = "lightblue", border = "black")
bootstrap_result2 <- boot(data = bootstrap_result$t, statistic = bootstrap_media, R = 1000)
intervalo_confianza2 <- boot.ci(bootstrap_result2, type = "perc")
print(intervalo_confianza2)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result2, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (4313, 4375 )
## Calculations and Intervals on Original Scale
####Dos grupos####
#Cargar librería necesaria
library(boot)
#Datos de salarios por departamento
salarios_A <- c(2500, 2800, 3000, 3500, 4000, 4200, 4500, 4800, 5000, 5500)
salarios_B <- c(2800, 3200, 3600, 4000, 4500, 4700, 5000, 5500, 6000, 6500)
#Función para calcular la diferencia de medias
bootstrap_diff_means <- function(data, indices) {
datos_A <- data[indices[1:10]] # Primeros 10 valores son del grupo A
datos_B <- data[indices[11:20]] # Últimos 10 valores son del grupo B
return(mean(datos_B) - mean(datos_A)) # Diferencia de medias
}
#Unir datos en un solo vector
datos_combinados <- c(salarios_A, salarios_B)
#Aplicar Bootstrap con 1000 repeticiones
set.seed(616) # Fijamos semilla para reproducibilidad
bootstrap_result <- boot(data = datos_combinados, statistic = bootstrap_diff_means, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = datos_combinados, statistic = bootstrap_diff_means,
## R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 600 -578.5 511.1703
#Calcular Intervalo de Confianza del 95%
intervalo_confianza <- boot.ci(bootstrap_result, type = "perc")
print(intervalo_confianza)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (-910.0, 1099.7 )
## Calculations and Intervals on Original Scale
hist(bootstrap_result$t, main = "Distribución Bootstrap de la Diferencia de Medias",
xlab = "Diferencia de Medias", col = "lightblue", border = "black")
bootstrap_result2 <- boot(data = bootstrap_result$t, statistic = bootstrap_diff_means, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result2)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = bootstrap_result$t, statistic = bootstrap_diff_means,
## R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* -276 273.935 231.7484
#Calcular Intervalo de Confianza del 95%
intervalo_confianza2 <- boot.ci(bootstrap_result2, type = "perc")
print(intervalo_confianza2)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result2, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (-451.9, 456.9 )
## Calculations and Intervals on Original Scale
####Ejercicio hotel Mirage ####
#Cargar librería necesaria
library(boot)
#Datos originales (Ocupación mensual del Hotel Mirage, en %)
ocupacion <- c(78, 82, 75, 80, 85, 88, 92, 90, 86, 84, 80, 83)
#Función para calcular la media (para el bootstrap)
bootstrap_media <- function(data, indices) {
return(mean(data[indices])) # Calcula la media de la muestra remuestreada
}
#Aplicar Bootstrap con 1000 repeticiones
set.seed(616) # Fijamos seed para reproducibilidad
bootstrap_result <- boot(data = ocupacion, statistic = bootstrap_media, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = ocupacion, statistic = bootstrap_media, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 83.58333 0.07033333 1.358444
#Calcular Intervalo de Confianza del 95%
intervalo_confianza <- boot.ci(bootstrap_result, type = "perc")
print(intervalo_confianza)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (81.00, 86.42 )
## Calculations and Intervals on Original Scale
#Histograma de medias remuestreadas
hist(bootstrap_result$t, main = "Distribución Bootstrap de la Ocupación Media",
xlab = "Ocupación remuestreada (%)", col = "lightblue", border = "black")
#(igual que en el ejemplo original) Bootstrap sobre el vector de estadísticas
bootstrap_result2 <- boot(data = bootstrap_result$t, statistic = bootstrap_media, R = 1000)
intervalo_confianza2 <- boot.ci(bootstrap_result2, type = "perc")
print(intervalo_confianza2)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result2, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (83.57, 83.74 )
## Calculations and Intervals on Original Scale
####Dos grupos####
#Cargar librería necesaria
library(boot)
#Datos de ocupación por “semestre” (enero–junio vs. julio–diciembre)
ocupacion_A <- c(78, 82, 75, 80, 85, 88) # Primeros 6 meses
ocupacion_B <- c(92, 90, 86, 84, 80, 83) # Últimos 6 meses
#Función para calcular la diferencia de medias
bootstrap_diff_means <- function(data, indices) {
datos_A <- data[indices[1:6]] # Primeros 6 valores son del grupo A
datos_B <- data[indices[7:12]] # Últimos 6 valores son del grupo B
return(mean(datos_B) - mean(datos_A)) # Diferencia de medias
}
#Unir datos en un solo vector
datos_combinados <- c(ocupacion_A, ocupacion_B)
#Aplicar Bootstrap con 1000 repeticiones
set.seed(616) # Fijamos semilla para reproducibilidad
bootstrap_result <- boot(data = datos_combinados, statistic = bootstrap_diff_means, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = datos_combinados, statistic = bootstrap_diff_means,
## R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 4.5 -4.368333 2.791358
#Calcular Intervalo de Confianza del 95%
intervalo_confianza <- boot.ci(bootstrap_result, type = "perc")
print(intervalo_confianza)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (-5.496, 5.662 )
## Calculations and Intervals on Original Scale
#Histograma de diferencias de medias
hist(bootstrap_result$t, main = "Distribución Bootstrap de la Diferencia de Ocupación",
xlab = "Diferencia de medias (B - A) en puntos porcentuales",
col = "lightblue", border = "black")
#(igual que en el ejemplo original) Bootstrap sobre las estadísticas
bootstrap_result2 <- boot(data = bootstrap_result$t, statistic = bootstrap_media, R = 1000)
#Mostrar resumen de resultados
print(bootstrap_result2)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = bootstrap_result$t, statistic = bootstrap_media,
## R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 0.1316667 0.001644833 0.08861677
#Calcular Intervalo de Confianza del 95%
intervalo_confianza2 <- boot.ci(bootstrap_result2, type = "perc")
print(intervalo_confianza2)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result2, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (-0.0468, 0.3072 )
## Calculations and Intervals on Original Scale
precios dinámicos y paquetes (noches extra, desayuno/spa) en días valle;
más visibilidad en OTAs + campañas locales;
atraer segmentos alternos (corporativo local, grupos, “staycations”, trabajo remoto);
campañas a clientes previos (beneficios: upgrade/late checkout);
empujar reservas directas con mejores condiciones;
mejorar experiencia clave (wifi, limpieza, check‑in) para subir reviews y conversión.