[Rcpp-devel] Favourite Rcpp examples for newbies ?

Jonathan Olmsted jolmsted at princeton.edu
Thu Aug 1 17:31:05 CEST 2013


Just my quick thoughts:

Bayesian MCMC is what brought me to Rcpp. So, I have always found those
examples the most compelling. This is precisely because good R coding can't
improve performance on these problems and the gain in computational
performance really justified the development cost as opposed to cases where
you come out with a time profit only in the *very* long-run.

In particular, I usually work with models that are conceptually similar to
factor analysis (i.e., nothing on the "right-hand side is observed"). This
is relevant because the next place one might go if R is slow for these
problems is JAGS. Or maybe it's the first place you go. I'm not sure.
Anyway, JAGS (as of when I last looked into it) doesn't handle the things I
was doing efficiently. It used a less efficient sampler because it didn't
detect that conditional on every other parameter, I was updating something
that came from a Normal dist. So, with just a vanilla Gibbs step, I could
out perform JAGS' slice sampler (where efficiency = increase in Effective
Sample Size / time).

I settled on Rcpp for these problems before Stan was really out there, so I
haven't doubled-back to see how Stan would factor in to someone's
decision-making process. Taken together:

   1. If you are doing MCMC in R for a model that isn't packaged, you have
   to code it by hand
   2. Even if your R code is efficient, your runtime will be slow
   3. Outside options don't get you too much improvement (e.g. JAGS), but
   they get you some
   4. For some problems, that just isn't fast enough and Rcpp-based C++
   code can help you get you a lot more speedup with a reduced learning curve

Particularly nice about this class of problems is that it "straightforward"
on the implementation side. It focuses on computation (not advanced
features of C++ or the nuances of R objects), the algorithm is conceptually
simple, and you don't have to rely on boost or armadillo or anything beyond
basic C++. Lastly, with all the recent sugar, MCMC Rcpp code is veryR-like.

Also, while it's never a complaint of mine, there is often some conceptual
hurdle for folks looking at an example like simulating pi and seeing how it
applies to their work. At least with MCMC, it is a bit closer to a real
application. I'm not saying it's anyone else's job to jump that hurdle for
them, but if it can be removed for free, why not?

Apologies for long-windedness.

-Jonathan




-------------------------------------------------------------------------
J.P. Olmsted

029 Corwin (Office)
130 Corwin Hall (Mail)

Politics Department
Princeton University
Princeton, NJ 08544


t: 609.258.6202
f: 609.258.1110
jolmsted at princeton.edu
http://about.me/olmjo
-------------------------------------------------------------------------


On Thu, Aug 1, 2013 at 10:19 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> I'm giving a talk to the Chicago RUG that is limited to 30 mins, and I
> would
> like to include some nice examples (besides standards like Fibonacci and
> SimulatingPi).  The other talk is on ggplot(2), so the house may be full
> with
> new users / non-C++ hackers.
>
> What examples should I talk about?  Bonus points for links for list
> questions, StackOverflow questions, or Rcpp Gallery posts.
>
> Dirk
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130801/ff3d70b1/attachment.html>


More information about the Rcpp-devel mailing list