I would like to get some random values from a student t with specific mean and variance.
Is it right to use the command rt = (n, df, ncp)
to have two random samples with different variance? Do I have to vary the degrees of freedom?
example:
rt=(n=30,df=5)
rt=(n=20,df=10)
The rt
function follows the standard convention of the Student's t distribution which has it centered (mean 0) and the only parameter is the degrees of freedom. See the wikipedia page on the distribution for more explanation. If you want different means, you can add whatever mean you want to the 0-centered random variables you generate with rt()
. As Wikipedia shows, the variance v = df / (df - 2)
where df
is the degrees of freedom, so you can solve for what df
you need to get a specific variance.
For example, if you wanted a t-distributed random variable with mean 5 and variance 1.2, we can solve 1.2 = df / (df - 2)
to get df = 12
, and generate 100 samples with rt(n = 100, df = 12) + 5
.