Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Rcpp中使用rWishart生成Wishart分发?_R_Rcpp - Fatal编程技术网

在Rcpp中使用rWishart生成Wishart分发?

在Rcpp中使用rWishart生成Wishart分发?,r,rcpp,R,Rcpp,我试图让R的rWishart在统计中在Rcpp中工作。下面是一个测试示例: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector rWishart_cpp(int p, int df, NumericMatrix Sigma) { return rWishart(p, df, Sigma); } #包括 使用名称空间Rcpp; //[[Rcpp::导出]] 数值向量rWishar

我试图让R的rWishart在统计中在Rcpp中工作。下面是一个测试示例:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector rWishart_cpp(int p, int df, NumericMatrix Sigma) {
    return rWishart(p, df, Sigma);
}
#包括
使用名称空间Rcpp;
//[[Rcpp::导出]]
数值向量rWishart_cpp(int p,int df,数值矩阵σ){
返回rWishart(p,df,Sigma);
}
我收到的错误是: “test.cpp:12:12:错误:使用未声明的标识符'rWishart' 返回rWishart(p,df,Sigma);”

从一个小插曲中,我认为d/r功能是在Rcpp中实现的,这是由Rmath.h


在任何情况下,是否有任何方法可以在Rcpp中生成wishart分布?

这里的问题似乎是您假设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:~$ 
最好的办法是从某处获得另一个实现,并通过Rcpp对其进行编码

编辑: 或者基于在的两分钟的研究,您可能可以遵循
stats::rWishart
的文档,将其作为多元正态分布的函数进行编码。我认为这是基于
RcppArmadillo…

根据@dirk的建议,我最近为armadillo编写了一个wishart函数的端口。它可以在这里使用:或者更有效地使用Wishart的Bartlett分解(Wishart见Wiki页面)。