[Rcpp-devel] rgamma() behavior
Kevin Ushey
kevinushey at gmail.com
Tue Mar 25 00:45:45 CET 2014
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.
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
More information about the Rcpp-devel
mailing list