rbs<-function(f,a,b,tol=1.0e-10,...){ if( abs(b-a) 0 ) stop("try new starting points") if( fa > 0 ) { tmp<-b b<-a a<-tmp } if(abs(fa) < abs(fb)) midold<-a else midold<-b while(T) { fb<-f(b,...) fa<-f(a,...) mid<-((fb*a-fa*b))/(fb-fa) if(abs(mid-midold) 0 ) { b<-mid } else { a<-mid } } } #The Poisson case, this works nicely... but now we need another function. (Note this is the upper tail value) rbspois <- function(x,lambda,p){log(p)-newpois(x,lambda)} newpois <-function(q,lambda) pgamma(q=lambda,shape=q,rate=1,log.p=T) #newpois(q,lambda)= P(X>=q,lambda) = 1-ppois(q-1,lambda)