Search code examples
algorithmrandomlogarithm

Pseudo-random Lognormal values


I'm trying to generate pairs of random values from two lognormal distributions - the catch is that one of them must be less than the other. For example:

a1 <- log(47.31)
b1 <- sqrt(2*log(50.84/47.31))
a2 <- log(47.31)
b2 <- sqrt(2*log(59.34/47.31))

x1 <- rlnorm(1,a1,b1)
x2 <- rlnorm(1,a2,b2)

I need some way of ensuring that x1 < x2. Is there any slick way to do this?


Solution

  • Well, yes and no. The simplest way is to check if the condition is met, and if not, regenerate the randoms. But the result of this is your variables are no longer characterized by the statistical distributions you started with: the filtering process biases x1 low and x2 high. But if you're okay with this, then just loop until the desired condition is met... in theory this could take an infinite number of iterations, but I assume you're not that unlucky :).

    If the two distributions are the same, it's simpler: just swap them if x1 > x2 (I assume they're not equal!)