dmvnorm (uses Sigma inverse)
This is a special form of the dmvnorm. You have to invert Sigma before passing it into this function, ie. Siginvf=solve(Sig).
double dmvnorm(Rcpp::NumericVector dataf, Rcpp::NumericVector meanf, Rcpp::NumericMatrix Siginvf )
{ RNGScope scope;
const double pi=3.141593; /* pi */
double send;
double d = dataf.size(); /* *.size() */
double four=0;
for (int i = 0; i < d; i++)
{ for (int j = 0; j < d; j++)
{ four=four + Siginvf(i,j)*(dataf(i)-meanf(i))*(dataf(j)-meanf(j));
}
}
/* pow() and exp() are touchy about 1/2 (int) and 0.5 (double) */
send= pow(2*pi,double(-d/2))*pow(det(Siginvf),0.5) *exp(-0.5*four);
return send;
}