How to simulate lognormal distributions?

  • Thread starter Thread starter jackaip
  • Start date Start date
  • Tags Tags
    Distributions
Click For Summary
To simulate a lognormal distribution, one can start by generating a normal random variable and then applying the exponential function to each value. This can be done easily in R using the command `lognorm = exp(rnorm(10000,0,1))`, which produces a lognormal distribution histogram. In MATLAB, the process involves modifying the existing normal distribution code to compute `T(j) = exp(S)` instead of just summing random values. Additionally, an alternative approach to understand the construction of a lognormal distribution is to use a multiplicative process, where values are generated by multiplying random exponentials. This method, while less efficient, provides insight into the underlying mechanics of 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:
The standard _A " operator" maps a Null Hypothesis Ho into a decision set { Do not reject:=1 and reject :=0}. In this sense ( HA)_A , makes no sense. Since H0, HA aren't exhaustive, can we find an alternative operator, _A' , so that ( H_A)_A' makes sense? Isn't Pearson Neyman related to this? Hope I'm making sense. Edit: I was motivated by a superficial similarity of the idea with double transposition of matrices M, with ## (M^{T})^{T}=M##, and just wanted to see if it made sense to talk...

Similar threads

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