Created
February 8, 2018 20:01
-
-
Save BrianWeinstein/d07d69404592090bbd790293fcdec82d to your computer and use it in GitHub Desktop.
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
bootstrap_ci <- function(data, sample_size_pct = 0.50, samples = 100, conf_level = 0.95){ | |
# Computes a bootstrapped confidence interval | |
# INPUT: | |
# data: a numeric vector | |
# sample_size_pct: the percentage of the input data to be used in each bootsrapped sample | |
# samples: the number of samples | |
# conf_level: the desired confidence level | |
# OUTPUT: | |
# a bootstrapped conf_level confidence interval | |
num_data_points <- length(data) | |
sample_means <- list() | |
for(i in 1:samples){ | |
sample_means[i] <- mean(sample(x = data, size = floor(num_data_points * sample_size_pct), replace = TRUE)) | |
} | |
sample_means <- unlist(sample_means) | |
ci <- sd(sample_means) * qnorm(p = conf_level+((1-conf_level)/2)) | |
return(ci) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment