Created
January 31, 2014 03:18
-
-
Save kevinushey/8726118 to your computer and use it in GitHub Desktop.
Re: Python and R: Is Python really faster than R?
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
case2 <- function(n = 10, mu = 3, sigma = sqrt(5), p = 0.025, rep = 100){ | |
xbar <- vapply(1:rep, FUN.VALUE=numeric(1), function(i) { | |
norm <- rnorm(mean = mu, sd = sigma, n = n) | |
return(mean(norm)) | |
}) | |
low <- xbar - qnorm(1-p) * (sigma / sqrt(n)) | |
up <- xbar + qnorm(1-p) * (sigma / sqrt(n)) | |
rem <- mu > low & mu < up | |
inside <- sum(rem) | |
per <- inside / rep | |
desc <- paste("There are ", inside, " confidence intervals that contain ", | |
"the true mean (", mu, "), that is ", per, " percent of the total CIs", sep = "") | |
return(list(Matrix = matrix( c(xbar, low, up, rem), ncol=4 ), Decision = desc)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment