<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/twins-on-the-up/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.johnmackintosh.com/2018-12-13-meet-the-twins/"> HighlandR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Are multiple births on the increase?</h2>
<p>My twin boys turned 5 years old today. Wow, time flies. Life is never dull, because twins are still seen as something of a novelty, so wherever we go, we find ourselves in conversation with strangers, who are intrigued by the whole thing.</p>
<p>In order to save time if we ever meet, here’s some FAQ’s:</p>
<ul>
<li>No, they’re not identical</li>
<li>Yes, I’m sure</li>
<li>No, they do not have similar personalities</li>
<li>They like different things – One likes Hulk and Gekko, the other likes Iron Man and Catboy.</li>
</ul>
<p>Recently I’ve been hearing and seeing anecdotal evidence that twins and multiple births are on the increase. I tried to find some data for Scotland, and while there is a <a rel="nofollow" href="https://www.opendata.nhs.scot/dataset/births-in-scottish-hospitals" target="_blank">lot of information on births in Scotland available</a>, I couldn’t find breakdowns of multiple births.<br>
However, I did find some information for England and Wales, so let’s look at that.</p>
<p>In this next bit, they key thing that may be of interest is the use of tidyr::gather.<br>
There has been some discussion on #rstats Twitter about things people struggle with and a surprising amount of people struggle to remember the syntax for tidyr’s gather and spread.</p>
<p>(I can neither confirm or deny I am one of them).</p>
<p>The data was found <a rel="nofollow" href="https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/livebirths/datasets/birthcharacteristicsinenglandandwales" target="_blank">here</a></p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>readxl</span><span>)</span><span>
</span><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>tidyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>data</span><span> </span><span>&lt;-</span><span> </span><span>read_xls</span><span>(</span><span>&quot;birthcharacteristicsworkbook2016.xls&quot;</span><span>,</span><span> </span><span>sheet</span><span> </span><span>=</span><span> </span><span>&quot;Table 11&quot;</span><span>,</span><span>
</span><span>range</span><span> </span><span>=</span><span> </span><span>&quot;A10:I87&quot;</span><span>)</span><span>
</span><span>data</span><span> </span><span>&lt;-</span><span> </span><span>data</span><span> </span><span>%>%</span><span> </span><span>rename</span><span>(</span><span>Year</span><span> </span><span>=</span><span> </span><span>X__1</span><span>,</span><span>
</span><span>All_ages</span><span> </span><span>=</span><span> </span><span>`All maternities with multiple births`</span><span>,</span><span>
</span><span>Under20</span><span> </span><span>=</span><span> </span><span>X__2</span><span>,</span><span>
</span><span>`20_to_24`</span><span> </span><span>=</span><span> </span><span>X__3</span><span>,</span><span>
</span><span>`25_to_29`</span><span> </span><span>=</span><span> </span><span>X__4</span><span>,</span><span>
</span><span>`30_to_34`</span><span> </span><span>=</span><span> </span><span>X__5</span><span>,</span><span>
</span><span>`35_to_39`</span><span> </span><span>=</span><span> </span><span>X__6</span><span>,</span><span>
</span><span>`40_to_44`</span><span> </span><span>=</span><span> </span><span>X__7</span><span>,</span><span>
</span><span>`45_and_over`</span><span> </span><span>=</span><span> </span><span>X__8</span><span>)</span><span>
</span><span># the 1981 data is borked, so ignore that</span><span>
</span></code></pre>
</div>
</div>
<p>Note use of gather to combine all the age groups into an age_group variable.</p>
<p>We use the Year column as an index so we have an entry for every age group, for every year, with the value represented as ‘maternities’.</p>
<p>Back to the code:</p>
<div>
<div>
<pre><code><span>long_data</span><span> </span><span>&lt;-</span><span> </span><span>data</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>Year</span><span> </span><span>!=</span><span> </span><span>&quot;1981&quot;</span><span>)</span><span> </span><span>%>%</span><span> </span><span>gather</span><span>(</span><span>key</span><span> </span><span>=</span><span> </span><span>age_group</span><span>,</span><span> </span><span>value</span><span> </span><span>=</span><span> </span><span>&quot;maternities&quot;</span><span>,</span><span> </span><span>-</span><span>Year</span><span>)</span><span>
</span><span>long_data</span><span>$</span><span>Year</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>long_data</span><span>$</span><span>Year</span><span>)</span><span>
</span><span>long_data</span><span>$</span><span>age_group</span><span> </span><span>&lt;-</span><span> </span><span>forcats</span><span>::</span><span>as_factor</span><span>(</span><span>long_data</span><span>$</span><span>age_group</span><span>)</span><span>
</span><span>long_data</span><span>$</span><span>maternities</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>long_data</span><span>$</span><span>maternities</span><span>)</span><span>
</span><span>ggplot</span><span>(</span><span>long_data</span><span>,</span><span>aes</span><span>(</span><span>Year</span><span>,</span><span> </span><span>maternities</span><span>),</span><span> </span><span>group</span><span> </span><span>=</span><span> </span><span>age_group</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>()</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>vars</span><span>(</span><span>age_group</span><span>),</span><span> </span><span>scales</span><span> </span><span>=</span><span> </span><span>&quot;free_y&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>&quot;England and Wales maternities with multiple births - numbers&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;By age of mother, 1940 to 2016&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>NULL</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Multiple maternities&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="2018-12-13-counts-common.png" src="https://i1.wp.com/www.johnmackintosh.com/img/2018-12-13-counts-common.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p><img alt="2018-12-13-counts-free.png" src="https://i1.wp.com/www.johnmackintosh.com/img/2018-12-13-counts-free.png?w=456&ssl=1" data-recalc-dims="1"></p>
<div>
<div>
<pre><code><span># Let's do rates</span><span>
</span><span>rates</span><span> </span><span>&lt;-</span><span> </span><span>read_xls</span><span>(</span><span>&quot;birthcharacteristicsworkbook2016.xls&quot;</span><span>,</span><span> </span><span>sheet</span><span> </span><span>=</span><span> </span><span>&quot;Table 11&quot;</span><span>,</span><span>
</span><span>range</span><span> </span><span>=</span><span> </span><span>&quot;A89:I166&quot;</span><span>)</span><span>
</span><span>rates</span><span> </span><span>&lt;-</span><span> </span><span>rates</span><span> </span><span>%>%</span><span> </span><span>rename</span><span>(</span><span>Year</span><span> </span><span>=</span><span> </span><span>X__1</span><span>,</span><span>
</span><span>All_ages</span><span> </span><span>=</span><span> </span><span>`All maternities with multiple births per 1,000 all maternities`</span><span>,</span><span>
</span><span>Under20</span><span> </span><span>=</span><span> </span><span>X__2</span><span>,</span><span>
</span><span>`20_to_24`</span><span> </span><span>=</span><span> </span><span>X__3</span><span>,</span><span>
</span><span>`25_to_29`</span><span> </span><span>=</span><span> </span><span>X__4</span><span>,</span><span>
</span><span>`30_to_34`</span><span> </span><span>=</span><span> </span><span>X__5</span><span>,</span><span>
</span><span>`35_to_39`</span><span> </span><span>=</span><span> </span><span>X__6</span><span>,</span><span>
</span><span>`40_to_44`</span><span> </span><span>=</span><span> </span><span>X__7</span><span>,</span><span>
</span><span>`45_and_over`</span><span> </span><span>=</span><span> </span><span>X__8</span><span>)</span><span>
</span><span>long_rates</span><span> </span><span>&lt;-</span><span> </span><span>rates</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>Year</span><span> </span><span>!=</span><span> </span><span>1981</span><span>)</span><span> </span><span>%>%</span><span> </span><span>gather</span><span>(</span><span>key</span><span> </span><span>=</span><span> </span><span>age_group</span><span>,</span><span> </span><span>value</span><span> </span><span>=</span><span> </span><span>&quot;multiple_maternities_per_1000&quot;</span><span>,</span><span> </span><span>-</span><span>Year</span><span>)</span><span>
</span><span>long_rates</span><span>$</span><span>Year</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>long_rates</span><span>$</span><span>Year</span><span>)</span><span>
</span><span>long_rates</span><span>$</span><span>age_group</span><span> </span><span>&lt;-</span><span> </span><span>forcats</span><span>::</span><span>as_factor</span><span>(</span><span>long_rates</span><span>$</span><span>age_group</span><span>)</span><span>
</span><span>long_rates</span><span>$</span><span>multiple_maternities_per_1000</span><span> </span><span>&lt;-</span><span> </span><span>as.numeric</span><span>(</span><span>long_rates</span><span>$</span><span>multiple_maternities_per_1000</span><span>)</span><span>
</span><span>ggplot</span><span>(</span><span>long_rates</span><span>,</span><span>aes</span><span>(</span><span>Year</span><span>,</span><span> </span><span>multiple_maternities_per_1000</span><span>),</span><span> </span><span>group</span><span> </span><span>=</span><span> </span><span>age_group</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>()</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>vars</span><span>(</span><span>age_group</span><span>))</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>&quot;England and Wales Rate of maternities with multiple births - per 1,000 all maternities &quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;By age of mother, 1940 to 2016&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>NULL</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Multiple maternities&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>When we look at maternities with multiple births as a rate per 1000 maternities, we see the increase in multiple births among older mothers, especially in the over 45 group.<br>
<img alt="2018-12-13-rates-common.png" src="https://i1.wp.com/www.johnmackintosh.com/img/2018-12-13-rates-common.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Again, with free scales on the y axis – which helps us see almost all age groups are exhibiting an increase – compare the 20-24 age group as a rate and as count for example.</p>
<p><img alt="2018-12-13-rates-free.png" src="https://i0.wp.com/www.johnmackintosh.com/img/2018-12-13-rates-free.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Looks to me that overall, the rate of multiple births is increasing.<br>
What’s driving this?<br>
Can it continue?<br>
Will people ever stop asking us if the twins are identical?</p>
<p><img alt="arnie.jpg" src="https://i2.wp.com/www.johnmackintosh.com/img/arnie.jpg?w=456&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://www.johnmackintosh.com/2018-12-13-meet-the-twins/"> HighlandR</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/G9evmO78hRI" height="1"></a></div>