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 number generator from t location scale distribution

Subject: random number generator from t location scale distribution

From: ArA Arns

Date: 1 Jul, 2010 08:32:07

Message: 1 of 4

Hi,
I'm trying to create a random number generator from the t location scale distribution.

At first I would do the following:

% for getting the parameters of my distribution
phat = mle(values,'dist','tlocationscale');

Te next step would be to create a random number
p = rand(length(values),1);

In the last step I would take the inverse of the cumulative distribution function which can be seen by searching "t Location-Scale Distribution" in the Matlab help.

Does the above described procedure look right or am I completely off track?

And the second question is, if anyone could please help me to fin the inverse of the cumulative distribution function?

Subject: random number generator from t location scale distribution

From: Roger Stafford

Date: 1 Jul, 2010 13:06:05

Message: 2 of 4

"ArA Arns" <doppela@gmx.de> wrote in message <i0hjq7$ajh$1@fred.mathworks.com>...
> Hi,
> I'm trying to create a random number generator from the t location scale distribution.
>
> At first I would do the following:
>
> % for getting the parameters of my distribution
> phat = mle(values,'dist','tlocationscale');
>
> Te next step would be to create a random number
> p = rand(length(values),1);
>
> In the last step I would take the inverse of the cumulative distribution function which can be seen by searching "t Location-Scale Distribution" in the Matlab help.
>
> Does the above described procedure look right or am I completely off track?
>
> And the second question is, if anyone could please help me to fin the inverse of the cumulative distribution function?
- - - - - - -
  Why not just do this:

 sigma*trnd(nu,m,n)+mu

using the student's t distribution random number generator, trnd, in matlab's statistics toolbox? That should get you the t location-scale distribution with parameters nu, mu, and sigma. See matlab's statistics toolbox user's guide.

  Of course you could always use that toolbox's tinv to compute the t locations-scale cdf inverse and then use rand, but I don't see the point in doing that when trnd is already available in the same toolbox.

Roger Stafford
 

Subject: random number generator from t location scale distribution

From: Peter Perkins

Date: 1 Jul, 2010 14:38:30

Message: 3 of 4

On 7/1/2010 4:32 AM, ArA Arns wrote:
> Hi,
> I'm trying to create a random number generator from the t location scale
> distribution.

Roger's suggestion is straight-forward. But since you have the
Statistics Toolbox, here's another way:

You already used the MLE function to fit a t location scale
distribution. It turns out that you can also use the FITDIST function
to do that, and return an object that the fitted t location scale
distribution. One of the things you can do with that is generate random
values from the fitted distribution:

 >> t = trnd(5,100,1);
 >> dist = fitdist(t,'tlocationscale')
dist =
tlocationscale distribution
     mu = -0.0570683
     sigma = 1.07074
     nu = 3.64601
 >> random(dist,5,1)
ans =
      -0.99189
      -0.94726
      -0.46287
       -1.9822
       0.75744

Sometimes, you know the parameters you want to use, and don't want to
fit to data. You can do that too:

 >> dist = ProbDistUnivParam('tlocationscale',[2,3,4])
dist =
tlocationscale distribution
     mu = 2
     sigma = 3
     nu = 4
 >> random(dist,5,1)
ans =
      -0.49685
        4.8959
        4.6588
        1.6293
       -1.9462

Subject: random number generator from t location scale distribution

From: ArA

Date: 2 Jul, 2010 06:10:22

Message: 4 of 4

Thank you Roger and Peter,

this helped me to solve my problem.

Kind regards

Tags for this Thread

No tags are associated with 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