Created
April 29, 2011 06:28
-
-
Save jpablo/947944 to your computer and use it in GitHub Desktop.
bootstrap in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Los datos (ejemplo) | |
d = c(2,4,6,6,7,11,13,13,14,15,19,23,24,27,28,28,28,30,31,43) | |
#### | |
dm <- mean(d) | |
ds <- sd(d) | |
n <- length(d) | |
T <- function() { | |
m <- sample(d, n, 1) | |
(mean(m) - dm)*sqrt(n) / sd(m) | |
} | |
B <- 999 | |
L = round(0.025 * B) | |
U = round(0.975 * B) | |
# El intervalo de 95 % confianza para el bootstrap | |
b <- sort(replicate(B, T())) | |
c( dm - b[U] * ds / sqrt(n), dm - b[L] * ds / sqrt(n) ) | |
# El mismo intervalo asumiendo normalidad | |
tn <- abs(qt(.05 / 2, n-1)) | |
c( dm - tn * ds / sqrt(n), dm + tn * ds / sqrt(n) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment