Simulating from a t distribution

Hello,

Maybe this is a silly question but I am trying to get simulations from a t distribution and cant find it. Any help?

 

Thanks.

3 Answers



0



The simplest way to accomplish this is by using the student-t inverse cdf to transform random uniform numbers like this:

proc (1) = rndT(rw, cl, df);
	retp(cdftci(rndu(rw, cl), df));
endp;

You can test that the distribution of your numbers is correct by checking to see what percentage of your numbers are less than a certain value and then comparing that with the T-CDF function:

rw = 1e5;
cl = 1;
df = 5;
r = rndT(rw, cl, df);
checkVal = 0.37;

comp = cdftc( checkVal, df);

//Since cdftc returns the compliment subtract 1
print (1 - comp);
print (sumc(r .<= checkVal))/rw;

proc (1) = rndT(rw, cl, df);
    retp(cdftci(rndu(rw, cl), df));
endp;

You can copy and paste the code snippet above to check. With a 'checkVal' of 0.37 both print statements should be about 0.636. You can change 'checkVal' to test other points.

I think there may be a faster method to make the random deviates in terms of the function rndGamma. But, I don't know it off the top of my head.

aptech

1,773


0



Thanks a lot. Basically my problem started because if you search in the help for this command that you showed me now "rndT", is non existent.

It would be good to include it I believe.

Best

Barbara



0



Sorry, my mistake, this is a function you are creating yourself. Please, disregard my last answer.

Best

Barbara

Your Answer

3 Answers

0

The simplest way to accomplish this is by using the student-t inverse cdf to transform random uniform numbers like this:

proc (1) = rndT(rw, cl, df);
	retp(cdftci(rndu(rw, cl), df));
endp;

You can test that the distribution of your numbers is correct by checking to see what percentage of your numbers are less than a certain value and then comparing that with the T-CDF function:

rw = 1e5;
cl = 1;
df = 5;
r = rndT(rw, cl, df);
checkVal = 0.37;

comp = cdftc( checkVal, df);

//Since cdftc returns the compliment subtract 1
print (1 - comp);
print (sumc(r .<= checkVal))/rw;

proc (1) = rndT(rw, cl, df);
    retp(cdftci(rndu(rw, cl), df));
endp;

You can copy and paste the code snippet above to check. With a 'checkVal' of 0.37 both print statements should be about 0.636. You can change 'checkVal' to test other points.

I think there may be a faster method to make the random deviates in terms of the function rndGamma. But, I don't know it off the top of my head.

0

Thanks a lot. Basically my problem started because if you search in the help for this command that you showed me now "rndT", is non existent.

It would be good to include it I believe.

Best

Barbara

0

Sorry, my mistake, this is a function you are creating yourself. Please, disregard my last answer.

Best

Barbara


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy