[R] Random numbers from noncentral t-distribution

Thomas Lumley tlumley at u.washington.edu
Fri Jun 30 18:00:45 CEST 2006


On Fri, 30 Jun 2006, Long Qu wrote:

> Hi there:
>
>  I'd thought these two versions of noncentral t-distribution are essentially the same:
>  > qqplot(rt(1000,df=20,ncp=3),qt(runif(1000),df=20,ncp=3))
>
>  But, the scales of the x-axis and the y-axis are quite different according to the QQ-plot.
>
>  Did I make any mistakes somewhere?
>

No, I think we did.

We have
> rt
function (n, df, ncp = 0)
{
     if (ncp == 0)
         .Internal(rt(n, df))
     else rnorm(n, ncp)/(rchisq(n, df)/sqrt(df))
}

and the rchisq() in the denominator should be inside the sqrt().


 	-thomas



More information about the R-help mailing list