TABLE OF CONTENTS


CmiscUtils/mvrnorm [ Functions ]

NAME

    mvrnorm --- multivariate normal random numbers

FUNCTION

Generate multivariate normal random numbers, given a mean and Cholesky-factored covariance matrix.

SYNOPSIS

577 static inline void mvrnorm(int n, double *out, double *mu, double *CholSigma, double tun)

INPUTS

    n         length of the vector to be generated
    out       storage for output of length n
    mu        mean vector (length n)
    CholSigma Cholesky factorization of the covariance matrix nxn
    tun       tuning parameter for the variance

SOURCE

581 {
582     double * temp = (double *) malloc(n * sizeof(double));
583     // iid N(0,1) random numbers:
584     for(int i=0; i<n; i++) temp[i] = rnorm(0,1);
585     int c1=1; 
586     char trans='T';
587     double c0=0;
588     double c1d=1;
589     double sqrttun = sqrt(tun);
590     // set out = 0*out + t(Ch)%*%temp
591     F77_CALL(dgemv)(&trans, &n, &n, &sqrttun, CholSigma, &n, temp, &c1, &c0, out, &c1);
592     // out = out + mu
593     F77_CALL(daxpy)(&n, &c1d, mu, &c1, out, &c1);
594     free(temp);
595 }