<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1153258758;
        mso-list-template-ids:858707796;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">After reviewing Jonathan’s suggestion and Dirk’s blog post on MCMC, I do agree with him. As Dirk points out, the Rcpp code is almost identical to the R code,
 making it an easier segue from R to C++ given the target audience.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D">Dale Smith, Ph.D.<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D">Senior Financial Quantitative Analyst<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D">Risk & Compliance<o:p></o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D">Fiserv<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D">Office: 678-375-5315<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><a href="http://www.fiserv.com/">www.fiserv.com</a></span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> rcpp-devel-bounces@r-forge.wu-wien.ac.at [mailto:rcpp-devel-bounces@r-forge.wu-wien.ac.at]
<b>On Behalf Of </b>Jonathan Olmsted<br>
<b>Sent:</b> Thursday, August 01, 2013 11:56 AM<br>
<b>To:</b> Dirk Eddelbuettel<br>
<b>Cc:</b> rcpp-devel<br>
<b>Subject:</b> Re: [Rcpp-devel] Favourite Rcpp examples for newbies ?<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">I think I've seen this somewhere out there on the webs... <br>
<br>
<a href="http://dirk.eddelbuettel.com/blog/2011/07/14/">http://dirk.eddelbuettel.com/blog/2011/07/14/</a><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">-------------------------------------------------------------------------<br>
J.P. Olmsted</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">029 Corwin (Office)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">130 Corwin Hall (Mail)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Politics Department</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Princeton University</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Princeton, NJ 08544</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">t: 609.258.6202</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">f: 609.258.1110<br>
<a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a></span><o:p></o:p></p>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666"><a href="http://about.me/olmjo" target="_blank">http://about.me/olmjo</a><br>
-------------------------------------------------------------------------</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Aug 1, 2013 at 11:31 AM, Jonathan Olmsted <<a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">Just my quick thoughts:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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:<o:p></o:p></p>
</div>
<div>
<div>
<ol start="1" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
If you are doing MCMC in R for a model that isn't packaged, you have to code it by hand<o:p></o:p></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
Even if your R code is efficient, your runtime will be slow<o:p></o:p></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
Outside options don't get you too much improvement (e.g. JAGS), but they get you some<o:p></o:p></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
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<o:p></o:p></li></ol>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">Apologies for long-windedness.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-Jonathan<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">-------------------------------------------------------------------------<br>
J.P. Olmsted</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">029 Corwin (Office)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">130 Corwin Hall (Mail)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Politics Department</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Princeton University</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">Princeton, NJ 08544</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">t: 609.258.6202</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666">f: 609.258.1110<br>
<a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a></span><o:p></o:p></p>
<div>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:#666666"><a href="http://about.me/olmjo" target="_blank">http://about.me/olmjo</a><br>
-------------------------------------------------------------------------</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Aug 1, 2013 at 10:19 AM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal"><br>
I'm giving a talk to the Chicago RUG that is limited to 30 mins, and I would<br>
like to include some nice examples (besides standards like Fibonacci and<br>
SimulatingPi).  The other talk is on ggplot(2), so the house may be full with<br>
new users / non-C++ hackers.<br>
<br>
What examples should I talk about?  Bonus points for links for list<br>
questions, StackOverflow questions, or Rcpp Gallery posts.<br>
<span style="color:#888888"><br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> |
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>