[Rcpp-devel] dmvnorm() of mvtnorm using RcppArmadillo

Qiang Kou qkou at qkou.info
Thu Dec 19 06:01:35 CET 2019


Please try the line below:

f(k) = *Rcpp::as<double>*(dmvnorm(x.row(k), mean,  sigma, give_log));

Best,

KK

On Wed, Dec 18, 2019 at 8:27 PM Shaami <nzshaam at gmail.com> wrote:

> Hi Dear
>
> I want to use dmvnorm() function into an cpp function using RcppArmadillo
> I am trying to execute the following function. It gives me error
>
> cannot convert 'SEXP' to 'double' in assignment
>
> Could you please guide where I am wrong?
>
> #include <RcppArmadillo.h>
> using namespace Rcpp;
> using namespace RcppArmadillo;
> using namespace arma;
>
> //[[Rcpp::depends(RcppArmadillo)]]
> //[[Rcpp::export]]
>
> arma::rowvec  dmvnormC(const arma::mat& x, const arma::vec& mean, const
> arma::mat& sigma, int give_log)
> {
>   Environment pkg = Environment::namespace_env("mvtnorm");
>   Function dmvnorm = pkg["mvtnorm"];
>   int N = x.n_rows;
>   arma::rowvec f(N, fill::zeros);
>   for(int k=0; k<N; k++)
>     {
>       f(k) = dmvnorm(x.row(k), mean,  sigma, give_log);
>     }
>   return f;
> }
>
> Thank you
>
> Shaami
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20191218/0ef405c9/attachment.html>


More information about the Rcpp-devel mailing list