簡體   English   中英

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

[英]Generate Wishart Distribution using rWishart within 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);
}

我收到的錯誤是:“ test.cpp:12:12:錯誤:使用未聲明的標識符'rWishart'返回rWishart(p,df,Sigma);”

從其中一個小插曲來看,我認為d / r函數是由Rmath.h提供的Rcpp實現的?

無論如何,有什么方法可以在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進行編碼。

編輯:或者根據在rdocumentation.org上兩分鍾的研究,您可能可以遵循stats::rWishart的文檔,並將其編碼為多元法線的函數。 我將基於RcppArmadillo ....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM