library(boot)
ocupacion <- c(78, 82, 75, 80, 85, 88, 92, 90, 86, 84, 80, 83)
bootstrap_media <- function(data, indices) {
return(mean(data[indices]))
}
set.seed(616)
bootstrap_result <- boot(data = ocupacion, statistic = bootstrap_media, R = 1000)
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
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
hist(bootstrap_result$t, main = "Distribución Bootstrap (1000 repeticiones)",
xlab = "Ocupación Remuestreada", col = "lightblue", border = "black")

set.seed(616)
bootstrap_result2 <- boot(data = ocupacion, statistic = bootstrap_media, R = 100000)
print(bootstrap_result2)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = ocupacion, statistic = bootstrap_media, R = 1e+05)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 83.58333 -0.003584167 1.374485
intervalo_confianza2 <- boot.ci(bootstrap_result2, type = "perc")
print(intervalo_confianza2)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 100000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result2, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (80.92, 86.25 )
## Calculations and Intervals on Original Scale
ocupacion2 <- c(78, 82, 75, 80, 85, 88, 92, 90, 86, 84, 80, 73)
set.seed(616)
bootstrap_result3 <- boot(data = ocupacion2, statistic = bootstrap_media, R = 1000)
print(bootstrap_result3)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = ocupacion2, statistic = bootstrap_media, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 82.75 0.0545 1.605597
intervalo_confianza3 <- boot.ci(bootstrap_result3, type = "perc")
print(intervalo_confianza3)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = bootstrap_result3, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (79.67, 86.00 )
## Calculations and Intervals on Original Scale
hist(bootstrap_result3$t, main = "Distribución Bootstrap (Diciembre = 73%)",
xlab = "Ocupación Remuestreada", col = "salmon", border = "black")
