Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to simulate lognormal distributions?

  1. May 17, 2012 #1
    I am studying statistics and am interested in understanding the log normal distribution. From some discussion I gather that the log normal distributions arises from multiplicative effects while the normal distribution arises from additive effects. I generated the following matlab code to simulate the normal distribution.

    clear
    for j = 1:10000
    S = 0;
    for i = 1:1000
    S = S + rand(1)-0.5;
    end
    T(j) = S;
    end
    hist(T,100)

    If you add a bunch of random numbers between -0.5 and 0.5 you get more or less a gaussian
    by the central limit theorem.

    Now I am interested in simulating the log normal distribution, but not sure what to do. Has anyone ever tried this. I saw that if the variance grows in time in certain stock market models you can get a log normal distribution. Also the number of proteins in cells is more or less log normal distributed.

    Thanks,
    jackaip
     
  2. jcsd
  3. May 17, 2012 #2

    Stephen Tashi

    User Avatar
    Science Advisor

    If you generate [itex] X [/itex] as a normal random variable then [itex] e^X [/itex] is a lognormal random variable.

    You should look at better algorithms for generating normal random variates. I don't know them by memory, but if I happen to run across one, I'll post it.
     
  4. May 18, 2012 #3

    chiro

    User Avatar
    Science Advisor

    Hey jackaip.

    If you can simulate a normal variable (if you don't have a tool, use R: it's free and you will able to do what you need in 5 minutes), then simply simulate a normal and then calculate a new variable which is eX which basically calculates the exponential of each realization created and stores this in another vector. This vector will be log-normally distributed.

    In R, this will look like:

    x = rnorm(10000,0,1)
    lognorm = exp(x)
    hist(lognorm)

    This will produce a histogram. If you want actual values just use lognorm and reference each component at location i using lognorm.

    If you need to do this in MATLAB, then basically generate a simulated normal and then just apply exp(x) where x is each generated value and throw that in a vector.
     
  5. May 18, 2012 #4
    Hi All!

    In fact R already has the log-normal distribution implemented, so simply rlnorm will suffice to generate those samples.

    And as for jackip's question, the algorithm to generate the normal distribution, in your code:

    Code (Text):
    for j = 1:10000
       S = 0;
       for i = 1:1000
          S = S + rand(1)-0.5;
       end
       T(j) = S;
    end
    You are using a random walk to generate the normal distribution which is extremely inefficient as well as inaccurate, so, I guess you do this not because you don't know better but rather because this way you can see how a normal distribution is constructed and, likewise, you'd like to see again how the log normal is constructed. Am I right?

    Well, if this is so you just need to change this T(j) = exp(S) in your code to converge to a log-normal distribution and, since S is a summatory, you can turn it into the following construction:

    Code (Text):
    for j = 1:10000
       S = 1;
       for i = 1:1000
          S = S * exp(rand(1)-0.5);
       end
       T(j) = S;
    end
    Which is even more inefficient and inaccurate but it gives you the rough understanding on how a log normal distribution is constructed which I guess is what you're looking for. right?
     
    Last edited: May 18, 2012
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to simulate lognormal distributions?
  1. Lognormal Distribution (Replies: 0)

  2. Lognormal distribution (Replies: 4)

Loading...