Solved

Getting a value from Standard Dev, and Mean

Posted on 2004-09-29
8
504 Views
Last Modified: 2008-02-01
Hi all,

I have the Mean and Standard Deviation of a variable. This variable is cost, and this will vary for each entity. Using the mean and SD can someone tell me how I would create a random number based on lognormal.

For example if the SD is 1 and the mean is 50, I would expect the result to produce (mainly) between 49 and 51. (I understand that this isnt always true by the very nature of the curve).

I am making the tool in Java, which contains method nextGaussian() to return a random number normal distrubution between 0 and 1.

Many thanks,

H
0
Comment
Question by:wazdaka
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:wazdaka
Comment Utility
sorry, nextGaussian() uses mean 0.0 and SD 1. Not sure if this helps at all.
0
 
LVL 27

Accepted Solution

by:
d-glitch earned 125 total points
Comment Utility
[Your Mean]  + [Your SD] * nextGaussian()      should give you what you want
0
 
LVL 27

Expert Comment

by:d-glitch
Comment Utility
nextGaussian() should give you a normal curve centered around zero with SD = 1

Multiplying by  [Your SD] spreads (or shrinks) the width of the curve.

Adding [Your Mean]  shifts the curve up to where you want it centered.

You may have to check for negative values:  If your mean was 5 and your SD is one, nextGaussin() will return values <5 once every million calls.
0
 
LVL 27

Expert Comment

by:d-glitch
Comment Utility
You may have to check for negative values:  If your mean was 5 and your SD is one, nextGaussin() will return values < -5 once every million calls.

That's negative 5.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:wazdaka
Comment Utility
Perfect, thank you very much. I should always be shifting the curve up enough to not worry about negatives bu I'll take the absolute value of the result just in case.

Thanks again

H
0
 
LVL 7

Expert Comment

by:wytcom
Comment Utility
A lower level, more work but more flexibility, approach is to generate a uniformly distributed random number and then project it onto the gaussian distribution to find the corresponding gaussian coordinate.  This isn't too hard to do:

Generate a uniformly distributed number x where  0 <= u < 1

Set the number of standard deviations you want to cover in your gaussian: Nsd = 40

Set a left bound for the range of your Gaussian distribution: gl = m - sd*Nsd

Set a right bound for the range of your Gaussian distribution: gr = m + sd*Nsd

Set the number of intervals to divide the Gaussian distribution into: N = 200

Set the initial coordinate to g = gl

Set the interval to dg = (gr - gl)/N

Write a subroutine to return the height of the gaussian given the coordinate value g (as well as the mean and standard deviation) = G(g)

Now start at the left bound and begin to sum the value of the Gaussian curve at coordinate g = gl.  Increment g = gl + dg and accumulate G(g) into the sum.  So far we have sum = G(gl) + G(gl + dg) ...

Continue this summation until the sum is greater than or equal to u (your uniformly distributed random number).  The last value of g used is the gaussian coordinate sought.

The idea here is that the integration over the guassian distribution gives the probability of occurence of coordinate less than or equal to g.  We simply sum here as our approximate integration.

This technique can be applied to any distribution you need, not just the gaussian.
0
 
LVL 7

Expert Comment

by:wytcom
Comment Utility
Oops:  

Generate a uniformly distributed number x where  0 <= u < 1

   should be

Generate a uniformly distributed number u where  0 <= u < 1
0
 
LVL 7

Expert Comment

by:wytcom
Comment Utility
Oops:

Continue this summation until the sum is greater than or equal to u (your uniformly distributed random number).

  should be

Continue this summation until the sum*dg is greater than or equal to u (your uniformly distributed random number).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Math question / mortgage loan question 4 127
Vertex form of the function 8 48
Linear algebra 3 52
Permutation and Combination 9 45
Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now