Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
random variable skewness

Subject: random variable skewness

From: David

Date: 4 Feb, 2009 21:40:18

Message: 1 of 4

I am trying to create a random number generator that accounts for a mean, std, and skewness. of course I could use randn() if it was just mean and std, but I need to account for skewness since my number in reality can't be negative and a -sigma value would make it so. Is there some way to account for skewness in matlab? Or is it more complicated than that?
I understand the basics of random number generation, skewness and all that, but am by no means an expert. any help would be appreciated

Subject: random variable skewness

From: Roger Stafford

Date: 4 Feb, 2009 23:24:01

Message: 2 of 4

"David " <david.j.ellis@saic.com> wrote in message <gmd202$fs8$1@fred.mathworks.com>...
> I am trying to create a random number generator that accounts for a mean, std, and skewness. of course I could use randn() if it was just mean and std, but I need to account for skewness since my number in reality can't be negative and a -sigma value would make it so. Is there some way to account for skewness in matlab? Or is it more complicated than that?
> I understand the basics of random number generation, skewness and all that, but am by no means an expert. any help would be appreciated

  You could use something like the Gamma distribution which is never negative. Mathworks has the 'gamrnd' generator on the Statistics Toolbox. Its parameters can be set to match a desired mean and standard deviation. It has a skewness value but the amount of that is determined by the mean and standard deviation values. See the site http://en.wikipedia.org/wiki/Gamma_distribution. Maybe this will give you some ideas for other kinds of distributions.

Roger Stafford

Subject: random variable skewness

From: John D'Errico

Date: 5 Feb, 2009 00:05:05

Message: 3 of 4

"David " <david.j.ellis@saic.com> wrote in message <gmd202$fs8$1@fred.mathworks.com>...
> I am trying to create a random number generator that accounts for a mean, std, and skewness. of course I could use randn() if it was just mean and std, but I need to account for skewness since my number in reality can't be negative and a -sigma value would make it so. Is there some way to account for skewness in matlab? Or is it more complicated than that?
> I understand the basics of random number generation, skewness and all that, but am by no means an expert. any help would be appreciated

Look in Johnson, Kotz and Balakrishnan. They show
(if I recall properly) how to use a family of distributions
to produce a distribution that has a given set of the
first few moments.

In your case, as Roger suggests, you might use the
gamma distribution.

http://en.wikipedia.org/wiki/Gamma_distribution

As a function of the two parameters (k,theta) we
have

mean = k*theta
var = k*theta^2
skewness = 2/sqrt(k)

So if you wish to fit the three moments, you only
have two parameters, and they will be insufficient.
However, you can always use a three parameter
gamma distribution. The third parameter is an
origin offset, so it affects only the mean.

mean = origin + k*theta
var = k*theta^2
skewness = 2/sqrt(k)

So, given the skewness, compute k. This implies
a value for theta from the variance, then find the
origin offset from the mean.

HTH,
John

Subject: random variable skewness

From: Peter Perkins

Date: 9 Feb, 2009 15:53:55

Message: 4 of 4

David wrote:
> I am trying to create a random number generator that accounts for a mean, std, and skewness.

If you have access to the Statistics Toolbox, use PEARSRND or JOHNSRND, to generate values from either the Pearson System or the Johnson System of distributions. The former allows you to specify the first four moments, the latter allows you to specify desired quantiles.

Tags for this Thread

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.

Contact us