MATLAB: Random t distribution sample

randomt-distribution

Hi!
I want to obtain a random sample of outcomes which follows a t student distribution given a mean and a std.
I have been able to create a sample of 1000 observations which follow normal dist. typing A=random('norm',mean,std,1000,1).
How should I do it for a t distribution?
Thanks in advance!

Best Answer

Because the expression for the variance depends on the noncentrality parameter and the degrees of freedom. If you plug in a noncentrality parameter of 2 and degrees of freedom of 100 into the expression for the variance of the noncentral t-distribution and then take the square root, you get a value near 1.
dof = 100;
ncentparam = 2;
ncentvar = ...
(dof*(1+ncentparam^2))/(dof-2)-...
(ncentparam^2*dof)/2*(gamma((dof-1)/2)/gamma(dof/2))^2
sqrt(ncentvar)
Wayne
P.S. On MATLAB Answers you are supposed to accept the answer if you have had your question answered so other people know that they don't have to answer it.