> >
> > Do anybody know how to generate multivariate normal data from the
> > correlation matrix?
> > Is there any standard Splus program can do it?
> > Thank you for any comment.
> >
> > David Wang
In S-PLUS 4.0 there is the function rmvnorm to do this (although for the
taks to be well-defined you need a covariance matrix, not just a
correlation matrix). There is also a function mvrnorm in the V&R2 MASS
library, which is
# file MASS/mvrnorm.q
# copyright (C) 1994-8 W. N. Venables and B. D. Ripley
#
mvrnorm <- function(n=1, mu, Sigma, tol=1e-6)
{
p <- length(mu)
if(!all(dim(Sigma) == c(p,p))) stop("incompatible arguments")
eS <- eigen(Sigma, sym = T)
ev <- eS$values
if(!all(ev >= -tol*abs(ev[1]))) stop("Sigma is not positive definite")
X <- mu + eS$vectors %*% diag(sqrt(pmax(ev, 0))) %*% matrix(rnorm(p*n),p)
nm <- names(mu)
if(is.null(nm) && !is.null(dn <- dimnames(Sigma))) nm <- dn[[1]]
dimnames(X) <- list(nm, NULL)
if(n == 1) drop(X) else t(X)
}
As you will see, a lot of the code is devoted to niceties such as adding
variable names, treating the case n=1 and dealing with singularities.
(By the way, the copyright notice is there to help a particular group
of users: the corresponding licence (in the distribution) is not at all
restrictive.)
-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 ----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news