Este documento presenta un análisis de Bootstrap usando el conjunto de datos de detalles de bicicletas.
library(boot)
library(readr)
Asegúrate de especificar la ruta correcta del archivo.
## Rows: 1061 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, seller_type, owner
## dbl (4): selling_price, year, km_driven, ex_showroom_price
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Puedes cambiarla por otra estadística como mediana, varianza, etc.
mean_function <- function(data, indices) {
return(mean(data[indices]))
}
set.seed asegura que los resultados sean reproducibles. Realiza el análisis Bootstrap con 1000 réplicas.
set.seed(123)
boot_results <- boot(data = bike_data$selling_price, statistic = mean_function, R = 1000)
Muestra la media original, el sesgo y el error estándar de las medias bootstrapped.
print(boot_results)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = bike_data$selling_price, statistic = mean_function,
## R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 59638.15 -31.65865 1747.875
Calcula y muestra el sesgo y la desviación estándar.
boot_bias <- boot_results$t0 - mean(boot_results$t)
boot_sd <- sd(boot_results$t)
cat("Sesgo (Bias):", boot_bias, "\n")
## Sesgo (Bias): 31.65865
cat("Desviación Estándar (Standard Error):", boot_sd, "\n")
## Desviación Estándar (Standard Error): 1747.875
Calcula y muestra el intervalo de confianza al 95% para la media.
conf_interval_perc <- boot.ci(boot_results, type = "perc")
print(conf_interval_perc)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = boot_results, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (56226, 63069 )
## Calculations and Intervals on Original Scale