Lognormal in Vensim

Use this forum to post Vensim related questions.
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Lognormal in Vensim

Post by lorenzo.cioni »

Hi all
I tried to use the following relation X = e^N to transform a normal variable N (with mean value m and standard deviation s) in the lognormal variable X with the same parameters but when i run the simulation I get an overflow over X.
Any suggestion? Is the procedure correct? 8)
Best regards and best wishes
Lorenzo 8)
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Lognormal in Vensim

Post by Administrator »

Can you upload the model so we can take a look at the values you are using?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi
here is the model, many thanks for any suggestion. It may look strange since it does not use any stock but for my purposes it's ok.
Lorenzo
Attachments
ModelloEsponenzialeSoloMatGrezzi.mdl
(3.13 KiB) Downloaded 3213 times
Last edited by lorenzo.cioni on Sun Jan 15, 2017 5:40 pm, edited 1 time in total.
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Lognormal in Vensim

Post by Administrator »

This runs fine for me.

Can you let me know the exact version of Vensim you are using (click Help->About Vensim).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

PLE Plus for Windows 10. This is the error message I get:
ERROR: Fix floating point errors before entering SyntheSim mode.
ERROR: Floating point error computing - "C/100" - at time = 2.000000.
Trying to save the results anyway
Many thanks.
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

In single precision Vensim (i.e. any version but DSS DP), taking EXP(x) with x greater than about 30 will cause an overflow. In double precision you can get to something like x ~= 300. But either way, anything that big is unlikely to be meaningful, so I'd guess you have an error.

If you really have some value e^30 or greater, one option would be to add some logic to switch to a limiting case of the equation for large values.
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Sorry, I posted the wrong model, check this one. Same name but a small difference in one of the variables.
Lorenzo
Attachments
ModelloEsponenzialeSoloMatGrezzi.mdl
(3.11 KiB) Downloaded 3201 times
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Lognormal in Vensim

Post by Administrator »

Change the model so that
"C/100" = EXP(rn)"
rn = RANDOM NORMAL(0.5, 750 , 27.16 , 165.89 , 0 )

You'll see that at time = 3, the random number is 371.877 which causes the overflow.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Any handy solution?
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

Your formulation suggests that some quantity has a geometric mean of e^165 - what physical meaning does that have? It's more than the number of particles in the universe.
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

If you want x distributed lognormal, with mean(x) = 165, that's not what you have here. Your equation gives mean(log(x)) = 165.

The mean of the lognormal is exp(mu + sigma^2/2), where mu and sigma are parameters of the corresponding normal. The median and geometric mean of the lognormal are exp(mu).

Typically, I do something like:

x = geometric mean x * EXP( RANDOM NORMAL(-6,6,0,geometric sd x,0) )

The geometric sd can be thought of as the standard deviation expressed as a fraction of the mean.
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi tomfid
thank you for your reply. Can you tell me why your random normal has 6 paramaters whereas the one we can find in Vensim
RANDOM NORMAL( {min} , {max} , {mean} , {stdev} , {seed} )
has only five?
Moreover if I want to use a lognormal distribution with min, Max, m and S by implementing it with a combination of exp and random normal how can I proceed? This is the key point: I have some data that are described (through a statistical analysis) with a lognormal distribution and I have min, Max, average value n and standard deviation S for these data. In Vensim, at least in my version, we do not have a lognormal distribution but we have to produce it with a combination of exp and random normal but what about the transformation of the descriptive parameters?
Thank a lot to everybody for any help.
Lorenzo
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Lognormal in Vensim

Post by Administrator »

lorenzo.cioni wrote:thank you for your reply. Can you tell me why your random normal has 6 paramaters whereas the one we can find in Vensim
RANDOM NORMAL( {min} , {max} , {mean} , {stdev} , {seed} )
has only five?
I can only see five,
-6 {min}
6 {max}
0 {mean}
geometric sd x {stdev}
0 {seed}
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

You are right, sorry... what about the other issues?
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

The wikipedia article on the lognormal distribution, https://en.wikipedia.org/wiki/Log-normal_distribution, lists formulas for converting between the arithmetic and geometric means and variances.

If you have a sample of data, the natural thing to do is to compute the mean(log(data)) etc. directly. Look for "The location (μ) and scale (σ) parameters can be obtained if the arithmetic mean and the arithmetic variance are known:"
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi
sorry for the delay... first of all thank you a lot... I have still some doubts...
If from a statistical analysis of some data I find that they can be thought as being generated by a lognormal distribution with mean m and standard deviation s but the tool I use provides me only a normal distribution can I use the latter tool instead of the former with the following values
mean M = ln m
st. dev. S = ln s
or which are the correct values I have to use?
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

Suppose you have data

x=
10
100
1000

Compute

y = ln(x) =
2.3
4.6
6.9

Mean(ln(x)) = 4.6 and stdev(ln(x))=1.88. Note that exp(4.6)=100, as you'd hope.

Then you can generate a sample via:

z = mean_ln_x * EXP( RANDOM NORMAL( -6,6,0,stdev_ln_x,seed ))

You can do all this in Excel using the average() and stdevp() functions, or you can use the Stats tool in Vensim if you've imported the data.
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Perfect, thanks...
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

Oops! I goofed.

You want

z = EXP( mean_ln_x + RANDOM NORMAL( -6,6,0,stdev_ln_x,seed ))
or
z = geometric mean * EXP( RANDOM NORMAL( -6,6,0,stdev_ln_x,seed ))
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi tomfid
sorry to be boring but my collegues changed their mind and decided to work on data on a normal scale and so on a non logaritmic scale.
Can I use he formulas you gave me as they are or do I need to get hem modified and, if yes, in which way? Why do you use the values -6 and 6? Is it for convenience or do you have any other reason?
Thank you for your kind patience.
Lorenzo
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: Lognormal in Vensim

Post by Administrator »

If you need a normal distribution now, just use the RANDOM NORMAL function.

Without reading through the whole thread, I think the -6 and 6 were just examples.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

No, I need a lognormal distribution but the data are (now) on a linear (or raw) scale.
Lorenzo
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: Lognormal in Vensim

Post by tomfid »

If the actual distribution of the data is lognormal, it seems odd to work with the ordinary mean and variance, rather than the geometric mean and variance.

Be that as it may ...

geometric mean = ln( arithmetic mean / sqrt( 1 + arithmetic variance / arithmetic mean^2 ) )
geometric std dev = sqrt( ln( 1 + arithmetic variance / arithmetic mean^2 ) )

Then you can plug those into my formula.

The -6,6 just set limits that don't constrain the Normal distribution - i.e. six sigma is a one-in-a-million event.
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi tomfid
thank you a lot... I'll do my best to follow your instructions.
Lorenzo
lorenzo.cioni
Senior Member
Posts: 102
Joined: Wed Jul 30, 2014 7:09 am
Vensim version: PLE

Re: Lognormal in Vensim

Post by lorenzo.cioni »

Hi tomfid
one more question. If I use the method you gave me for a varibale, let's call it C, in Vensim I cannot use a Monte Carlo tecnique on C. So if I need to use a MC on C (that I know is lognormally distributed with known mu and sigma) is it possible to use a normal distribution? With which parameters?
Thank you and sorry to be boring (and maybe a little bit stupid too).
Lorenzo
Post Reply