[Rcpp-devel] rgamma() behavior

Dirk Eddelbuettel edd at debian.org
Tue Mar 25 01:05:06 CET 2014


On 24 March 2014 at 16:45, Kevin Ushey wrote:
| Hi Gregor,
| 
| This is probably worth a reminder as you say. Just for reference, the
| motivation is that R's internal computations for rexp and rgamma
| default to the 'scale' parameterization, rather than the 'rate'
| parameterization seen at the R level. Rcpp uses that internal
| operation and hence isn't consistent with what you see at the top
| level (even though it's consistent with the internals).
| 
| R-exts does give this a bit of treatment in
| http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Distribution-functions.
| 
| It's a bit awkward that the parameterizations differ at the R and C
| level, but it is what it is.

Kevin beat me to it but that is what I was about to say.  Rcpp sugar does
what the standalone R math library does (also at the C level).  

But you raise a good point, and we should add a note to the vignette.

Dirk

 
| Cheers,
| Kevin
| 
| On Mon, Mar 24, 2014 at 4:34 PM, Gregor Kastner <gregor.kastner at wu.ac.at> wrote:
| > Dear all,
| >
| > I believe it's the second time I just realized that Rcpp::rgamma() behaves
| > differently than to R's rgamma() when called without named arguments:
| >
| > ********** BEGIN code.R **********
| >
| > library(Rcpp)
| >
| > cppFunction('
| >     SEXP rgamma2(const int n, const double a, const double b) {
| >         RNGScope scope;
| >         return Rcpp::rgamma(n, a, b);
| >     }
| > ')
| >
| > set.seed(123);
| > print(rgamma(1, 2, 3));
| >
| > set.seed(123);
| > print(rgamma2(1L, 2, 3));
| >
| > set.seed(123);
| > print(rgamma2(1L, 2, 1/3));
| >
| > **********  END  code.R **********
| >
| > yields:
| >
| > [1] 0.2973645
| > [1] 2.676281
| > [1] 0.2973645
| >
| > Maybe this is worth a tiny note in e.g. the "Rcpp syntactic sugar" vignette?
| > Might save me (and possibly others) from realizing a third time.
| >
| > Best and thanks,
| > Gregor
| > _______________________________________________
| > Rcpp-devel mailing list
| > Rcpp-devel at lists.r-forge.r-project.org
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list