2
$\begingroup$

One of my class tasks is to make a simulation. I've gathered the data and done distribution fitting to it and the result of the distribution is log-normal. I have the code to generate random numbers in Java using a linear congruential generator, so can I somehow convert them to a log-normal distribution with parameters mu and sigma?

$\endgroup$
5
  • $\begingroup$ unclear: do you have to run a simulation or analyse data? $\endgroup$
    – Xi'an
    Commented May 16, 2015 at 6:42
  • $\begingroup$ i analyze a set of the data and make simulation based on it. $\endgroup$
    – theo
    Commented May 16, 2015 at 7:28
  • 1
    $\begingroup$ Sure - convert uniforms to the corresponding normal by any of the standard methods (Polar method, Box-Muller, inverse transform, ziggurat, etc etc) - and then exponentiate. $\endgroup$
    – Glen_b
    Commented May 16, 2015 at 9:28
  • $\begingroup$ and in which part i set the parameter for the distribution, because the lognormal dist in my case must follow specific mu and sigma $\endgroup$
    – theo
    Commented May 16, 2015 at 10:17
  • $\begingroup$ The mu and sigma are set when you transform to normality. Since this is for a class, you need to add the self-study tag and edit your question to follow the guidelines at its tag wiki, including explaining what you understand, outlining what attempts you made to solve your problem and identifying the specific help you need. $\endgroup$
    – Glen_b
    Commented May 31, 2015 at 23:26

1 Answer 1

6
$\begingroup$

You should be able to use your random number generator to get a random uniform $U \sim \mathcal{U}(0, 1)$ (just a random number between zero and one, the default for many random number generators). Then you can use the Box-Muller transform to get a random normal $X \sim \mathcal{N}(0, 1)$. This involves generating two random uniforms $U_1$ and $U_2$ and then forming the variables:

$$\sqrt{-2 \log(U_1)} \cos(2 \pi U_2)$$

and

$$\sqrt{-2 \log(U_1)} \sin(2 \pi U_2)$$

Both of these resulting random variables are normally distributed with mean $0$ and standard deviation $1$.

Finally, take one of your standard normals $X$. The transformation $e^{\mu + \sigma X}$ is the log-normal you're after.

Here's a quick implementation of this in R, plus a histogram to show it working its magic:

mu <- 0; sigma <- 1
u1 <- runif(50000); u2 <- runif(50000)
n <- sqrt(-2 * log(u1)) * cos(2 * pi * u2)
e <- exp(mu + sigma * n)
hist(e[e < 4], breaks=100)

lognormal

$\endgroup$
4
  • $\begingroup$ and where do i set my own parameters for lognormal (mu and sigma)? $\endgroup$
    – theo
    Commented May 16, 2015 at 7:29
  • $\begingroup$ In the exponentiation step $e^{\mu + \sigma X}$. $\endgroup$ Commented May 16, 2015 at 15:22
  • 1
    $\begingroup$ @MatthewDrury This looks like a good answer to the question. Unfortunately it also looks like you've completed (at least part of) the OP's homework for them, which isn't consistent with our policy. The idea is to give hints and guidance on anything which is effectively routine bookwork (as might be set for.homework, even when it isn't homework). $\endgroup$
    – Glen_b
    Commented May 31, 2015 at 23:24
  • $\begingroup$ @Glen_b I see that you are correct. I almost certainly did not read the introduction carefully enough, and the "one of my class tasks is to make a simulation" went through my head like noise. I'll be more careful in the future, thank you for the heads up. $\endgroup$ Commented Jun 1, 2015 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.