Error with mvrnorm from library MASS

Marcello D'Orazio (
Wed, 21 Jan 1998 18:34:06 +0100

I'm trying to use the function mvrnorm from MASS with S-Plus vers. 3.3
but I receive an error message:

> mvrnorm(25, mu=rep(182,2), Sigma=diag(100,2))
Error in "%*%.default"(eS$vectors, diag(sqrt(max..: Number of columns of x
should be the same as number of rows of y

Could someone tell me were I'm wrong.

Thanks in advance,

P.S. I've found the following function in help pages about rnorm:

rmultnorm <- function(n, mu, vmat, tol = 1e-07)
p <- ncol(vmat)
stop("mu vector is the wrong length")
if(max(abs(vmat - t(vmat))) > tol)
stop("vmat not symmetric")
vs <- svd(vmat)
vsqrt <- t(vs$v %*% (t(vs$u) * sqrt(vs$d)))
ans <- matrix(rnorm(n * p), nrow = n) %*% vsqrt
ans <- sweep(ans, 2, mu, "+")

dimnames(ans) <- list(NULL, dimnames(vmat)[[2]])

This seems to work, but how much can I trust in it?

Marcello D'Orazio
Fac. of Economy, Univ. of Salerno
P.zza Guerrazzi, 1
82100 Benevento