Guest User

Untitled

a guest
Nov 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. n<-100;
  2. mtres<-rep(0,n)
  3.  
  4. nsim<-10000
  5.  
  6. for (t in 1:647) {
  7.  
  8. tourres<-matrix(rep(0,n*n),nrow=n,ncol=n)
  9. for (k in 2:n) {
  10. for (l in 1:(k-1)) {
  11. tourres[k,l]<-sample(c(0,1),1)
  12. tourres[l,k]<-1-tourres[k,l]
  13. }
  14. }
  15. mtres<-mtres+sort(rowSums(tourres))
  16. }
  17.  
  18. plot(mtres/nsim,type='l')
  19.  
  20. me<-(n-1)/2
  21. se<-sqrt((n-1)/4)
  22.  
  23. curve(qnorm(x/n,me,se),from=0,to=n,add=T,col='red')
  24. curve(qbinom((x-0.5)/n,n-1,1/2),from=0,to=n,add=T,col='blue')
  25.  
  26. > mtres/nsim
  27. [1] 37.0529 38.8178 39.8103 40.5246 41.1004 41.5688 41.9787 42.3477 42.6726
  28. [10] 42.9847 43.2639 43.5249 43.7751 44.0082 44.2256 44.4402 44.6479 44.8379
  29. [19] 45.0221 45.2040 45.3828 45.5611 45.7286 45.8976 46.0504 46.2097 46.3602
  30. [28] 46.5153 46.6663 46.8137 46.9510 47.0826 47.2206 47.3658 47.5138 47.6548
  31. [37] 47.7893 47.9121 48.0304 48.1495 48.2822 48.4198 48.5623 48.6912 48.8136
  32. [46] 48.9286 49.0407 49.1549 49.2819 49.4216 49.5650 49.7027 49.8218 49.9305
  33. [55] 50.0414 50.1550 50.2857 50.4243 50.5592 50.7022 50.8349 50.9580 51.0779
  34. [64] 51.1992 51.3318 51.4758 51.6228 51.7688 51.9080 52.0362 52.1782 52.3212
  35. [73] 52.4726 52.6264 52.7842 52.9417 53.0956 53.2592 53.4346 53.6118 53.7920
  36. [82] 53.9683 54.1521 54.3493 54.5514 54.7600 54.9891 55.2233 55.4744 55.7365
  37. [91] 56.0231 56.3181 56.6480 57.0165 57.4239 57.9007 58.4657 59.1880 60.1857
  38. [100] 61.9515
  39. > qbinom(((1:n)-0.5)/n,n-1,1/2)
  40. [1] 37 39 40 41 41 42 42 42 43 43 43 44 44 44 44 44 45 45 45 45 45 46 46 46 46
  41. [26] 46 46 47 47 47 47 47 47 47 48 48 48 48 48 48 48 48 49 49 49 49 49 49 49 49
  42. [51] 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 52 52 52 52 52 52 52 53 53
  43. [76] 53 53 53 53 54 54 54 54 54 55 55 55 55 55 56 56 56 57 57 57 58 58 59 60 62
  44. >
Add Comment
Please, Sign In to add comment