Guest User

Untitled

a guest
Feb 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. ac_exam2=function(n,p1_low,p1_high,p2_low,p2_high,study1,study2){
  2.  
  3. #n:持っている科目数
  4. #p1_low:1次試験科目の合格率下限
  5. #p1_high:1次試験科目の合格率上限
  6. #p2_low:2次試験科目の合格率下限
  7. #p2_high: 2次試験科目の合格率上限
  8. #study1:勉強により科目1の合格率を引き上げることができる
  9. #study2:勉強により科目2の合格率を引き上げることができる
  10. #year:受験年数
  11. #year1:1次試験合格年数
  12. #year2:2次試験合格年数
  13.  
  14. year=0
  15. while(n<4){
  16. year=year+1
  17. k=rep(0,5)
  18. t1=5-n
  19. k[1]=rbinom(1, 1, runif(1,p1_low,p1_high)+study1)
  20. k[2]=rbinom(1, 1, runif(1,p1_low,p1_high)+study2)
  21. for(i in 3:t1){
  22. k[i]=rbinom(1, 1, runif(1,p1_low,p1_high))
  23. }
  24. n=n+sum(k)
  25. }
  26.  
  27. while(n<5){
  28. year=year+1
  29. k=rep(0,5)
  30. k[1]=rbinom(1, 1, runif(1,p1_low,p1_high)+study1+study2)
  31. n=n+sum(k)
  32. }
  33.  
  34. year1=year
  35.  
  36. while(n<6){
  37. year=year+1
  38. l=rep(0,2)
  39. l[1]= rbinom(1, 1, runif(1,p2_low,p2_high)+study1)
  40. l[2]= rbinom(1, 1, runif(1,p2_low,p2_high)+study2)
  41. n=n+sum(l)
  42. }
  43. while(n<7){
  44. year=year+1
  45. l=rep(0,2)
  46. l[1]= rbinom(1, 1, runif(1,p2_low,p2_high)+study1+study2)
  47. n=n+sum(l)
  48. }
  49.  
  50. year2=year
  51. result=cbind(year1,year2)
  52. return(result)
  53.  
  54. }
  55.  
  56. ac_exam2(0,0.1,0.3,0.1,0.2,0.25,0.25)
  57.  
  58. #シミュレーションをN回行ってみる。
  59. sim2=function(N,n,p1_low,p1_high,p2_low,p2_high,study1,study2){
  60. res=matrix(0,N,2)
  61. for(i in 1:N){
  62. res[i,]=ac_exam2 (n,p1_low,p1_high,p2_low,p2_high,study1,study2)
  63. }
  64. return(res)
  65. }
  66. test_50=sim2(10000,0,0.1,0.3,0.1,0.2,0.25,0.25)
Add Comment
Please, Sign In to add comment