Skip to content

mvrnorm problem

5 messages · Stuart V Jordan, Peter Dalgaard, (Ted Harding) +2 more

#
Stuart V Jordan <sjordan at princeton.edu> writes:
You might, for at least two good reasons, have said that this is from
library(MASS). The point is that
Error in mu + eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X) :
        non-conformable arrays
Error in mu + eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X) :
        non-conformable arrays
[,1]       [,2]
 [1,]  0.5005327  1.1919216
 [2,]  2.8273925  2.7004788
 [3,]  2.6493970  1.1304274
....

and the docs quite clearly say that mu wants to be a vector, not a
matrix. 

Curiously enough, this works with rmvnorm from the mvtnorm package by
Genz, Bretz, and Hothorn, the difference being that this version adds
in the means with a sweep() operation, whereas mvrnorm just adds mu
(to the transpose of the ultimate result) and relies on recycling
rules. I.e. the point is that
Error in x + M : non-conformable arrays
Error in t(x) + M : non-conformable arrays
[,1] [,2]
[1,]    2    4
[2,]    4    6
[,1] [,2]
[1,]    2    4
[2,]    4    6
#
On 02-Feb-04 Stuart V Jordan wrote:
[...]

Hmmm ... using the same B and V as giben by Stuart Jordan, I get:
[1]  -179.8332342     0.9632282     2.5687489    -2.2337125    47.2717626
 [6] -3745.3844310     0.9632282     0.2839965    -0.1500585     0.5804460
[11]     5.1919420    -4.7381677    -0.2382119
Error in mu + eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X) : 
        non-conformable arrays

?????

Ted.

PS By the way, [near] singularity seems to have nothing to do
   with it here:
   If I brutally make V non-singular:

     diag(V) <- diag(V)+10000000

   it goes the same way.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 02-Feb-04                                       Time: 22:17:13
------------------------------ XFMail ------------------------------
#
Credits to Fritz: {rd}mvnorm moved from `e1071' to `mvtnorm' for
obvious reasons some time ago.

Best,

Torsten
#
As Peter Dalgaard has already pointed out, you both need to read the help 
page.

If you supply a matrix where the help page asks for a vector, you are 
likely to get troubles.  I will coerce it for the next version, but I 
would like to point out that in about 12 years of providing mvrnorm (often 
as here without credit), this it the first time anyone has made this error 
in public.  Anticipating what people will try is not easy.
On Mon, 2 Feb 2004 Ted.Harding at nessie.mcc.ac.uk wrote: