Sampling from the t-distribution in R

How can I choose from a t-distribution in R when I want to indicate degrees of freedom (df), mean and variance? For example, how will I choose from a t-distribution with 8 df, average = 4, and variance = 16? I assume that I need to use the off-center parameter in some way, but I'm not sure how to do this.

+4
source share
2 answers

Do you want off-center t or just scaled and offset (central) t? To select from the t distribution with location m and scaling parameter s do

 rt(N, df=df)*s + m 

The dispersion of the distribution t df/(df-2) , therefore, to obtain a specific dispersion v :

 rt(N, df=df)*sqrt(v * (df-2)/df) + m 
+11
source

If you look at the code for rt , you will see that random variations from off-center t are returned from:

 rnorm(n, ncp)/sqrt(rchisq(n, df)/df) 

Thus, the noncentrality parameter is assigned rnorm as the average for the numeral distribution.

0
source

Source: https://habr.com/ru/post/1493285/


All Articles