<h2>Abstract</h2>
<p>Data on the names of all newborn babies in Berlin 2016 are used to illustrate how a scientific treatment of chance could enhance rank statements in, e.g., <strong>onomastics</strong> investigations. For this purpose, we first identify different stages of the naming-your-baby process, which are influenced by chance. Second, we compute confidence intervals for the ranks based on a bootstrap procedure reflecting the above chance elements. This leads to an alternative league table based on what we will call <strong>uncertainty corrected ranks</strong>. From an R perspective we use the problem as a practice session for wrangling data <code>dplyr</code>-style (code available by clicking on the github logo in the license below).</p>
<p><br><a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"></a> This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>. The markdown+Rknitr source code of this blog is available under a <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU General Public License (GPL v3)</a> license from <a href="https://github.com/hoehleatsu/hoehleatsu.github.io"></a>.</p>
<h2>Introduction</h2>
<p>What's the most popular first name given to newborn boys and girls? This question seems to fascinate at different levels of temporal and spatial aggregation, because the choice of names and its dynamics reflects cultural and social behavior. The branch of science related to the study of names is entitled <a href="https://en.wikipedia.org/wiki/Onomastics"><strong>onomastics</strong></a>. Mathematical modelling is used in onomastics to study name dynamics by evolutionary models and models for contagious phenomena <span>(Hahn and Bentley 2003, <span>Kessler et al. (2012)</span>)</span>. But even the task of naming your baby has almost onomastics optimizing flavour requiring <a href="http://waitbutwhy.com/2013/12/how-to-name-baby.html">data science skills</a>. However, once the Official Social Security Administration has released the numbers for all names of newborns in a given year, finding the most popular baby name appears a simple counting and ranking job: for example the <a href="http://www.babynamewizard.com/the-top-1000-baby-names-of-2015-united-states-of-america">most popular US baby name in 2015 were Emma (girls) and Noah (boys)</a>.</p>
<br>
<p>
</p><p>
</p><p><strong>Statistics</strong> is the scientific study of chance. One fundamental concept is the inference of a <strong>population</strong> quantity from observing the quantity in a <strong>sample</strong> (=subset) of this population. To make this specific for the baby names: In Germany there is no official first name statistics, as a consequence, the site <a href="http://www.beliebte-vornamen.de/">www.beliebte-vornamen.de</a> uses information from a sample of 196,158 kids (corresponding to 26% of all newborns in Germany 2016) originating from a selection of registrar's offices and birth clinics to determine the most popular first name in Germany 2016. However, the aspect of uncertainty in the resulting ranking due to only having a sample is ignored. The aspect of uncertainty can also be more subtle. As an example, the city of Berlin recently released the official <a href="https://daten.berlin.de/datensaetze/liste-der-h%C3%A4ufigen-vornamen-2014">2016 first name statistic</a> of <strong>all newborns</strong> in the city. The data are available at <a href="https://en.wikipedia.org/wiki/Boroughs_and_neighborhoods_of_Berlin">district level</a>, which is helpful since there are notable socio-economic and cultural differences between the districts. One could argue that since the data cover the <strong>entire population of interest</strong> (i.e. newborns in Berlin 2016) the use of <strong>inferential statistics</strong> is superfluous. But is it that simple?</p>
<p>In what follows we use the Berlin newborn names to illustrate how a scientific treatment of <strong>chance</strong> could enhance rank statements in general and in name rank tables in particular.</p>
<h2>Descriptive Data Analysis</h2>
<p>Altogether, the <code>distrNames</code> variable contains the information about the frequency of 13245 unique first names. Below is shown the first 10 lines of the data.</p>
<p></p>
<p>By summing the <code>count</code> column it becomes clear that in total, 69525 names were registered in Berlin 2016 (35620 boys and 33905) girls. The proportion of boy names is 51.2%. One caveat with the Berlin statistic is the fact that, if a child is given several first names, each name is counted once in the statistic. Hence, the above total sum is actually higher than the number of kids born 2016 (roughly 38,030 in 2015, official 2016 number not available yet). Despite of the potential problems with multiple names per kids, the empirical boy fraction in the data is close to reported ratios of the number of born boys vs. girls of 1.05 <span>(Jacobsen, Møller, and Mouritsen 1999)</span>, which means that the expected fraction of boys among the newborns should be approximately 51.2%.</p>
<p>Strangely enough, 15 babies seem to have an empty first name (but the sex is known). We decided to keep these <code>NA</code> names in the analysis, because at the time of writing it was unclear, if this is a data recording problem (e.g. a delay of the December 2016 kids) or actually allowed. An email inquiry with the data providing agency about the origin of these <code>NA</code>'s currently remains unanswered (since 4 days).</p>
<p>We can now look at the top-5-names in Berlin for each gender:</p>
<div><pre><code>##Aggregate data over district and sort according to rank within gender
newborn &lt;-<span> </span>distrNames %>%<span> </span><span>group_by</span>(firstname, sex) %>%
<span> </span><span>summarise</span>(<span>count=</span><span>sum</span>(count)) %>%
<span> </span><span>arrange</span>(<span>desc</span>(count)) %>%<span> </span><span>group_by</span>(sex) %>%
<span> </span><span>mutate</span>(<span>rank=</span><span>rank</span>(-count,<span>ties=</span><span>&quot;min&quot;</span>))</code></pre></div>
<pre><code>## Source: local data frame [10 x 4]
## Groups: sex [2]
## 
##     firstname    sex count  rank
##         &lt;chr> &lt;fctr> &lt;int> &lt;int>
## 1       Marie      f   695     1
## 2      Sophie      f   649     2
## 3   Charlotte      f   495     3
## 4       Maria      f   403     4
## 5      Emilia      f   382     5
## 6   Alexander      m   467     1
## 7        Paul      m   383     2
## 8       Elias      m   371     3
## 9  Maximilian      m   344     4
## 10       Emil      m   295     5</code></pre>
<p>The top-1 names per gender and district from <code>distrNames</code> can easily be computed in similar fashion using <code>group_by</code> and <code>summarise</code> operations. To spice up the visualization we use a custom made <strong>wordmapcloud</strong>, which overlays the top-1 names over an alpha-channeled wordcloud of the district's name with font size proportional to frequency. We see little geographical variation in the top-1 names over the districts - particularly for the girls.</p>
<p></p>
<p>The <a href="https://en.wikipedia.org/wiki/Gini_coefficient">Gini index</a> for the name frequency is calculated using the <code>ineq</code> package and is 0.728 and 0.743 for girls and boys, respectively. This means that the occurrence of names in boys is dominated by fewer names for boys than for girls. Furthermore, both gender's name distribution tend to be dominated by few names. This feature can also be visualized by a Lorenz curve - here shown separately for each sex:</p>
<p></p>
<p>From the curve one can for example deduce that the frequency of the top-50 girl names (top 0.7% out of the 6957 girl names), cover 29.0% of all 33905 girl namings.</p>
<h2>Analysing Stochasticity in the Name Selection</h2>
<p>At which places is stochasticity a useful concept for abstracting unobservable factors influencing the name selection and, hence, the data analysed above? We shall focus on 5 stages:</p>
<ol type="1"><li><p>the number of babies born in Berlin in 2016</p></li>
<li><p>the gender of a given born baby; as mentioned above the odds for the kid being a boy is roughly 1.05:1.</p></li>
<li><p>the number of names given to a baby of a specific sex</p></li>
<li><p>the selection of the name(s) given that the gender of the baby is known</p></li>
<li><p>reporting problems leading to the wrong name(s) being recorded</p></li>
</ol><p>We will ignore uncertainty from stages 1, 3 and 5 and, hence, only focus on uncertainty arising from stages 2 and 4. One may ask in stage 4, if the naming is not deterministic, once the parents know the sex of their baby? In this post we take the position that even given sex the naming is the outcome of a stochastic process. The selection probabilities are likely to vary from couple to couple based on complex interactions between, e.g., social status, existing names in the family as well as past exposure and associations with names. Since data are never going to be available on these individual factors, we will, as a proxy, assume that the drawing probabilities are district specific. As a result, the selected name can be considered as one realization of the multinomial distribution with the underlying true popularity of all possible names in the district acting as selection probabilities.</p>
<h3>Uncertainty Assessment using the Bootstrap</h3>
<p>When combining the above stages 3 and 4, the name selection process can be mimicked by a <strong>simple bootstrap</strong> procedure <strong>stratified by district</strong> <span>(Davison and Hinkley 1997)</span>. In spirit, this approach corresponds to the bootstrap approach to ranks used in Sect. 5.3 of <span>Goldstein and Spiegelhalter (1996)</span>. We operationalise this in R using the <code>boot</code> package, the work-horse will be the function <code>name_ranks</code> shown below.</p>
<div><pre><code>######################################################################
## Compute rank of name within female and male population,
## respectively for a draw of all kids (one kid per row) with
## replacement.
##
## Parameters:
##  x - the full data, one row per kid
##  idx - vector of length nrow(x) containing a possible permutation
##        (with replacement)
##  returns - which column to return, rank or count?
##
## Returns:
##  sex stratified ranks (ordered according to (firstname, sex))
######################################################################

name_ranks &lt;-<span> </span>function(x,  <span>idx=</span><span>seq_len</span>(<span>nrow</span>(x)), <span>returns=</span><span>c</span>(<span>&quot;rank&quot;</span>,<span>&quot;count&quot;</span>)) {
  ##Make resampled data and append all_strata to ensure each firstname-sex combination occurs
  x_boot &lt;-<span> </span>x %>%<span> </span><span>slice</span>(idx) %>%<span> </span><span>bind_rows</span>(all_strata)

  ##Summarise the number of occurences for each firstname-sex strata and compute the ranks.
  aggrx_wranks &lt;-<span> </span>x_boot %>%<span> </span><span>group_by</span>(firstname,sex) %>%
<span> </span><span>summarise</span>(<span>count =</span> <span>sum</span>(count)) %>%
<span> </span><span>group_by</span>(sex) %>%
<span> </span><span>mutate</span>(<span>rank=</span><span>rank</span>(-count, <span>ties.method=</span><span>&quot;min&quot;</span>)) %>%
<span> </span><span>arrange</span>(firstname, sex) <span>#important to ensure order.</span>

  <span>return</span>(aggrx_wranks %>%<span> </span><span>select_</span>(returns) %>%<span> </span>.[[<span>2</span>]])
}</code></pre></div>
<p>In the above, <code>all_strata</code> is a <code>data.frame</code> containing all possible strata of gender and firstname. This is done in order to ensure that we later get a zero count for names, even if they do not appear in the bootstrap re-sample.</p>
<p>We then convert the aggregated data to long format where each kid is represented by one row. This is the most didactic way to explain what is going on in the bootstrap, but an aggregated multinomial approach would probably be much faster in terms of execution time.</p>
<div><pre><code>kids &lt;-<span> </span>distrNames %>%<span> </span><span>slice</span>(<span>rep</span>(<span>seq_len</span>(<span>nrow</span>(distrNames)), <span>times=</span>distrNames %$%<span> </span>count)) %>%<span> </span><span>mutate</span>(<span>count=</span><span>1</span>)</code></pre></div>
<p>Ready to perform the bootstrap stratified within districts? Yes, its conveniently done using the <code>boot</code> package (which is easily paralleled too).</p>
<div><pre><code><span>set.seed</span>(<span>123</span>) ##fix seed for reproducibility
b &lt;-<span> </span>boot::<span>boot</span>(kids, <span>statistic=</span>name_ranks, <span>R=</span><span>999</span>, <span>strata=</span>kids$district, <span>parallel=</span><span>&quot;multicore&quot;</span>,<span>ncpus=</span><span>3</span>)</code></pre></div>
<p>We use the percentile method on the 999 + 1 bootstrap rank-vectors as a method for computing a 95% confidence interval for the rank of each name for boys and girls, respectively.</p>
<pre><code>## Source: local data frame [10 x 5]
## Groups: sex [2]
## 
##     firstname    sex  rank rankci.5. rankci.95.
##         &lt;chr> &lt;fctr> &lt;int>     &lt;int>      &lt;int>
## 1   Alexander      m     1         1          1
## 2       Marie      f     1         1          2
## 3        Paul      m     2         2          4
## 4      Sophie      f     2         1          2
## 5   Charlotte      f     3         3          3
## 6       Elias      m     3         2          4
## 7       Maria      f     4         4          5
## 8  Maximilian      m     4         3          4
## 9        Emil      m     5         5          9
## 10     Emilia      f     5         4          5</code></pre>
<p>Using the lower limit of the 95% CI to group the names, we define the concept of a <strong>uncertainty corrected</strong> rank (ucrank). This is just the lowest rank which we, given the modelled stochasticity, cannot be ruled out (at the 2.5% lvl. of significance). Listing the top-5 of these corrected ranks leads to the following tables for girls and boys, respectively:</p>
<table border="5,"><tr>
ucrank (among girls)
first names (girls)
ucrank (among boys)
first names (boys)
</tr><tr><td align="center">
1
</td>
<td align="center">
Marie, Sophie
</td>
<td align="center">
1
</td>
<td>
Alexander
</td>
</tr><tr><td align="center">
3
</td>
<td align="center">
Charlotte
</td>
<td align="center">
2
</td>
<td>
Elias, Paul
</td>
</tr><tr><td align="center">
4
</td>
<td align="center">
Emilia, Maria
</td>
<td align="center">
3
</td>
<td>
Maximilian
</td>
</tr><tr><td align="center">
6
</td>
<td align="center">
Anna, Emma, Mia, Sophia
</td>
<td align="center">
5
</td>
<td>
Anton, Emil, Felix, Noah
</td>
</tr><tr><td align="center">
8
</td>
<td align="center">
Johanna
</td>
<td align="center">
6
</td>
<td>
Jonas, Oskar
</td>
</tr></table>
<p>
</p><p>Instead of using the uncertainty corrected ranks, we could instead have visualized the 95% rank confidence intervals instead (dots denote the observed ranks):</p>
<p></p>
<h2>Discussion</h2>
<p>In this post we have used the bootstrap method as a way to assess uncertainty in ranks. This approach is very general and can be extended to areas beyond onomastics. No matter the area of application the approach requires a careful identification of the elements of chance you want to take into account. In the particular application we decided to ignore specific uncertainty aspects (e.g. number of babies born) to not impose further hard-to-verify assumptions. However, as soon as there is uncertainty, ranks are known to be subject to large variation. Hence, a different reporting or visualization of the ranks than the point estimator from the sample is necessary. The use of uncertainty corrected ranks is not revolutionary, but it underlines the importance of uncertainty in the construction of league tables. A more uncertainty enhancing presentation of ranks in, e.g., data journalism, is therefore needed.</p>
<p>
</p>
<h2>References</h2>
<div>
<div>
<p>Davison, A. C., and D. V. Hinkley. 1997. Bootstrap Methods and Their Applications. Cambridge University Press.</p>
</div>
<div>
<p>Goldstein, Harvey, and David J. Spiegelhalter. 1996. “League Tables and Their Limitations: Statistical Issues in Comparisons of Institutional Performance.” Journal of the Royal Statistical Society. Series A (Statistics in Society) 159 (3). [Wiley, Royal Statistical Society]: 385–443. <a href="http://www.jstor.org/stable/2983325">http://www.jstor.org/stable/2983325</a>.</p>
</div>
<div>
<p>Hahn, Matthew W, and Alexander R Bentley. 2003. “Drift as a Mechanism for Cultural Change: An Example from Baby Names.” Proceedings of the Royal Society B: Biological Sciences 270 (Suppl 1): S120–S123. doi:<a href="https://doi.org/10.1098/rsbl.2003.0045">10.1098/rsbl.2003.0045</a>.</p>
</div>
<div>
<p>Jacobsen, R., H. Møller, and A. Mouritsen. 1999. “Natural Variation in the Human Sex Ratio.” Human Reproduction 14 (12): 3120. doi:<a href="https://doi.org/10.1093/humrep/14.12.3120">10.1093/humrep/14.12.3120</a>.</p>
</div>
<div>
<p>Kessler, David A, Yosi E Maruvka, Jøergen Ouren, and Nadav M Shnerb. 2012. “You Name It –How Memory and Delay Govern First Name Dynamics.” Edited by Eshel Ben-Jacob. PLoS ONE 7 (6). San Francisco, USA: Public Library of Science: e38790. doi:<a href="https://doi.org/10.1371/journal.pone.0038790">10.1371/journal.pone.0038790</a>.</p>
</div></div>