Thread Subject: help with generating skewed distribution?

Subject: help with generating skewed distribution?

From: Anna Chen

Date: 15 Aug, 2008 15:09:02

Message: 1 of 4

Hello,
I would like to generate a population of numbers, from 1-
100 for example, distributed almost uniformly. However, I
want the larger numbers to have more chance of popping up,
so the population skews to the left.
how would i be able to do this with matlab 2008? i had
thought of using randsrc, but for some reason it's not in
my version? i have the statistics toolbox, if that helps.
thanks!

Subject: help with generating skewed distribution?

From: Donn Shull

Date: 15 Aug, 2008 15:32:03

Message: 2 of 4

"Anna Chen" <icedredtea@yahoo.com> wrote in message
<g8466e$amb$1@fred.mathworks.com>...
> Hello,
> I would like to generate a population of numbers, from 1-
> 100 for example, distributed almost uniformly. However,
I
> want the larger numbers to have more chance of popping
up,
> so the population skews to the left.
> how would i be able to do this with matlab 2008? i had
> thought of using randsrc, but for some reason it's not in
> my version? i have the statistics toolbox, if that helps.
> thanks!

randsrc is part of the Communications Toolbox.

Subject: help with generating skewed distribution?

From: Bruno Eklund

Date: 20 Aug, 2008 12:05:02

Message: 3 of 4

"Anna Chen" <icedredtea@yahoo.com> wrote in message
<g8466e$amb$1@fred.mathworks.com>...
> Hello,
> I would like to generate a population of numbers, from 1-
> 100 for example, distributed almost uniformly. However,
I
> want the larger numbers to have more chance of popping
up,
> so the population skews to the left.
> how would i be able to do this with matlab 2008? i had
> thought of using randsrc, but for some reason it's not
in
> my version? i have the statistics toolbox, if that
helps.
> thanks!


Hi Anna,
this is how you can do it. It's actually a general way of
drawing random numbers from any distribution. Start by
defining what kind of distribution you want. You said you
used a uniform distribution, p(x) = 1/100 for x=1,...,100.
Let's assume you instead want to use, for example, a
triangular distribution, p(x) = constant * x for
x=1,...,100. Of course, you need to set the constant such
that the function sum to one, that is p(1)+...+p(100)=1.
In this case the constant is 1/5050, so p(1) = 1/5050 and p
(100) = 100/5050. Next step is to construct the cumulative
distribution, which in fact would correspond to stacking
the 100 probability bars on top of each other.
Now draw a uniform random number between zero and one.
Compare this number with your cumulative distribution and
make a note within which probability bar the drawn random
number lies. The x value corresponding to that probability
bar would then be a draw from your desired triangular
distribution. For example assume that, to make it more
easy for me, you drew the number 0.9851 from the uniform
distribution. Comparing this number with the cumulative
distribution you'll see that it lies within the last
probability bar, since the last bar is 0.0198 tall. You
can thus conclude that x=100 is a draw from your desired
triangular distribution. Continuing like this you'll note
that, in the long run, the drawn uniform number will "hit"
taller probability bars more often that shorter ones
implying more frequent draws from larger x numbers, just
as you wanted.
Best of luck

Subject: help with generating skewed distribution?

From: Peter Perkins

Date: 20 Aug, 2008 13:44:01

Message: 4 of 4

Anna Chen wrote:

> I would like to generate a population of numbers, from 1-
> 100 for example, distributed almost uniformly. However, I
> want the larger numbers to have more chance of popping up,
> so the population skews to the left.


As long as you mean, "the integers from 1 to 100", and as long as you're willing to actually specify all 100 probabilities, then RANDSAMPLE is just what you need. You might take a look at DISTTOOL, and the beta distribution. While this is a continuous dist'n defined on the unit interval, you can fiddle with the parameters to get roughly the shape you're looking for, a=3, b=1, for example. Then use BETAPDF to evaluate the beta density on (1:100)/101, normalize those values to sum to 1, and pass that to RANDSAMPLE, something like

   p = betapdf((1:100)/101,3,1);
   randsample(1:100,n,true,p/sum(p))

Hope this helps.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com