Empirical distribution function

X <- runif(10, 0, 5)
head(X)
## [1] 3.8711971 0.8607530 1.7208043 1.0334157 4.4005678 0.1501857

plot(ecdf(X))


X <- runif(100, 0, 5)
head(X)
## [1] 4.4819105 0.2040852 4.6547130 2.0921513 0.6092080 2.5964367

plot(ecdf(X))

Bootstrap

N <- 100
X <- runif(N, 0, 1)
head(X)
## [1] 0.5478503 0.1747706 0.1609349 0.8704673 0.9702808 0.5617399
median(X)
## [1] 0.4510158

X_star <- sample(X, length(X), replace = TRUE)
head(X_star)
## [1] 0.17477056 0.04233419 0.76503417 0.64784282 0.62239219 0.62239219
median(X_star)
## [1] 0.4463568
median(sample(X, length(X), replace = TRUE))
## [1] 0.4553928

T_boot_dist <- replicate(
  1e4, median(sample(X, length(X), replace = TRUE)))
head(T_boot_dist)
## [1] 0.4466388 0.4510158 0.4466388 0.4185943 0.5331197 0.3694078
sd(T_boot_dist)
## [1] 0.05583576

sd(replicate(1e4, median(runif(100, 0, 1))))
## [1] 0.04905206

Bootstrap confidence interval

X <- runif(100, 0, 1)
head(X)
## [1] 0.4997914 0.3997159 0.5221164 0.9405741 0.4973175 0.2348496
median(X)
## [1] 0.4985545

T_boot_dist <- replicate(
  1e4, median(sample(X, length(X), replace = TRUE)))
quantile(T_boot_dist, c(.975, .025), names = FALSE)
## [1] 0.6344970 0.4362474
2 * median(X) - quantile(T_boot_dist, c(.975, .025),
                         names = FALSE)
## [1] 0.3626120 0.5608615