Skip to content

Instantly share code, notes, and snippets.

@dritoshi
Created March 30, 2012 11:32
Show Gist options
  • Save dritoshi/2250944 to your computer and use it in GitHub Desktop.
Save dritoshi/2250944 to your computer and use it in GitHub Desktop.
Monte Carlo method
m <- 100000
x <- runif(m)
# Monte Carlo method
theta.hat <- mean(exp(-x))
# numeric integral
theta <- 1 - exp(-1)
results <- sprintf("Theta hat: %f\nNumeric integral: %f\n", theta.hat, theta)
cat(results)
Theta hat: 0.629351
Numeric integral: 0.632121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment