Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Created January 31, 2014 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinushey/8726118 to your computer and use it in GitHub Desktop.
Save kevinushey/8726118 to your computer and use it in GitHub Desktop.
Re: Python and R: Is Python really faster than R?
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