On 01-May-05 Peter Dalgaard wrote: > (Ted Harding) <[EMAIL PROTECTED]> writes: >> Something like the following code will do the job vectorially: >> >> n<-1000 # desired size of sample >> T<-3.5 # pre-truncation mean of Poisson >> U<-runif(n) # the uniform sample >> t = -log(1 - U*(1 - exp(-T))) # the "first" event-times >> T1<-(T - t) # the set of (T-t) >> >> X <- rpois(n,T1)+1 # the final truncated Poisson sample >> >> The expected value of your truncated distribution is of course >> related to the mean of the pre-truncated Poisson by >> >> E(X) = T/(1 - exp(-T)) > > There must be an easier way... Anything wrong with > > rtpois <- function(N, lambda) > qpois(runif(N, dpois(0, lambda), 1), lambda) > > rtpois(100,5) > > ?
Well, that's neat! (When I saw that, I had to switch in backup-brain to think clearly about qpois, but there you are ... ) Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 01-May-05 Time: 21:20:43 ------------------------------ XFMail ------------------------------ ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
