<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/climate-change-and-population-modeling-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rviews.rstudio.com/2017/10/09/population-modeling-in-r/"> R Views</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A recent paper in <a rel="nofollow" href="https://www.nature.com/nclimate/" target="_blank">nature climate change</a>: <a rel="nofollow" href="http://go.nature.com/2xiyNC0" target="_blank">Less than 2°C warming by 2100 unlikely</a> (Raftery et al. 2017), concludes that the goal of the <a rel="nofollow" href="https://ec.europa.eu/clima/policies/international/negotiations/paris_en" target="_blank">Paris Agreement</a> is unlikely to be met.</p>
<p>Although the conclusion is disheartening, the paper advances the science of climate modeling by developing a joint Bayesian hierarchical model for Gross Domestic Product per capita and carbon intensity. This ensemble of models, in turn, depends on the availability of probabilistic population projections developed by the <a rel="nofollow" href="https://bayespop.csss.washington.edu/software/" target="_blank">BayesPop</a> Project at the University of Washington and available on CRAN.</p>
<p>The linkage between CO<sub>2</sub> emissions and population modeling comes through the use of a version of the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Kaya_identity" target="_blank">Kaya identity</a>, which “expresses future emissions levels in a country as a product of three components: population, GDP per capita, and carbon intensity (CO<sub>2</sub> emissions per unit of GDP).”</p>
<p>The 3700 lines of R code that implement the models underlying the paper are available <a rel="nofollow" href="https://github.com/PPgp/Co2projections" target="_blank">here</a> on GitHub. Unless you work in this aspect of climate modeling, mastering this code seems likely to be a formidable task. A good first step, however, might be to work through the population models developed by BayesPop. These models comprise a series of R packages:</p>
<ul>
<li><a rel="nofollow" href="https://cran.r-project.org/package=bayesTFR" target="_blank"><code>bayesTFR</code></a> implements a Bayesian hierarchical model to make projections of total fertility for all of the countries in the world.
</li>
<li><a rel="nofollow" href="https://cran.r-project.org/package=bayesLife" target="_blank"><code>bayesLife</code></a> implements a Bayesian Hierarchical model to make life expectancy projections for all the countries in the world is described <a rel="nofollow" href="https://link.springer.com/article/10.1007%2Fs13524-012-0193-x" target="_blank">here</a>.
</li>
<li><a rel="nofollow" href="https://cran.r-project.org/package=bayesPop" target="_blank"><code>bayesPop</code></a> uses <code>bayesTFR</code> and <code>bayesLife</code> to generate population projections for all of the world’s countries.
</li>
<li><a rel="nofollow" href="https://cran.r-project.org/package=bayesDem" target="_blank"><code>bayesDem</code></a> provides graphical user interface for <code>bayesTFR</code>, <code>bayesLife</code> and <code>bayesPop</code>.
</li>
<li><a rel="nofollow" href="https://cran.r-project.org/package=wppExplorer" target="_blank"><code>wppExployer</code></a> implements a <code>shiny</code> app for exploring the data in on the <a rel="nofollow" href="https://esa.un.org/unpd/wpp/" target="_blank">World Population Prospects</a> This data is available in R packages <a rel="nofollow" href="https://cran.r-project.org/package=wpp2017" target="_blank">wpp2017</a>, <a rel="nofollow" href="https://cran.r-project.org/package=wpp2015" target="_blank">wpp2015</a>, <a rel="nofollow" href="https://cran.r-project.org/package=wpp2012" target="_blank">wpp2012</a>, and <a rel="nofollow" href="https://cran.r-project.org/package=wpp2010" target="_blank">wpp2010</a>,</li>
</ul>
<p>The <code>wppExployer</code> <code>shiny</code> app is also available <a rel="nofollow" href="https://rstudio.stat.washington.edu/shiny/wppExplorer/inst/explore/" target="_blank">online</a>. <br> <iframe width="100%" src="https://rstudio.stat.Washington.edu/shiny/wppExplorer/inst/explore/" height="450"></iframe> </p>
<p>To give you a feel for how these models work, we use the <code>bayesTFR</code> package to estimate and plot fertility rates for the United States. (Note that, for brevity, the informative console output of the simulations in the code below have been suppressed.)</p>
<pre><code>library(bayesTFR)
# This command produces output data, such as in the directory ex-data
sim.dir &lt;- tempfile()
# Phase II MCMCs
m &lt;- run.tfr.mcmc(nr.chains=1, iter=60, output.dir=sim.dir, seed=1, verbose=TRUE)</code></pre>
<pre><code>## Loading required package: wpp2017</code></pre>
<pre><code>## Warning: package 'wpp2017' was built under R version 3.4.2</code></pre>
<pre><code># Phase III MCMCs (not included in the package)
m3 &lt;- run.tfr3.mcmc(sim.dir=sim.dir, nr.chains=2, iter=100, thin=1, seed=1, verbose=TRUE)
# Prediction
pred &lt;- tfr.predict(m, burnin=30, burnin3=50, verbose=TRUE)
summary(pred, country='United States of America')
unlink(sim.dir, recursive=TRUE)</code></pre>
<pre><code>tfr.trajectories.plot(pred,country=&quot;United States of America&quot;)</code></pre>
<p><img src="https://i0.wp.com/rviews.rstudio.com/post/2017-10-04-population-modeling-in-r_files/figure-html/unnamed-chunk-3-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p></p>
<p>The transparent, reproducible work being done by Raftery and his collaborators, and the other members of the BayesPop Project, is a great gift to the R community. Anyone with an appetite for R code and the patience to learn something of Bayesian hierarchical models can gain some insight into one of the most important scientific problems of our day.</p>
<p> </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://rviews.rstudio.com/2017/10/09/population-modeling-in-r/"> R Views</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/vKlPVp98LIM" height="1"></a></div>