Reputation:
I wanted to generate random variables from a multivariate t distribution in R. i am using the mvtnorm
package which has the command rmvt
for generating random variables from the multivariate t-distribution. Now my question is about the syntax of the function and being able to manipulate it to do what I want. The function requires the following
rmvt(n, sigma = diag(2), df = 1, delta = rep(0, nrow(sigma)),
type = c("shifted", "Kshirsagar"), ...)
where sigma is a correlation matrix. Now what I am having trouble with is how to sample from a multivariate t-distribution with mean m and covariance matrix S. Is the following the appropriate syntax?
rmvt(1,S,df=n) + m
or
rmvt(1,R,df=n)*sigma + m
where my covariance matrix can be decomposed as S = sigma*R (i.e., R is my correlation matrix). I am getting different results when I run the two lines of code so that is partially where my confusion stems from.
Upvotes: 2
Views: 5129
Reputation: 1510
Have a look at the help file for rmvt. There is says that sigma
is the scale (not correlation) matrix and that the correlation matrix, which is only defined for df>2
is given by sigma * df/(df-2)
. Therefore is you have a pre-specified covariance matrix S
then you should set
sigma=S*(D-2)/D
where D
is the degrees of freedom. To generate n
samples from the multivariate t-distribution with mean m
and covariance matrix S
you can either add the mean outside the call to rmvt
, as you indicated:
rmvt(n, sigma=S*(D-2)/D, df=D) + m
or by using the mu
argument:
rmvt(n, mu=m, sigma=S*(D-2)/D, df=D)
Edit: For whatever reason, rmvt
is not loading properly on my machine so I have to type this first to have the function loaded properly:
rmvt <- bfp:::rmvt
Upvotes: 4