Created
April 18, 2016 02:51
-
-
Save soumyaray/bfb856aaca91d262a6f95285cd8275d2 to your computer and use it in GitHub Desktop.
First attempt of .632 bootstrap on mean estimation
This file contains hidden or 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
adj_test <- function() { | |
a <- rnorm(n=100, mean=50, sd=10) | |
b <- rnorm(n=100, mean=60, sd=5) | |
c <- rnorm(n=100, mean=65, sd=2) | |
abc <- c(a,b,c) | |
data <- data.frame(key=c(1:300), vals=abc) | |
boot_mean <- c() | |
boot_mean_adj <- c() | |
for(i in 1:2000) { | |
boot_index <- sample(nrow(data), replace = TRUE) | |
boot_data <- data[boot_index,] | |
boot_index_missing <- setdiff((1:nrow(data)), unique(boot_index)) | |
boot_data_missing <- data[boot_index_missing,] | |
boot_mean[i] <- mean(boot_data$vals) | |
boot_mean_adj[i] <- 0.632*mean(boot_data$vals) + 0.368*mean(boot_data_missing$vals) | |
} | |
return(data.frame(data_mean=mean(data$vals), bootstrap_mean=mean(boot_mean), bootstrap632_mean=mean(boot_mean_adj))) | |
} | |
results <- adj_test() | |
for (i in 1:29) { | |
res <- adj_test() | |
results <- rbind(results, res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment