SHARE
TWEET

Untitled

a guest Oct 24th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ## Calculation labs
  3.  
  4. choose(4,2)
  5. factorial(5)
  6. #EX 1
  7. choose(8,3)*factorial(3)
  8. #EX 2
  9. # a)
  10. #permutation because order matters
  11. choose(36,8)*factorial(8)
  12. factorial(36)/factorial(36-8)
  13. # b)
  14. #if letters can repeat
  15. 36^8
  16. #EX 3
  17. #combination because order doesnt matter (n=10, r =4)
  18. choose(10,4)
  19. #EX 4
  20. # P(all def.) = 1 (in mean choose(3,3)) / choose(14,3)
  21. 1/choose(14,3)
  22. # also
  23. 3/14*2/13*1/12
  24. #EX 5
  25. choose(6,6)/choose(49,6)
  26. choose(6,5)*choose(43,1)/choose(49,6)
  27. choose(6,4)*choose(43,2)/choose(49,6)
  28. choose(6,3)*choose(43,3)/choose(49,6)
  29. choose(6,2)*choose(43,4)/choose(49,6)
  30. choose(6,1)*choose(43,5)/choose(49,6)
  31. choose(6,0)*choose(43,6)/choose(49,6)
  32.  
  33. probs <- choose(6,0:6)*choose(43,6-0:6)/choose(49,6)
  34. plot(probs)
  35. format(probs, digits = 6, format="f")
  36.  
  37. ## Bayesian revision labs
  38.  
  39. # EX 1
  40. prior<-c(.3,.5,.2)
  41. likelyhood<-c(.7,.4,.2)
  42. posterior_a<-prior*likelyhood
  43. posterior<-posterior_a/sum(posterior_a)
  44.  
  45. #EX 2
  46. prior<-c(.9,.1)
  47. likelyhood<-c(.98,.05)
  48. posterior_a<-prior*likelyhood
  49. posterior<-posterior_a/sum(posterior_a)
  50.  
  51. #EX 3
  52. prior<-c(1/6,1/6,1/6,1/6,1/6,1/6)
  53. likelyhood<-c(0,.5,.5,1,1,1)
  54. posterior_a<-prior*likelyhood
  55. posterior<-posterior_a/sum(posterior_a)
  56.  
  57. #EX 4
  58. prior<-c(1/3,1/3,1/3)
  59. likelyhood<-c(0,0.5,1)
  60. posterior_a<-prior*likelyhood
  61. posterior<-posterior_a/sum(posterior_a)
  62.  
  63. # Discrete random variables
  64.  
  65. #EX 1
  66. x<-1:6
  67. prob<-rep(1/6,6)
  68. #expected value
  69. expected_value<-sum(x*prob)
  70. #variance
  71. variance<-sum((x-expected_value)^2*prob)
  72.  
  73. #EX 2
  74. n<-3
  75. x<-0:n
  76. #prob<-c(.81,.18,.01)
  77. binomial_distribution<-dbinom(x,n,.1)
  78. #expected value
  79. expected_value<-sum(x*binomial_distribution)
  80. #variance
  81. variance<-sum((x-expected_value)^2*binomial_distribution)
  82.  
  83. #expected value = n * p
  84. #variance = n * p * q
  85.  
  86. #EX 5
  87. x<-c(0,0,0,24,200,5000,9000000)-3
  88. prob<-(dhyper(0:6,6,43,6))
  89. #expected value
  90. expected_value<-sum(x*prob)
  91. #variance
  92. variance<-sum((x-expected_value)^2*prob)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top