Skip to content

generating multivariate normal random numbers in C

5 messages · Mathieu Ros, Thomas Lumley, Brian Ripley

#
hello all,
I'm looking for a C/C++ library (or algorithm) to compute draws from a
multivariate normal distribution in order to do block sampling.
(I'm plugging my results in an R function so this is not really off
topic ;)
thanks for your help,
  Mathieu
#
On Tue, 26 Jun 2001, Mathieu Ros wrote:

            
In that case, why not use mvrnorm() in the MASS package? It's not in C,
but it doesn't need to be.

	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#

        
TL> On Tue, 26 Jun 2001, Mathieu Ros wrote:
>> hello all, I'm looking for a C/C++ library (or algorithm) to
    >> compute draws from a multivariate normal distribution in order
    >> to do block sampling.  (I'm plugging my results in an R
    >> function so this is not really off topic ;)

    TL> In that case, why not use mvrnorm() in the MASS package? It's
    TL> not in C, but it doesn't need to be.

Well, as I just replied to prof. Rossini, I'm doing about 50000
iterations (up to 100000) with at least 88 parameters to update at each turn
(at least 2x4 + 2x40 if I do block sampling).
I don't know much about R/C interface but I believe it will slow down
my program if I call an R function to do the job.
My elementwise sampling algorithm (C code) takes between 3 and 4
hours to run (with intermediate data sets).
Thanks for the quick reply,
  Mathieu
#
On Tue, 26 Jun 2001, Mathieu Ros wrote:

            
mvrnorm in package MASS (in bundle VR).

  
    
#
On Tue, 26 Jun 2001, Mathieu Ros wrote:

            
Well, it's an elementary computation once you have a random normal
generator and a numerical linear algebra suite.  For 88 dimensions (if I
understand you aright) the issue is going to be the matrix decomposition.
Is this the same multivariate normal distribution at each draw?  If so
just write a binary file using writeBin: it will not slow you down.  If it
is different each time the linear algebra computations will be slow enough
to swamp the communications overhead.