How to use qnorm on Rcpp?

require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp") 

error: there is no corresponding function to call 'qnorm5 (double, int, int)

 require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );' ,plugin="Rcpp") 

error: there is no corresponding function to call 'qnorm5 (double, double, double, int, int)

 require(inline) code <-' double a = qnorm(0.95, 0.0, 1.0); return Rcpp::wrap( a ); ' func <- cxxfunction(, code ,plugin="Rcpp") func() 

error: there is no corresponding function to call "qnorm5 (double, double, double)

How to use qnorm for rcpp?

+4
source share
1 answer

Having done the mean and sd double arguments as the error message shows, try this full example

 library(inline) f <- cxxfunction(signature(xs="numeric", plugin="Rcpp", body=' Rcpp::NumericVector x(xs); return Rcpp::wrap(Rcpp::qnorm(x, 1.0, 0.0)); ') 

and take a look at the examples and unit tests β€” I just looked at the unit test runit.stats.R , which has many test cases for these statistical functions β€œRcpp sugar”.

Edit in 2012-11-14:. With Rcpp 0.10.0 released today, you can invoke the signature R::qnorm(double, double, double, int, int) if you want to use C style code written against Rmath.h . Rcpp sugar still gives you vectorized versions.

+7
source

Source: https://habr.com/ru/post/1401820/


All Articles