1 #include "bayesm.h"
2
3 // [[Rcpp::export]]
lndMvn(vec const & x,vec const & mu,mat const & rooti)4 double lndMvn(vec const& x, vec const& mu, mat const& rooti){
5
6 //Wayne Taylor 9/7/2014
7
8 // function to evaluate log of MV Normal density with mean mu, var Sigma
9 // Sigma=t(root)%*%root (root is upper tri cholesky root)
10 // Sigma^-1=rooti%*%t(rooti)
11 // rooti is in the inverse of upper triangular chol root of sigma
12 // note: this is the UL decomp of sigmai not LU!
13 // Sigma=root'root root=inv(rooti)
14
15 vec z = vectorise(trans(rooti)*(x-mu));
16
17 return((-(x.size()/2.0)*log(2*M_PI) -.5*(trans(z)*z) + sum(log(diagvec(rooti))))[0]);
18 }
19