Dear Sir

Here is my MWE.

I am still getting the follwoing error.

Error in dmvnormC(x, mean, sigma, 0) : Cannot convert object to a function:
[type=NULL; target=CLOSXP, SPECIALSXP, or BUILTINSXP].

Could you please guide what is going wrong?
y <- matrix(1:10, nrow=5)
mean <- c(4, 5)
sigma <- matrix(c(0.01, 0.009, 0.009, 1.2), nrow =2, byrow = TRUE)
dmvnormC(y, mean, sigma, 0) # Function is below.
#include <RcppArmadillo.h>
#include <mvtnormAPI.h>
using namespace Rcpp;
using namespace RcppArmadillo;
using namespace arma;

//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::depends(mvtnorm)]]
//[[Rcpp::export]]

arma::vec  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);
  for(int k=0; k<N; k++)
    {
      f(k) = Rcpp::as<double>(dmvnorm(x.row(k), mean,  sigma, give_log));
    }
  return f;
}


Thank you


On Fri, Dec 20, 2019 at 12:19 AM Ralf Stubner <ralf.stub...@gmail.com>
wrote:

>
>
> On Thu, Dec 19, 2019 at 8:01 AM Shaami <nzsh...@gmail.com> wrote:
>
>>   Environment pkg = Environment::namespace_env("mvtnorm");
>>   Function dmvnorm = pkg["mvtnorm"];
>>
>
> There is no mvtnorm function in the mvtnorm package. You probably want to
> dmvnorm function instead.
>
> BTW, the mvtnorm package provides a C API for the dmvnorm function, c.f.
> https://stackoverflow.com/a/51294364/8416610
>
> cheerio
> ralf
>
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to