sbp.r (334B)
1 sbp = function(n, a) { 2 bundle = list(0, numeric(0)) 3 for (j in seq(n)) { 4 bundle = snap(bundle[[1]], bundle[[2]], a) 5 } 6 c(bundle[[2]], 1 - sum(bundle[[2]])) 7 } 8 9 snap = function(acc, bun, a) { 10 b = rbeta(1, 1, a) 11 stick = exp(log(b) + acc) 12 13 nacc = log (1 - b) + acc 14 nbun = c(bun, stick) 15 list(nacc, nbun) 16 } 17