How to simulate lognormal distributions?

  • Context: Undergrad 
  • Thread starter Thread starter jackaip
  • Start date Start date
  • Tags Tags
    Distributions
Click For Summary

Discussion Overview

The discussion centers on simulating lognormal distributions, particularly in the context of statistics and programming. Participants explore methods for generating lognormal data using MATLAB and R, while also discussing the theoretical underpinnings of lognormal versus normal distributions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant, jackaip, describes their interest in lognormal distributions and shares MATLAB code for simulating normal distributions, noting the connection between multiplicative effects and lognormal distributions.
  • Another participant suggests that generating a normal random variable and then applying the exponential function will yield a lognormal variable, providing a brief example in R.
  • A third participant reiterates the R method for generating lognormal distributions and critiques jackaip's approach as inefficient, proposing an alternative method using a product of exponentials instead of a sum.
  • There is a discussion about the efficiency and accuracy of different methods for simulating normal and lognormal distributions, with some participants questioning the rationale behind the chosen methods.

Areas of Agreement / Disagreement

Participants generally agree on the method of generating lognormal distributions from normal distributions, but there are differing opinions on the efficiency and accuracy of various approaches. The discussion remains unresolved regarding the best method to use.

Contextual Notes

Participants express concerns about the inefficiency of certain algorithms for generating normal distributions, but do not reach a consensus on the most effective approach for simulating lognormal distributions.

jackaip
Messages
1
Reaction score
0
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
 
Physics news on Phys.org
If you generate X as a normal random variable then e^X 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.
 
jackaip said:
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

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.
 
Hi All!

chiro said:
In R, this will look like:

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

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:
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:
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:

Similar threads

  • · Replies 24 ·
Replies
24
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
6K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K