Last active
June 2, 2018 12:51
-
-
Save lwaldron/67a9684952dabb88fb9499b4f324813a to your computer and use it in GitHub Desktop.
What is the fraction of sample means expected to fall within the 95% confidence intervals? This is an incorrect (and not useful) interpretation of the 95% CI, but out of curiosity, the answer is less than 95%.
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
fracwithin <- function(n){ | |
sam1 <- rnorm(n) | |
ci <- t.test(sam1)$conf.int | |
means <- replicate(100, mean(rnorm(n))) | |
mean(means > ci[1] & means < ci[2]) | |
} | |
set.seed(2) | |
n <- seq(5, 10000, by=2) | |
fraction <- sapply(n, function(i) fracwithin(i)) | |
plot(n, fraction) | |
abline(h=0.95, lw=4) | |
lines(smooth.spline(n, fraction), col="red", lw=5, lty=3) | |
legend("bottomright", col = c("black", "red"), lty=c(1, 3), | |
legend=c("0.95", "frac sample means within 95% CI")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment