Created
February 12, 2018 13:32
-
-
Save ac00std/a6770c9662958d15a5d652e3e708cd43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ac_exam2=function(n,p1_low,p1_high,p2_low,p2_high,study1,study2){ | |
#n:持っている科目数 | |
#p1_low:1次試験科目の合格率下限 | |
#p1_high:1次試験科目の合格率上限 | |
#p2_low:2次試験科目の合格率下限 | |
#p2_high: 2次試験科目の合格率上限 | |
#study1:勉強により科目1の合格率を引き上げることができる | |
#study2:勉強により科目2の合格率を引き上げることができる | |
#year:受験年数 | |
#year1:1次試験合格年数 | |
#year2:2次試験合格年数 | |
year=0 | |
while(n<4){ | |
year=year+1 | |
k=rep(0,5) | |
t1=5-n | |
k[1]=rbinom(1, 1, runif(1,p1_low,p1_high)+study1) | |
k[2]=rbinom(1, 1, runif(1,p1_low,p1_high)+study2) | |
for(i in 3:t1){ | |
k[i]=rbinom(1, 1, runif(1,p1_low,p1_high)) | |
} | |
n=n+sum(k) | |
} | |
while(n<5){ | |
year=year+1 | |
k=rep(0,5) | |
k[1]=rbinom(1, 1, runif(1,p1_low,p1_high)+study1+study2) | |
n=n+sum(k) | |
} | |
year1=year | |
while(n<6){ | |
year=year+1 | |
l=rep(0,2) | |
l[1]= rbinom(1, 1, runif(1,p2_low,p2_high)+study1) | |
l[2]= rbinom(1, 1, runif(1,p2_low,p2_high)+study2) | |
n=n+sum(l) | |
} | |
while(n<7){ | |
year=year+1 | |
l=rep(0,2) | |
l[1]= rbinom(1, 1, runif(1,p2_low,p2_high)+study1+study2) | |
n=n+sum(l) | |
} | |
year2=year | |
result=cbind(year1,year2) | |
return(result) | |
} | |
ac_exam2(0,0.1,0.3,0.1,0.2,0.25,0.25) | |
#シミュレーションをN回行ってみる。 | |
sim2=function(N,n,p1_low,p1_high,p2_low,p2_high,study1,study2){ | |
res=matrix(0,N,2) | |
for(i in 1:N){ | |
res[i,]=ac_exam2 (n,p1_low,p1_high,p2_low,p2_high,study1,study2) | |
} | |
return(res) | |
} | |
test_50=sim2(10000,0,0.1,0.3,0.1,0.2,0.25,0.25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment