Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. set.seed(421) # for reproducibility
  2. m = 20000; n = 5
  3. par(mfrow=c(1,3))
  4. x = rnorm(m*n); DTA = matrix(x, nrow=m)
  5. a = rowMeans(DTA); s = apply(DTA, 1, sd)
  6. plot(a, s, pch=".", main="Standard Normal")
  7. cor(a,s)
  8. [1] -0.001354763 # consistent with 0
  9. x = rexp(m*n); DTA = matrix(x, nrow=m)
  10. a = rowMeans(DTA); s = apply(DTA, 1, sd)
  11. plot(a, s, pch=".", main="Standard Exponential")
  12. cor(a,s)
  13. [1] 0.7695967
  14. x = rbeta(m*n, .1,.1); DTA = matrix(x, nrow=m)
  15. a = rowMeans(DTA); s = apply(DTA, 1, sd)
  16. plot(a, s, pch=".", main="Standard Normal")
  17. cor(a,s)
  18. [1] -0.008673277 # consistent with 0
  19. par(mfrow=c(1,1))
  20.  
  21. set.seed(2019)
  22. m = 10^4 # for good graph, don't use too many
  23. # for accurate est of r, use very many
  24. x = runif(m); x1 = (x<.3); x2 = (x>=.8)
  25. cor(x1, x2)
  26. [1] -0.327649
  27. jit1 = runif(m, -.25, .25); jit2 = runif(m, -.25, .25)
  28. plot(x1+jit1, x2+jit2, pch=".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement