COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### random number generator from t location scale distribution

• Email
• Follow

```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?
```
 0

See related articles to this posting

```"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

```
 0

```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
```
 0

```Thank you Roger and Peter,

this helped me to solve my problem.

Kind regards
```
 0