Question

I'm trying to get R's rWishart in stats to work within Rcpp. Here is a test example:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector rWishart_cpp(int p, int df, NumericMatrix Sigma) {
    return rWishart(p, df, Sigma);
}

The error I receive is: "test.cpp:12:12: error: use of undeclared identifier 'rWishart' return rWishart(p, df, Sigma);"

From one of the vignettes, I thought d/r functions were implemented in Rcpp courtesy of Rmath.h?

In any case, is there any way I can generate a wishart distribution within Rcpp?

Was it helpful?

Solution

The problem here seems to be that you assume Wishart is in Rmath.h when it isn't:

edd@max:~$ grep -i wish /usr/include/Rmath.h         # no Wishart
edd@max:~$ grep -i weib /usr/include/Rmath.h         # but Weibull has an example
#define dweibull        Rf_dweibull
#define pweibull        Rf_pweibull
#define qweibull        Rf_qweibull
#define rweibull        Rf_rweibull
        /* Weibull Distribution */
double  dweibull(double, double, double, int);
double  pweibull(double, double, double, int, int);
double  qweibull(double, double, double, int, int);
double  rweibull(double, double);
edd@max:~$ 

The best bet would be to get another implementation from somewhere and code that up via Rcpp.

Edit: Or based on two minutes worth of research at rdocumentation.org, you can probably follow the documentation of stats::rWishart and code this up as a function for multivariate Normals. I'd based this on RcppArmadillo....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top