Re: [R] Multivariate normal density in C for R

2011-06-26 Thread Dimitris Rizopoulos
On 6/26/2011 5:53 PM, zerfetzen wrote: IIRC, package mvtnorm will allow an X matrix, but requires mu to be a vector, so although it's close, it won't do it all...but all suggestions are well received. Dimitrius, you don't happen to have the multivariate t form of that function, do you? Well, i

Re: [R] Multivariate normal density in C for R

2011-06-26 Thread zerfetzen
IIRC, package mvtnorm will allow an X matrix, but requires mu to be a vector, so although it's close, it won't do it all...but all suggestions are well received. Dimitrius, you don't happen to have the multivariate t form of that function, do you? -- View this message in context: http://r.789695

Re: [R] Multivariate normal density in C for R

2011-06-26 Thread Berend Hasselman
zerfetzen wrote: > > Does anyone know of a package that uses C code to calculate a multivariate > normal density? > > My goal is to find a faster way to calculate MVN densities and avoid R > loops or apply functions, such as when X and mu are N x K matrices, as > opposed to vectors, and in this

Re: [R] Multivariate normal density in C for R

2011-06-26 Thread zerfetzen
Dimitris, Thanks for the great code. When the number of rows of X and mu are large, it is probably faster due to R's vectorization. Thanks again. -- View this message in context: http://r.789695.n4.nabble.com/Multivariate-normal-density-in-C-for-R-tp3624602p3625857.html Sent from the R help maili

Re: [R] Multivariate normal density in C for R

2011-06-26 Thread Dimitris Rizopoulos
I use the following function which does not uses loops and seems to be pretty fast: dmvnorm <- function (x, mu, Sigma, df, log = FALSE) { if (!is.matrix(x)) x <- rbind(x) p <- nrow(Sigma) ed <- eigen(Sigma, symmetric = TRUE) ev <- ed$values if (!all(ev >= -1e-06 * abs

[R] Multivariate normal density in C for R

2011-06-25 Thread zerfetzen
Does anyone know of a package that uses C code to calculate a multivariate normal density? My goal is to find a faster way to calculate MVN densities and avoid R loops or apply functions, such as when X and mu are N x K matrices, as opposed to vectors, and in this particular case, speed really mat