Generate a random number from the mean and standard deviation of a lognormal distribution

I have calculated the Mean and Standard deviation from a list which fits to a lognormal distribution.
The values of mean and standard deviation are: 31.59299751 and 69.72271594 respectively.
I want to generate one random number to be given as an input.
Note: With the use of lognrnd(mu,sigma); I get strange values like 2.33+e^15, etc. Whereas, I require a number around the mean of the distribution (for e.g. 50.334, etc.)

 Accepted Answer

You need to compute the mean and sigma of the log normal distribution:
m=31.59299751;
s=69.72271594;
mu = log(m^2/sqrt(s+m^2))
sigma = sqrt(log(1+s/m^2))
lognrnd(mu,sigma)

6 Comments

You are correct with the above suggestion, but I am still seing inappropriate results.
I will explain the whole process that I followed.
Raw Data:(240 340 1740 6540 360). I use the Maxiumum likelihood estimation (MLE) for finding the corresponding mean and variance. It is explained in http://engineer.jpl.nasa.gov/practices/at2.pdf.
I get the outputs as 6.688604282 (MLE-Mean) and 1.959390892 (MLE-Variance).
Further, I estimate the MEAN and ST. Dev. That comes to 2139.440719 and 5281.864544.
Then when I use the above formulas you mentioned, I get the outputs 3.330049825 and 0.000901859.
This is no where near the RAW values which were used as input.
MLE already estimates the lognormal distribution parameters, you don't have to reapply above formulae. use:
Is that your sample size? its too small to get back a close estimate.
Yes, for some cases I have quite small sample size. But for some, I have better raw data.
As far as 'lognstat', it is used if I have the mu and sigma of the normal distribution. The MLE formulas I apply is for the Normal distribution. (The link I mentioned in the previous comment)
Do let me know if my understanding is wrong.
For normal distribution MLE estimates are equal to mean(data) and std(data). You can then pass this mean and std to lognstat to get the lognormal distribution parameters.
However just to clarify so that there are no confusions, lognrnd which I mentioned earlier accepts the mean and std of normal distribution (not the output of lognstat which are the parameters of the lognormal distribution)
R = lognrnd(mean(data),std(data));
@ Shashank- Though I understood the concept you explained before, I need to still clear one doubt.
I derived the Mean as - 11.5hrs and standard deviation as- 9.14 hrs from the MLE approach I mentioned before. (The parameters are that of a lognormal distribution.)
[I understand the reason for such high standard dev. is the less number of raw inputs. Also, the values are quite varying.]
THe question is- My model needs ONLY one value of time (ONE INPUT) taking the mean and st. dev. both. Which Matlab function should be used then? (For e.g. a value like (11.5 +/- 9.14)hrs.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!