简体   繁体   English

使用Rcpp中的rWishart生成Wishart分布?

[英]Generate Wishart Distribution using rWishart within Rcpp?

I'm trying to get R's rWishart in stats to work within Rcpp. 我正在尝试让R的rWishart的统计数据在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);" 我收到的错误是:“ test.cpp:12:12:错误:使用未声明的标识符'rWishart'返回rWishart(p,df,Sigma);”

From one of the vignettes, I thought d/r functions were implemented in Rcpp courtesy of Rmath.h? 从其中一个小插曲来看,我认为d / r函数是由Rmath.h提供的Rcpp实现的?

In any case, is there any way I can generate a wishart distribution within Rcpp? 无论如何,有什么方法可以在Rcpp中生成wishart分布吗?

The problem here seems to be that you assume Wishart is in Rmath.h when it isn't: 这里的问题似乎是您假设Wishart Rmath.h

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. 最好的选择是从某个地方获取另一个实现,然后通过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. 编辑:或者根据在rdocumentation.org上两分钟的研究,您可能可以遵循stats::rWishart的文档,并将其编码为多元法线的函数。 I'd based this on RcppArmadillo.... 我将基于RcppArmadillo ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM