Skip to content

Instantly share code, notes, and snippets.

@ac00std ac00std/actuary_exam
Created Feb 12, 2018

Embed
What would you like to do?
ac_exam=function(n,p1_low,p1_high,p2_low,p2_high,study){
#n:持っている科目数
#p1_low:1次試験科目の合格率下限
#p1_high:1次試験科目の合格率上限
#p2_low:2次試験科目の合格率下限
#p2_high: 2次試験科目の合格率上限
#study:勉強により1科目だけ合格率を引き上げることができる
#year:受験年数
#year1:1次試験合格年数
#year2:2次試験合格年数
year=0
while(n<5){
year=year+1
k=rep(0,5)
t1=5-n
k[1]= rbinom(1, 1, runif(1,p1_low,p1_high)+study)
for(i in 2:t1){
k[i]=rbinom(1, 1, runif(1,p1_low,p1_high))
}
n=n+sum(k)
}
year1=year
while(n<7){
year=year+1
l=rep(0,2)
t2=7-n
l[1]= rbinom(1, 1, runif(1,p2_low,p2_high)+study)
for(j in 2:t2){
l[j]=rbinom(1, 1, runif(1,p2_low,p2_high))
}
n=n+sum(l)
}
year2=year
result=cbind(year1,year2)
return(result)
}
ac_exam(0,0.1,0.3,0.1,0.2,0.5)
#シミュレーションをN回行ってみる。
sim=function(N,n,p1_low,p1_high,p2_low,p2_high,study){
res=matrix(0,N,2)
for(i in 1:N){
res[i,]=ac_exam (n,p1_low,p1_high,p2_low,p2_high,study)
}
return(res)
}
test_50=sim(10000,0,0.1,0.3,0.1,0.2,0.5)
test_10=sim(10000,0,0.1,0.3,0.1,0.2,0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.