Replaces the contents of the result variable with sizeNumber numbers randomly selected from the Lognormal distribution with the specified mean and standard deviation.
If the keyword exp is absent, the mean and standard deviation are taken to be those of the normal distribution that underlies the lognormal distribution. If the keyword exp is present, then the mean and standard deviation are taken to be those of the lognormal distribution itself.
The following program (in file "ResamplingPrograms/quakeProbability.txt")...
'Given: ' - The distribution of earthquakes is lognormal. ' - The mean time between quakes in a certain region ' is 1400 years ' - The standard deviation of the time between quakes is ' 120 years ' - The last quake was 1200 years ago 'Find: The probability that another quake will occur in ' the next 50 years. '(From: http://www.physics.utah.edu/~p5720/assgn/a07.html) ' COPY 1400 mean ' Mean time between earthquakes. COPY 120 stdDev ' Standard Deviation of time between ' earthquakes. COPY 1200 lastQuake ' Years since last quake. COPY 10000 trials ' Number of samples to generate. ' Generate samples of years since last quake till next one: LOGNORMAL exp trials mean stdDev nextQuake SUBTRACT nextQuake lastQuake years ' Years from now till ' next quake. COUNT years between 0 50 quakes ' Quakes between now and ' next 50 years. COUNT years >=0 futureQuakes ' past quakes don't count. DIVIDE quakes futureQuakes probability PRINT probability
produced this output:
Here are some subroutines that you might find useful when working with the lognormal distribution:
'The following subroutines compute values related to the 'lognormal distribution. The conventions for the variable 'names used in all these subroutines are these: ' m: mean of underlying Normal distribution ' s: Standard Deviation of underlying Normal distribution ' mu: the mean of the lognormal distribution ' sigma: Standard Deviation of the lognormal distribution 'These calculations were derived from the information at: 'http://www.riskglossary.com/link/lognormal_distribution.htm 'http://en.wikipedia.org/wiki/Log-normal_distribution 'STATS2NORM Converts lognormal stats to the stats of its underlying 'normal distribution. ' Inputs: mu, sigma ' Outputs: m, s ' NEWCMD STATS2NORM mu sigma m s @statistics \ ?"Converts lognormal stats to the stats of its underlying normal distribution." m = log(mu*mu/sqrt(sigma*sigma + mu*mu)) s = sqrt(log(sigma*sigma/(mu*mu) + 1)) END 'STATS2LOGNORM Converts stats of a normal distribution to 'the stats of its lognormal distribution. This is the inverse 'of the subroutine STATS2NORM above. ' Inputs: m, s ' Outputs: mu, sigma ' NEWCMD STATS2LOGNORM m s mu sigma @statistics \ ?"Converts stats of a normal distribution to the stats of its lognormal distribution." mu = exp((2*m + s*s)/2) sigma = sqrt(exp(2*m + 2*s*s) -exp(2*m + s*s)) END 'LOGNORMALPDF Computes the probability density function for 'the lognormal distribution given the statistics of the 'underlying normal distribution. ' Inputs: m, s, x ' Output: pdf, the Probability density function computed for ' each value in the x vector. NEWCMD LOGNORMALPDF m s x pdf @statistics \ ?"Computes the probability density function for the lognormal distribution given the statistics of the underlying normal distribution." CONST 6.283185307179586 twoPi pdf = exp(-0.5*((log(x) - m)/s)^2)/(x*s*sqrt(twoPi)) END