p = 0.7; n = 10; np <-‐ p*n; # n→∞ɺp→0ɺnp=Ұఆ n = 10000; p <-‐ np/n; alpha <-‐ 5 # ϕϧψʔΠʹै͏ཚੜ get_interval <-‐ function(){ cnt <-‐ 0 while (TRUE) { cnt <-‐ cnt + 1 if (rbern(1, p)==1){ return(cnt) } } } gen_exp_var <-‐ function() { data <-‐ data.frame(x=rdply(trial_size, get_interval())/n) names(data) <-‐ c("n", "x") return(data) } result <-‐ rlply(alpha, gen_exp_var()) data <-‐ data.frame(x=1/(result[[1]]$x + result[[2]]$x + result[[3]]$x + result[[4]]$x + result[[5]]$x)) # ٯΨϯϚͷີؔ dens <-‐ data.frame(y=dinvgamma(seq(0, 23,.01), shape=5, rate=1/np)*trial_size*width) ggplot() + layer(data=data, mapping=aes(x=x), geom="bar", stat = "bin", binwidth=width, fill="#6666ee", color="gray" ) + layer(data=dens, mapping=aes(x=seq(0,3,.01), y=y), geom="line", stat="identity", position="identity", colour="red" ) + ggtitle("Bernoulli to Inversegamma") 3ίʔυ ͷۂઢɿཧతͳ֬ ώετάϥϜɿཚ͔Βੜ ٯΨϯϚ