Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. m = 10^5; s = numeric(m); rate=1/3; lam=5
  2. for (i in 1:m) {
  3. n = rpois(1, lam)
  4. s[i] = sum(rexp(n+1, rate)) }
  5. mean(s); var(s)
  6. ## 17.93764 # approximates E(S) = (5 + 1)(3)
  7. ## 97.76707 # approximates V(X)
  8. mean(s > 30)
  9. ## 0.11677 # approximates P(S > 30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement