Closed linzhp closed 10 years ago
Thanks for the request.
A couple of suggestions/comments before merging:
m$pars
is correctresult = numeric(n)
log(m$xmin -0.5)
since we are discretising the distribution.u = runif(n, 0, exp(-m$pars*(m$xmin-0.5)))
-log(u)/m*pars
will work - I just rearranged the standard exponential random number algorithm.
What do you think?
Thanks for the comments. I will address them and update the pull request.
Question: in the lognormal RNG, wouldn't min <- round(log(m$xmin))
be better than min <- log(m$xmin -0.5)
?
I think you're correct about rounding xmin
. A couple of other points I just thought of:
dist_pdf
n
values on average we will discard plnorm(xmin-0.5, m$pars[1],m$pars[2], lower.tail=TRUE)
So simulate (something like)ceiling(n/plnorm(m$xmin-0.5, m$pars[1],m$pars[2], lower.tail=FALSE))
I've updated the pull request according to your suggestions. However, I don't understand what
ceiling(n/plnorm(m$xmin-0.5, m$pars[1],m$pars[2], lower.tail=FALSE))
does.
I used
r<-dist_rand(exponential, 1000)
plot(density(r, from=min(r)))
curve(dexp(x, exponential$pars), from=min(r), to=max(r))
to visually compare the two pdfs
@csgillespie
Please review. Specifically, please confirm my use of m$pars in disexp$dis_rand is correct.
Thanks!