<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/rng-impact-on-mcmc-or-lack-thereof/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2017/07/13/33889/"> R – Xi'an's Og</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong><a rel="nofollow" href="https://xianblog.files.wordpress.com/2017/07/rngs.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2017/07/rngs.jpg?w=328&amp;h=328&amp;fit=328%2C328&amp;resize=328%2C328" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2017/07/rngs.jpg?w=328&amp;h=328&amp;fit=328%2C328&amp;resize=328%2C328?w=300" data-attachment-id="33890" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2017/07/rngs.jpg?w=328&h=328&fit=328%2C328&resize=328%2C328" data-permalink="https://xianblog.wordpress.com/2017/07/13/33889/rngs/" data-large-file="https://xianblog.files.wordpress.com/2017/07/rngs.jpg?w=328&amp;h=328&amp;fit=328%2C328&amp;resize=328%2C328?w=450" alt="" data-image-title="RNGs" sizes="(max-width: 328px) 100vw, 328px" data-comments-opened="1" class="wp-image-33890" data-recalc-dims="1"></a>F</strong>ollowing the talk at MCM 2017 about the strange impact of the random generator on the outcome of an MCMC generator, I tried in <a rel="nofollow" href="https://xianblog.wordpress.com/2017/07/04/montreal-street-art-jatp/" target="_blank">Montréal</a> airport the following code on the banana target of Haario et al. (1999), copied from <a rel="nofollow" href="https://cran.r-project.org/web/packages/FME/vignettes/FMEmcmc.pdf" target="_blank">Soetaert and Laine</a> and using the MCMC function of the <a rel="nofollow" href="https://cran.r-project.org/package=FME" target="_blank">FME package</a>:</p>
<pre>library(FME)
Banana &lt;- function (x1, x2) {
 return(x2 - (x1^2+1)) }
pmultinorm &lt;- function(vec, mean, Cov) {
 diff &lt;- vec - mean
 ex &lt;- -0.5*t(diff) %*% solve(Cov) %*% diff
 rdet &lt;- sqrt(det(Cov))
 power &lt;- -length(diff)*0.5
 return((2.*pi)^power / rdet * exp(ex)) }
BananaSS &lt;- function (p) {
 P &lt;- c(p[1], Banana(p[1], p[2]))
 Cov &lt;- matrix(nr = 2, data = c(1, 0.9, 0.9, 1))
N=1e3
ejd=matrix(0,4,N)
RNGkind(&quot;Mars&quot;)
for (t in 1:N){
  MCMC &lt;- modMCMC(f = BananaSS, p = c(0, 0.7), 
  jump = diag(nrow = 2, x = 5), niter = 1e3)
  ejd[1,t]=mean((MCMC$pars[-1,2]-MCMC$pars[1,2])^2)}
</pre>
<p>since this divergence from the initial condition seemed to reflect the experiment of the speaker at MCM 2017. Unsurprisingly, no difference came from using the different RNGs in R (which may fail to contain those incriminated by the study)…</p>
<p>Filed under: <a rel="nofollow" href="https://xianblog.wordpress.com/category/books/" target="_blank">Books</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/statistics/r-statistics/" target="_blank">R</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/statistics/" target="_blank">Statistics</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/travel/" target="_blank">Travel</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/category/university-life/" target="_blank">University life</a> Tagged: <a rel="nofollow" href="https://xianblog.wordpress.com/tag/donald-knuth/" target="_blank">Donald Knuth</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/george-marsaglia/" target="_blank">George Marsaglia</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/gnu-c-library/" target="_blank">GNU C library</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/mcm-2017/" target="_blank">MCM 2017</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/montreal/" target="_blank">Montréal</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/r/" target="_blank">R</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/random-number-generator/" target="_blank">random number generator</a>, <a rel="nofollow" href="https://xianblog.wordpress.com/tag/super-duper/" target="_blank">Super-duper</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xianblog.wordpress.com/33889/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/xianblog.wordpress.com/33889/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://xianblog.wordpress.com/2017/07/13/33889/"> R – Xi'an's Og</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/7s6gMguLmgE" height="1"></a></div>