Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a gaussian distribution with only positive numbers

Tags:

Is there any way to randomly generate a set of positive numbers such that they have a desired mean and standard deviation?

I have an algorithm to generate numbers with a gaussian distribution, but I don't know how to deal with negative numbers in a way the preserves the mean and standard deviation.
It looks like a poisson distribution might be a good approximation, but it takes only a mean.

EDIT: There's been some confusion in the responses so I'll try to clarify.

I have a set of numbers that give me a mean and a standard deviation. I would like to generate an equally sized set of numbers with an equivalent mean and standard deviation. Normally, I would use a gaussian distribution to do this, however in this case I have an additional constraint that all values must be greater than zero.

The algorithm I'm looking for doesn't need to be gaussian-based (judging by the comments so far, it probably shouldn't be) and doesn't need to be perfect. It doesn't matter if the resulting number set has a slightly different mean/standard deviation -- I just want something that will usually be in the ballpark.

like image 247
Whatsit Avatar asked Nov 05 '09 20:11

Whatsit


People also ask

Is normal distribution always positive?

A normal distribution can have negative values for some or all of its data points. A normal distribution can also have a negative mean. However, the standard deviation of a normal distribution is always positive – it is never negative or zero.

How do you generate positive random numbers in Matlab?

Use the rand , randn , and randi functions to create sequences of pseudorandom numbers, and the randperm function to create a vector of randomly permuted integers. Use the rng function to control the repeatability of your results.

What are the 2 values that define a Gaussian distribution?

All normal distributions can be described by just two parameters: the mean and the standard deviation.


2 Answers

You may be looking for log-normal distribution, as David Norman suggested, or maybe exponential, binomial, or some other distribution. If you have an algorithm to generate one distribution, it is probably not good for generating numbers conforming to another distribution. But only you know how your numbers are really distributed.

With normal distribution, the random variable's range is from negative infinity to positive infinity, so if you're looking for positive numbers only, then it is not Gaussian.

Different distributions also have unique properties, for example, with Poisson distribution, the standard deviations is always equal to the mean. (That's why your library function doesn't ask from the standard deviation parameter, only the mean).

In the worst case, you could generate a random real number between 0 and 1 and compute the probability density function on your own. (Depending on the distribution, this may be much easier said than done).

like image 79
azheglov Avatar answered Sep 22 '22 21:09

azheglov


You could use a log-normal distribution.

like image 45
David Norman Avatar answered Sep 22 '22 21:09

David Norman