Skip to content

identifying and drawing from T distribution

3 messages · Joshua Wiley, ivo welch

#
dear R experts:

fitdistr suggests that a t with a mean of 1, an sd of 2, and 2.6
degrees of freedom is a good fit for my data.

now I want to draw random samples from this distribution.    should I
draw from a uniform distribution and use the distribution function
itself for the transform, or is there a better way to do this?   there
is a non-centrality parameter ncp in rt, but one parameter ncp cannot
subsume two (m and s), of course.  my first attempt was to draw
rt(..., df=2.63)*s+m, but this was obviously not it.

advice appreciated.

/iaw

----
Ivo Welch (ivo.welch at gmail.com)
http://www.ivo-welch.info/
#
Hi Ivo,

Try something like this:

rt(1e5, df = 2.6, ncp = (1 - 0) * sqrt(2.6 + 1)/2)

The NCP comes from the mean, N, and SD.  See ?rt

Cheers,

Josh
On Fri, Mar 15, 2013 at 6:58 PM, ivo welch <ivo.welch at anderson.ucla.edu> wrote:
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://joshuawiley.com/
Senior Analyst - Elkhart Group Ltd.
http://elkhartgroup.com
#
actually, I had it right all along.  that is,

m<- runif(); s<- runif(); df<-runif()*10+1  # get some
parameters...any parameters
x <- rt( 100000, df )*s + m  # create random draws
library(MASS)
fitdistr(x, "t")  # confirm properties

will work.  (josh suggested working with the skewness parameter, ncp,
which solves a different problem.)

I believe that I was confused, because fitdistr will not necessarily
assign the sample mean to be its maximum-likelihood estimate of the
population mean.

/iaw