<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/count-models-in-jags/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://aghaynes.wordpress.com/2017/05/17/count-models-in-jags/"> R – Insights of a PhD student</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Looks like I’ll be diving into some Bayesian analyses using JAGS. This post is primarily intended as a collection of links to [potentially] useful information, but also includes a few initial thoughts (I might update it occasionally with new links).</p>
<p>In terms of R packages, a very brief play suggests that R2jags is more user friendly than rjags (seems to be easier to get hold of the output and chains etc). Both packages seem to be missing good vignettes. The latter misses good examples too (although there are quite a few examples for both on the internet).</p>
<p>A tip from Zuur &amp; Ieno 2016: use a model matrix and assign priors based on the number of columns of the model matrix. Saves having to change the model description when adding/removing variables (how to include different priors for different betas though…?). E.g. (modified from Zuur &amp; Ieno 2016)</p>
<pre>X &lt;- model.matrix(~x1+x2+x3)
k &lt;- ncol(X)
mod &lt;- &quot;
model {
 # priors
 for (i in 1:k) { 
      b[i] &lt;- dnorm(0, 0.1) }
 # likelihood
 for (i in 1:N) {
      Y[i] ~ dpois(mu[i])      
      log(mu[i]) &lt;- inprod(b[], X[i,])
 } 
...
&quot;</pre>
<h3></h3>
<h3>General links:</h3>
<p><a target="_blank" rel="nofollow" href="http://www.jkarreth.net/files/bayes-cph_Tutorial-JAGS.pdf">Guide to JAGS through R</a>, goes into quite a bit of detail on installing, diagnostics, even running JAGS from the terminal (as well as 2 or 3 three of the R packages for interfacing with JAGS).</p>
<p><a target="_blank" rel="nofollow" href="http://lalashan.mcmaster.ca/theobio/bio_708/index.php/Bayesian_regression_example">Bayesian regression example</a> (wiki style).</p>
<p><a target="_blank" rel="nofollow" href="http://users.aims.ac.za/~mackay/BUGS/Manuals/Tricks.html">Advanced BUGS topics</a> (includes the “zero-trick” to fit any distribution in JAGS)</p>
<p><a target="_blank" rel="nofollow" href="https://stackoverflow.com/questions/tagged/r2jags">Newest R2JAGS questions </a>on StackOverflow</p>
<p> </p>
<h3>Count models:</h3>
<p><a target="_blank" rel="nofollow" href="https://blog.aidanfindlater.com/2016/09/12/poisson-and-negbin-in-jags/">A post with a couple of examples for JAGS count models</a> (including offsets)</p>
<p>A post with a question regarding<a target="_blank" rel="nofollow" href="http://doingbayesiandataanalysis.blogspot.ch/2012/03/negative-binomial-for-count-data.html"> autocorrelation of parameters in negative binomial models</a> and the answer on <a target="_blank" rel="nofollow" href="http://doingbayesiandataanalysis.blogspot.ch/2012/04/negative-binomial-reparameterization.html">how to get around it</a>.</p>
<p>A <a target="_blank" rel="nofollow" href="https://groups.nceas.ucsb.edu/non-linear-modeling/projects/owls/WRITEUP/owls.pdf">report using some data on owl feeding</a> behaviour using 3 or 4 methods for ZIP/ZINBs. (This is not JAGS stuff, but interesting for ZIPs/ZINBs)</p>
<p> </p>
<h3>Books:</h3>
<p>A <a target="_blank" rel="nofollow" href="https://sites.google.com/a/statistica.it/gianluca/bookhe">book website</a> with lots of code (Bayesian methods in health economics by Gianluca Baio). But see <a target="_blank" rel="nofollow" href="https://www.r-bloggers.com/r2jags-bcea-the-examples-from-bmhe/">this R-bloggers post</a> which mentions that an update broke some of the code, and details how to fix it. No idea if the book is any good, but the code should/could be useful</p>
<p>As with their other books*, <a target="_blank" rel="nofollow" href="http://www.highstat.com/BGZIM.htm">HighStat’s “beginners guide” to ZIP models</a> is very well written and easy to follow. Because mixed effects zero inflated methods are not implemented in standard software, Zuur and Ieno use JAGS quite a lot. Chapter 12 gives two methods (and code) for assessing overdispersion.</p>
<p>Zuur &amp; Ieno (2016) A beginners guide to zero inflated models using R.</p>
<p> </p>
<p>*well, the only other one I’ve read (the fantastic “penguin book” – Mixed Effects Models and Extensions in Ecology with R)</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aghaynes.wordpress.com/235/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/aghaynes.wordpress.com/235/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" 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://aghaynes.wordpress.com/2017/05/17/count-models-in-jags/"> R – Insights of a PhD student</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/brP-Yk90T4A"></a></div>