Fast computation of the multivariate normal density.

1 |

`X` |
matrix n by d where each row is a d dimensional random vector. Alternatively |

`mu` |
vector of length d, representing the mean of the distribution. |

`sigma` |
covariance matrix (d x d). Alternatively it can be the cholesky decomposition of the covariance. In that case isChol should be set to TRUE. |

`log` |
boolean set to true the logarithm of the pdf is required. |

`ncores` |
Number of cores used. The parallelization will take place only if OpenMP is supported. |

`isChol` |
boolean set to true is |

A vector of length n where the i-the entry contains the pdf of the i-th random vector.

Matteo Fasiolo <matteo.fasiolo@gmail.com>

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ```
N <- 100
d <- 5
mu <- 1:d
X <- t(t(matrix(rnorm(N*d), N, d)) + mu)
tmp <- matrix(rnorm(d^2), d, d)
mcov <- tcrossprod(tmp, tmp) + diag(0.5, d)
myChol <- chol(mcov)
head(dmvn(X, mu, mcov), 10)
head(dmvn(X, mu, myChol, isChol = TRUE), 10)
## Not run:
# Performance comparison
library(mvtnorm)
library(microbenchmark)
a <- cbind(
dmvn(X, mu, mcov),
dmvn(X, mu, myChol, isChol = TRUE),
dmvnorm(X, mu, mcov))
# Check if we get the same output as dmvnorm()
a[ , 1] / a[, 3]
a[ , 2] / a[, 3]
microbenchmark(dmvn(X, mu, myChol, isChol = TRUE),
dmvn(X, mu, mcov),
dmvnorm(X, mu, mcov))
detach("package:mvtnorm", unload=TRUE)
## End(Not run)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.