How to generate random variable from t distribution with mean and scale

So the question is
How can I take 1000 draws from univariate Student-t distributions with mean = 1.5, scale = 2 and
degrees of freedom nu = 3; 5; 10; 20; 30; 60

1 Comment

nu = 3;
sigma = 2;
mu = 1.5;
V = nu * sigma + mu;
x = (-5:0.1:30)';
nct = nctpdf(x,nu,V);
t = tpdf(x,nu);
plot(x,nct,'b-','LineWidth',2)
hold on
plot(x,t,'g--','LineWidth',2)
legend('nct','t')
This is my code. Is this correct?

Sign in to comment.

Answers (1)

I don't see that your code is correct, because it does not take 1,000 draws from anything, which is what you said you want to do.
Actually, it is not clear what you mean by "univariate t-distribution with mean=1.5, scale=2" and any specific df value. Apparently you want a noncentral t-distribution, which is required to give you a nonzero mean. That distribution has a noncentrality parameter and a df parameter, but that is all--there is no separate scale parameter.
Using the Cupid routines, maybe this will give you what you want:
df = 10; % for example
noncentrality_guess = 0.8; % This will soon be adjusted to give the desired mean of 1.5.
myt = tNoncentral(df,noncentrality_guess); % Construct a noncentral t distribution with these parameters.
myt.EstMom(1.5,'fr'); % Adjust the noncentrality parameter to give a distribution mean of 1.5
randvals = myt.Random(1000,1); % Generate 1,000 draws from the adjusted noncentral t.

Asked:

on 7 Apr 2019

Answered:

on 8 Apr 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!