Diego Valle-Jones's Bloghttps://blog.diegovalle.net/2022-11-14T00:00:00+01:00Shapefiles from the 2020 INEGI Census2022-11-14T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2022-11-14:2022/11/inegi-mexico-2020-census-shapefiles.html<p><a href="/images/posts/inegi-census-shapefiles/mexico.jpg">
<img alt="Streets of Mexico City" class="image-process-article-image" src="/images/posts/inegi-census-shapefiles/derivatives/article-image/mexico.jpg"/>
</a></p>
<p>You can now download shapefiles of selected geographic areas from the
latest <span class="caps">INEGI</span> <a href="https://gaia.inegi.org.mx/scince2020/"><span class="caps">SCINCE</span></a>
database. In addition to geospatial information on state and
municipios, the files include <a href="https://www.inegi.org.mx/app/scitel/Default?ev=10"><span class="caps">AGEB</span> and
manzana</a>
boundaries. The files are available in shapefile format and include
demographic data</p>
<p>If you don’t know how to run the script or prefer to simply download
the data, you can subscribe to my newsletter (one email per post) and
you’ll get the shapefile download links directly in your inbox as a bonus.</p>
<p><br/>
</p><div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden;
text-align: left;">
<div class="form-top-left" style="float: left;
width: 75%;
padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;">Subscribe to my <span class="free" style="color: #C7B720;">free</span> newsletter</h3>
<br/>
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers to my newsletter from Harvard, Stanford, Google, McKinsey, and many more, you’ll receive as a welcome gift the 100+ shapefiles described in this post (It’s more than <span class="caps"><span class="caps">7GB</span></span> of data and totally free)</b></p>
<p></p><ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Shapefiles of Manzanas, AGEBs, Municipios, Estados, and more
</li>
<li>
The latest shapefiles from the 2020 Census
</li>
<li>Includes historical shapefiles from 2010 census</li>
<li><a href="https://www.diegovalle.net/privacy/">Privacy policy</a></li>
<li>Unsubscribe at any time</li>
<p></p></ul><p></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left;
width: 25%;
padding-top: 5px;
font-size: 66px;
color: #fff;
line-height: 100px;
text-align: right;
opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form action="https://www.diegovalle.net/api/newsletter" class="registration-form" id="Newsletter" method="post" novalidate="novalidate" role="form">
<!-- <div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="form-first-name">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name">
</div> -->
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100;
font-size: 90%;">Where should I send the newsletter and shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Email</label>
<input aria-required="true" class="form-email form-control" id="email" name="email" placeholder="Email..." required="" type="email"/>
</div>
<div style="position: absolute; left: -5000px;"><input name="website" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" tabindex="-1" type="text" value="fatcatseat2much"/>
<input name="referrer" tabindex="-1" type="text" value="2015shapefiles"/>
</div>
<input class="hiddenRecaptcha_post required" id="hiddenRecaptcha_post" name="hiddenRecaptcha_post" type="hidden"/>
<div class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd" id="recaptcha_post"></div><br/>
<button class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" type="submit">Get your free newsletter</button>
</form>
</div>
</div>
<br/>
<p>If you use linux you can use the following script or if you’re unable to run the script you can always use the <a href="https://github.com/diegovalle/docker_scince_2020">docker</a> <a href="https://hub.docker.com/r/diegovalle/scince_2020">image</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>docker run -v <span class="s2">"</span><span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span><span class="s2">/scince_2020"</span>:/scince_2020 diegovalle/scince_2020
</pre></div>
</td></tr></table>
<p><br/>
<style>
/<em> https://github.com/lonekorean/gist-syntax-themes </em>/
@import url('https://cdn.rawgit.com/lonekorean/gist-syntax-themes/d49b91b3/stylesheets/idle-fingers.css');</p>
<p>@import url('https://fonts.googleapis.com/css?family=Open+Sans');
body {
font: 16px 'Open Sans', sans-serif;
}
body .gist .gist-file {
border-color: #555 #555 #444
}
body .gist .gist-data {
border-color: #555
}
body .gist .gist-meta {
color: #ffffff;
background: #373737;
}
body .gist .gist-meta a {
color: #ffffff
}
body .gist .gist-data .pl-s .pl-s1 {
color: #a5c261
}
</style></p>
<script src="https://gist.github.com/diegovalle/af936552e0998174313154a2ea9e92a9.js"></script>
<p><a href="/images/posts/inegi-census-shapefiles/cdmx.jpg">
<img alt="Streets of Mexico City" class="image-process-article-image" src="/images/posts/inegi-census-shapefiles/derivatives/article-image/cdmx.jpg"/>
</a></p>The most polluted cities in Mexico2018-05-27T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2018-05-27:2018/05/most-polluted-cities-in-mexico.html<p><a href="/images/posts/most-polluted-cities-in-mexico/most-polluted-cities-in-mexico.png">
<img alt="PM10 pollution in Guadalajara, Jalisco" class="image-process-article-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/article-image/most-polluted-cities-in-mexico.png"/>
</a></p>
<p>I’ve created an R package to download air quality data from the
website of the
<em><a href="http://sinaica.inecc.gob.mx/">Sistema Nacional de Información de la Calidad del Aire</a></em>
and published it to <span class="caps">CRAN</span>. To install it you have to type the following:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>install.packages<span class="p">(</span><span class="s">"rsinaica"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p>you can also install the development version by typing:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4</pre></div></td><td class="code"><div class="highlight"><pre><span class="kr">if</span> <span class="p">(</span><span class="o">!</span><span class="kn">require</span><span class="p">(</span>devtools<span class="p">))</span> <span class="p">{</span>
install.packages<span class="p">(</span><span class="s">"devtools"</span><span class="p">)</span>
<span class="p">}</span>
devtools<span class="o">::</span>install_github<span class="p">(</span><span class="s">"diegovalle/rsinaica"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Website</td>
<td><a href="https://hoyodesmog.diegovalle.net/rsinaica/">https://hoyodesmog.diegovalle.net/rsinaica/</a></td>
</tr>
<tr>
<td>Download from <span class="caps">CRAN</span></td>
<td><a href="https://cran.r-project.org/package=rsinaica">https://cran.r-project.org/package=rsinaica</a></td>
</tr>
<tr>
<td>Browse source code</td>
<td><a href="https://github.com/diegovalle/rsinaica">https://github.com/diegovalle/rsinaica</a></td>
</tr>
<tr>
<td>Report bugs</td>
<td><a href="https://github.com/diegovalle/rsinaica/issues">https://github.com/diegovalle/rsinaica/issues</a></td>
</tr>
</tbody>
</table>
<p>The <em>Instituto Nacional de Ecología y Cambio Climático</em> (<span class="caps">INECC</span>)
created the <a href="http://sinaica.inecc.gob.mx"><span class="caps">SINAICA</span> website</a> to gather
the information generated by the more than a hundred air quality
monitoring stations located throughout Mexico. The pollution and
meteorological information is generated by the monitoring stations run
by the state and local authorities, who then transmit it to <span class="caps">SINAICA</span>.</p>
<p>The <code>rsinaica</code> package provides tools for downloading that information; for example, you
can easily create <a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/rsinaica.html">pollution maps</a>:</p>
<p><a href="/images/posts/most-polluted-cities-in-mexico/guadalajara.png">
<img alt="Map of PM10 pollution in Guadalajara during 2017" class="image-process-article-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/article-image/guadalajara.png"/>
</a></p>
<p>And rank cities by how polluted they are (be sure to click the links):</p>
<h5><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/ozone_awards.html">Ozone</a></h5>
<p><a href="/images/posts/most-polluted-cities-in-mexico/ozone-vm.png">
<img alt="Valle de México is the most ozone-polluted city in Mexico" class="image-process-large-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/large-image/ozone-vm.png"/>
</a></p>
<h5><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/pm10_awards.html"><span class="caps">PM</span><sub>10</sub></a></h5>
<p><a href="/images/posts/most-polluted-cities-in-mexico/pm10-monterrey.png">
<img alt="Monterrey is the most PM10-polluted city in Mexico" class="image-process-large-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/large-image/pm10-monterrey.png"/>
</a></p>
<h5><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/pm25_awards.html"><span class="caps">PM</span><sub>2.5</sub></a></h5>
<p><a href="/images/posts/most-polluted-cities-in-mexico/pm25-toluca.png">
<img alt="Toluca is the most PM2.5-polluted city in Mexico" class="image-process-large-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/large-image/pm25-toluca.png"/>
</a></p>
<p>Guadalajara gets a special mention since they managed to take second
place in all categories. Congratulations and better luck next year!</p>
<p><a href="/images/posts/most-polluted-cities-in-mexico/top3.png">
<img alt="Toluca is the most PM2.5-polluted city in Mexico" class="image-process-large-image" src="/images/posts/most-polluted-cities-in-mexico/derivatives/large-image/top3.png"/>
</a></p>
<p>The package also has
an <a href="https://hoyodesmog.diegovalle.net/rsinaica/">official website</a>
with several examples:</p>
<ul>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/rsinaica.html">Map of pollution levels</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/airezmvm_vs_rsinaica.html">Comparing rsinaica to aire.zmvm</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/errors.html">Errors in the <span class="caps">SINAICA</span> data</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/ozone_awards.html">Most Ozone-Polluted City in Mexico - 2017</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/pm10_awards.html">Most <span class="caps">PM10</span> Polluted City in Mexico - 2017</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/pm25_awards.html">Most <span class="caps">PM2</span>.5 Polluted City in Mexico - 2017</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/pollution_cdmx_vs_guadalajara.html">Ozone Pollution in <span class="caps">CDMX</span> and Guadalajara</a></li>
<li><a href="https://hoyodesmog.diegovalle.net/rsinaica/articles/articles/trends.html">Long-term pollution trends</a></li>
</ul>How to create crime maps of Mexico City2016-10-31T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2016-10-31:2016/10/crime-maps-of-mexico-city.html<p>Thanks to an information request to the <span class="caps">SSP</span>‑<span class="caps">CDMX</span> <a href="https://hoyodecrimen.com">hoyodecrimen.com</a> now has crime data at the
<a href="https://hoyodecrimen.com/mapa#/19.36753/-99.14754/11">latitude and longitude level</a>. You
can access the data systematically using the
<a href="https://hoyodecrimen.com/api"><span class="caps">API</span></a> or
<a href="https://hoyodecrimen.com/acerca">download</a> it in full. In this post
I’ll provide many examples of how to manipulate the <span class="caps">API</span> to create maps.</p>
<p><a href="https://hoyodecrimen.com"><img alt="" src="/images/posts/crime-maps-of-mexico-city/crime-cdmx.jpg"/></a></p>
<h2>I.</h2>
<p>First, we’ll load the R packages we need:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22</pre></div></td><td class="code"><div class="highlight"><pre><span class="kn">library</span><span class="p">(</span><span class="s">"DCluster"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"jsonlite"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"RCurl"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"jsonlite"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"rgdal"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"rgeos"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"ggplot2"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"ggmap"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"RColorBrewer"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"stringr"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"scales"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"geojsonio"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"downloader"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"spdep"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"viridis"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"maptools"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"rvest"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"dplyr"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"stringr"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"stringi"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"geojsonio"</span><span class="p">)</span>
<span class="kn">library</span><span class="p">(</span><span class="s">"knitr"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p>Then, we’ll download a list of all crimes available from hoyodecrimen
(since the data comes from
<a href="https://hoyodecrimen.com/acerca"><span class="caps">FOIA</span> request</a> the specific crimes
available may vary depending on when you access the <span class="caps">API</span>). To do this,
we can use the jsonlite package to convert the <span class="caps">JSON</span> data the <span class="caps">API</span>
endpoints return into data.frames.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre>crimes <span class="o"><-</span> fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/crimes"</span><span class="p">)</span><span class="o">$</span>rows
kable<span class="p">(</span>crimes<span class="p">,</span> caption <span class="o">=</span> <span class="s">'List of crimes available from hoyodecrimen.com'</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<table>
<thead>
<tr>
<th align="left">crime</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
</tr>
<tr>
<td align="left"><span class="caps">LESIONES</span> <span class="caps">POR</span> <span class="caps">ARMA</span> <span class="caps">DE</span> <span class="caps">FUEGO</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">METRO</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">METRO</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">MICROBUS</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">MICROBUS</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">TAXI</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">CASA</span> <span class="caps">HABITACION</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">CUENTAHABIENTE</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">NEGOCIO</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">REPARTIDOR</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">REPARTIDOR</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">TRANSEUNTE</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">TRANSEUNTE</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">TRANSPORTISTA</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> A <span class="caps">TRANSPORTISTA</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> <span class="caps">DE</span> <span class="caps">VEHICULO</span> <span class="caps">AUTOMOTOR</span> <span class="caps">C.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">ROBO</span> <span class="caps">DE</span> <span class="caps">VEHICULO</span> <span class="caps">AUTOMOTOR</span> <span class="caps">S.V.</span></td>
</tr>
<tr>
<td align="left"><span class="caps">VIOLACION</span></td>
</tr>
</tbody>
</table>
<p>All requests to the <span class="caps">API</span> start with the address
<code>https://hoyodecrimen.com/api/v1/</code> followed by the specific path of
the data you want, sometimes with query parameters (the part of the url
followed by ?) specifying the start and end dates of the data you need.</p>
<p>If you wanted to download the sum of all murders commited in <span class="caps">CDMX</span>
since 2014 you’d look up the appropriate method in the
<a href="https://hoyodecrimen.com/api/#get--api-v1-df-crimes-(string-crime)-series">documentation</a>. And
then use the following code to create a chart:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6</pre></div></td><td class="code"><div class="highlight"><pre><span class="c1"># Note that since the crime we want to graph, 'Homicidio Doloso',</span>
<span class="c1"># contains a space we need to encode the URL</span>
homicidio_series <span class="o"><-</span> fromJSON<span class="p">(</span>str_c<span class="p">(</span><span class="s">"https://hoyodecrimen.com"</span><span class="p">,</span>
URLencode<span class="p">(</span><span class="s">"/api/v1/df/crimes/HOMICIDIO DOLOSO/series?start_date=2014-01&end_date=2016-09"</span><span class="p">)))</span><span class="o">$</span>rows
kable<span class="p">(</span><span class="kp">head</span><span class="p">(</span>homicidio_series<span class="p">),</span> caption <span class="o">=</span> <span class="s">'Homicides in CDMX since 2014'</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<table>
<thead>
<tr>
<th align="right">count</th>
<th align="left">crime</th>
<th align="left">date</th>
<th align="right">population</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">71</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-01</td>
<td align="right">8785911</td>
</tr>
<tr>
<td align="right">55</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-02</td>
<td align="right">8785911</td>
</tr>
<tr>
<td align="right">91</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-03</td>
<td align="right">8785911</td>
</tr>
<tr>
<td align="right">76</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-04</td>
<td align="right">8785911</td>
</tr>
<tr>
<td align="right">64</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-05</td>
<td align="right">8785911</td>
</tr>
<tr>
<td align="right">78</td>
<td align="left"><span class="caps">HOMICIDIO</span> <span class="caps">DOLOSO</span></td>
<td align="left">2014-06</td>
<td align="right">8785911</td>
</tr>
</tbody>
</table>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5</pre></div></td><td class="code"><div class="highlight"><pre>ggplot<span class="p">(</span>homicidio_series<span class="p">,</span> aes<span class="p">(</span><span class="kp">as.Date</span><span class="p">(</span>str_c<span class="p">(</span><span class="kp">date</span><span class="p">,</span> <span class="s">"-01"</span><span class="p">)),</span> count<span class="p">))</span> <span class="o">+</span>
geom_line<span class="p">()</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"CDMX - HOMICIDIO DOLOSO"</span><span class="p">)</span> <span class="o">+</span>
xlab<span class="p">(</span><span class="s">"date"</span><span class="p">)</span> <span class="o">+</span>
scale_y_continuous<span class="p">(</span>expand <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="m">0</span><span class="p">,</span> <span class="m">0</span><span class="p">),</span> limits <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="m">0</span><span class="p">,</span> <span class="kp">max</span><span class="p">(</span>homicidio_series<span class="o">$</span>count<span class="p">)))</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-2-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-2-1.png"/>
</a></p>
<p>We can also download geojson maps of
<a href="https://hoyodecrimen.com/api/#get--api-v1-cuadrantes-geojson">cuadrantes</a>
and
<a href="https://hoyodecrimen.com/api/#get--api-v1-sectores-geojson">sectores</a>
which we can convert to SpatialPolygonsDataFrame to work with in R.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12</pre></div></td><td class="code"><div class="highlight"><pre><span class="c1"># create a tempory to save the geojson from the API</span>
tmp_cuadrantes <span class="o">=</span> <span class="kp">tempfile</span><span class="p">(</span><span class="s">"cuads"</span><span class="p">,</span> fileext <span class="o">=</span> <span class="s">".json"</span><span class="p">)</span>
download<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/geojson"</span><span class="p">,</span> tmp_cuadrantes<span class="p">)</span>
<span class="c1"># read the geojson into a spatial object</span>
cuadrantes <span class="o">=</span> readOGR<span class="p">(</span>tmp_cuadrantes<span class="p">,</span> <span class="s">"OGRGeoJSON"</span><span class="p">,</span> verbose <span class="o">=</span> <span class="kc">FALSE</span><span class="p">)</span>
tmp_sectores <span class="o">=</span> <span class="kp">tempfile</span><span class="p">(</span><span class="s">"secs"</span><span class="p">,</span> fileext <span class="o">=</span> <span class="s">".json"</span><span class="p">)</span>
download<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/sectores/geojson"</span><span class="p">,</span> tmp_sectores<span class="p">)</span>
sectores <span class="o">=</span> readOGR<span class="p">(</span>tmp_sectores<span class="p">,</span> <span class="s">"OGRGeoJSON"</span><span class="p">,</span> verbose <span class="o">=</span> <span class="kc">FALSE</span><span class="p">)</span>
plot<span class="p">(</span>cuadrantes<span class="p">,</span> main <span class="o">=</span> <span class="s">"cuadrantes"</span><span class="p">)</span>
plot<span class="p">(</span>sectores<span class="p">,</span> main <span class="o">=</span> <span class="s">"sectores"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/cuadrantes.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/cuadrantes.png"/>
</a></p>
<p><a href="/images/posts/crime-maps-of-mexico-city/sectores.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/sectores.png"/>
</a></p>
<h2><span class="caps">II</span>.</h2>
<p>Now that we have the maps, we can download
<a href="https://hoyodecrimen.com/api/#get--api-v1-sectores-(string-sector)-crimes-(string-crime)-period">period data</a>
(by default the last twelve months) for all crimes and merge
them. Then use the ggmap package to create choropleths on top of a
Google Maps image.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29</pre></div></td><td class="code"><div class="highlight"><pre>crime.sectors <span class="o"><-</span> fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/sectores/all/crimes/all/period"</span><span class="p">)</span><span class="o">$</span>rows
<span class="c1">#fortify the data for ggplot2</span>
fsectors <span class="o"><-</span> fortify<span class="p">(</span>sectores<span class="p">,</span> region <span class="o">=</span> <span class="s">"sector"</span><span class="p">)</span>
sector.map <span class="o"><-</span> left_join<span class="p">(</span>fsectors<span class="p">,</span> crime.sectors<span class="p">,</span> by <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="s">"id"</span> <span class="o">=</span> <span class="s">"sector"</span><span class="p">))</span>
sector.map<span class="o">$</span>rate <span class="o"><-</span> sector.map<span class="o">$</span>count <span class="o">/</span> sector.map<span class="o">$</span>population <span class="o">*</span> <span class="m">10</span><span class="o">^</span><span class="m">5</span>
crime.cuadrantes <span class="o"><-</span> fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/all/crimes/all/period"</span><span class="p">)</span><span class="o">$</span>rows
fcuadrantes <span class="o"><-</span> fortify<span class="p">(</span>cuadrantes<span class="p">,</span> region <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
cuadrante.map <span class="o"><-</span> left_join<span class="p">(</span>fcuadrantes<span class="p">,</span> crime.cuadrantes<span class="p">,</span> by <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="s">"id"</span> <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">))</span>
cuadrante.map<span class="o">$</span>rate <span class="o"><-</span> cuadrante.map<span class="o">$</span>count <span class="o">/</span> cuadrante.map<span class="o">$</span>population <span class="o">*</span> <span class="m">10</span><span class="o">^</span><span class="m">5</span>
draw_gmap <span class="o"><-</span> <span class="kr">function</span><span class="p">(</span>map<span class="p">,</span> crimeName<span class="p">,</span> bb<span class="p">,</span> pal<span class="p">,</span> fill <span class="o">=</span> <span class="s">"rate"</span><span class="p">,</span> alpha<span class="o">=</span><span class="m">.9</span><span class="p">)</span> <span class="p">{</span>
ggmap<span class="p">(</span>get_map<span class="p">(</span>location <span class="o">=</span> bb<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>data<span class="o">=</span> <span class="kp">subset</span><span class="p">(</span>map<span class="p">,</span> crime <span class="o">==</span> crimeName<span class="p">),</span>
aes_string<span class="p">(</span><span class="s">"long"</span><span class="p">,</span> <span class="s">"lat"</span><span class="p">,</span> group <span class="o">=</span> <span class="s">"group"</span><span class="p">,</span> fill <span class="o">=</span> fill<span class="p">),</span>
color <span class="o">=</span> <span class="s">"#666666"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">,</span>
alpha <span class="o">=</span> alpha<span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span> <span class="o">+</span>
ggtitle<span class="p">(</span>crimeName<span class="p">)</span> <span class="o">+</span>
<span class="c1">#scale_fill_viridis(option="plasma") +</span>
scale_fill_continuous<span class="p">(</span>low <span class="o">=</span> brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span> pal<span class="p">)[</span><span class="m">1</span><span class="p">],</span>
high <span class="o">=</span> brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span> pal<span class="p">)[</span><span class="m">9</span><span class="p">],</span>
space <span class="o">=</span> <span class="s">"Lab"</span><span class="p">,</span> na.value <span class="o">=</span> <span class="s">"grey50"</span><span class="p">,</span>
guide <span class="o">=</span> <span class="s">"colourbar"</span><span class="p">)</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span>
<span class="p">}</span>
bb.sector <span class="o"><-</span> bbox<span class="p">(</span>sectores<span class="p">)</span>
draw_gmap<span class="p">(</span>sector.map<span class="p">,</span> <span class="s">"HOMICIDIO DOLOSO"</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Reds"</span><span class="p">,</span> <span class="s">"rate"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-1.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>sector.map<span class="p">,</span> <span class="s">"LESIONES POR ARMA DE FUEGO"</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Greys"</span><span class="p">,</span> <span class="s">"rate"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-2.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-2.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>sector.map<span class="p">,</span> <span class="s">"ROBO A TRANSEUNTE C.V."</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Greys"</span><span class="p">,</span> <span class="s">"rate"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-3.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-3.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>cuadrante.map<span class="p">,</span> <span class="s">"ROBO DE VEHICULO AUTOMOTOR S.V."</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"YlGn"</span><span class="p">,</span> <span class="s">"count"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-4.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-4.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>cuadrante.map<span class="p">,</span> <span class="s">"ROBO DE VEHICULO AUTOMOTOR C.V."</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Greens"</span><span class="p">,</span> <span class="s">"count"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-5.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-5.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>cuadrante.map<span class="p">,</span> <span class="s">"LESIONES POR ARMA DE FUEGO"</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Greys"</span><span class="p">,</span> <span class="s">"count"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/lesiones-fuego.png">
<img alt="Firearm lesions counts by cuadrante" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/lesiones-fuego.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>draw_gmap<span class="p">(</span>cuadrante.map<span class="p">,</span> <span class="s">"HOMICIDIO DOLOSO"</span><span class="p">,</span> bb.sector<span class="p">,</span> <span class="s">"Reds"</span><span class="p">,</span> <span class="s">"count"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-3-6.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-3-6.png"/>
</a></p>
<h2><span class="caps">III</span>.</h2>
<p>One thing that you may have noticed from the ‘Homicidio Doloso’ and
‘Lesiones por Arma de Fuego’ cuadrante maps is that the cuadrantes
that contain hospitals tend to have very high homicides counts (dark
red and gray in the maps).</p>
<p>We can investigate the phenomena further by
<a href="https://hoyodecrimen.com/api/#get--api-v1-latlong-crimes-(string-crime)-coords-(string-long)-(string-lat)-distance-(int-distance)">downloading the coordinates</a>
of homicides and firearm lesions within 1,000 meters of hospitals.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39</pre></div></td><td class="code"><div class="highlight"><pre><span class="c1">#function to download a cuadrante given a latitude and longitude</span>
get_cuadrante <span class="o"><-</span> <span class="kr">function</span><span class="p">(</span>long<span class="p">,</span> lat<span class="p">){</span>
tmp_file <span class="o">=</span> <span class="kp">tempfile</span><span class="p">(</span>fileext <span class="o">=</span> <span class="s">".geojson"</span><span class="p">)</span>
<span class="kp">write</span><span class="p">(</span>fromJSON<span class="p">(</span>str_c<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/pip/"</span><span class="p">,</span>long<span class="p">,</span><span class="s">"/"</span><span class="p">,</span>lat<span class="p">))</span><span class="o">$</span>pip<span class="o">$</span>geometry<span class="p">,</span>
file <span class="o">=</span> tmp_file<span class="p">)</span>
cuad <span class="o"><-</span> geojson_read<span class="p">(</span>tmp_file<span class="p">,</span> method <span class="o">=</span> <span class="s">"local"</span><span class="p">,</span> what <span class="o">=</span> <span class="s">"sp"</span><span class="p">)</span>
cuad.f <span class="o"><-</span> fortify<span class="p">(</span>cuad<span class="p">)</span>
<span class="p">}</span>
<span class="c1">#function to create a point map of crimes with their cuadrante</span>
latlong_map <span class="o"><-</span> <span class="kr">function</span><span class="p">(</span>title<span class="p">,</span> lat<span class="p">,</span> long<span class="p">,</span> distance<span class="p">,</span> crime <span class="o">=</span> <span class="s">"HOMICIDIO DOLOSO"</span><span class="p">,</span>
fill <span class="o">=</span> <span class="s">"red"</span><span class="p">)</span> <span class="p">{</span>
geocrimes <span class="o"><-</span> fromJSON<span class="p">(</span>str_c<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/latlong/crimes/"</span><span class="p">,</span>
URLencode<span class="p">(</span>crime<span class="p">),</span> <span class="s">"/coords/"</span><span class="p">,</span>
long<span class="p">,</span>
<span class="s">"/"</span><span class="p">,</span>
lat<span class="p">,</span>
<span class="s">"/distance/"</span><span class="p">,</span>
distance<span class="p">,</span>
<span class="s">"?start_date=2013-01&end_date=2016-09"</span><span class="p">))</span><span class="o">$</span>rows
cuadrante.f <span class="o"><-</span> get_cuadrante<span class="p">(</span>long<span class="p">,</span> lat<span class="p">)</span>
bb <span class="o"><-</span> bbox<span class="p">(</span>coordinates<span class="p">(</span>geocrimes<span class="p">[,</span><span class="kt">c</span><span class="p">(</span><span class="s">"long"</span><span class="p">,</span> <span class="s">"lat"</span><span class="p">)]))</span>
ggmap<span class="p">(</span>get_map<span class="p">(</span>location <span class="o">=</span> bb<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>data <span class="o">=</span> cuadrante.f<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">),</span>
color <span class="o">=</span> <span class="s">"black"</span><span class="p">,</span> fill <span class="o">=</span> <span class="s">"yellow"</span><span class="p">,</span> alpha <span class="o">=</span> <span class="m">.2</span><span class="p">)</span> <span class="o">+</span>
geom_point<span class="p">(</span>data<span class="o">=</span> <span class="kp">subset</span><span class="p">(</span>geocrimes<span class="p">,</span> crime <span class="o">==</span> crime<span class="p">),</span>
aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">),</span>
fill <span class="o">=</span> fill<span class="p">,</span>
color <span class="o">=</span> <span class="s">"black"</span><span class="p">,</span>
size <span class="o">=</span> <span class="m">3</span><span class="p">,</span>
shape <span class="o">=</span> <span class="m">21</span><span class="p">,</span>
alpha <span class="o">=</span> <span class="m">.8</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span>title<span class="p">)</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span>
<span class="p">}</span>
latlong_map<span class="p">(</span><span class="s">"Hospital Balbuena - Murder"</span><span class="p">,</span> <span class="m">19.42410</span><span class="p">,</span> <span class="m">-99.115520</span><span class="p">,</span> <span class="m">1000</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-4-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-4-1.png"/>
</a></p>
<p><a href="https://hoyodecrimen.com/mapa#/19.42399/-99.11504/19">Interactive Map</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Hospitales en Lindavista - Murder"</span><span class="p">,</span> <span class="m">19.482973</span><span class="p">,</span> <span class="m">-99.134091</span><span class="p">,</span> <span class="m">1000</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-4-2.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-4-2.png"/>
</a></p>
<p><a href="https://hoyodecrimen.com/mapa#/19.48244/-99.13414/18">Interactive Map</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Hospital General - Murder"</span><span class="p">,</span> <span class="m">19.411300</span><span class="p">,</span> <span class="m">-99.152405</span><span class="p">,</span> <span class="m">1000</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-4-3.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-4-3.png"/>
</a></p>
<p><a href="https://hoyodecrimen.com/mapa#/19.41124/-99.15215/17">Interactive Map</a> - Note that there is a second hospital in another cuadrante.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Hospital General Iztapalapa - Murder"</span><span class="p">,</span> <span class="m">19.343515</span><span class="p">,</span> <span class="m">-99.027382</span><span class="p">,</span> <span class="m">1000</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-4-4.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-4-4.png"/>
</a></p>
<p><a href="https://hoyodecrimen.com/mapa#/19.34311/-99.02699/19">Interactive Map</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Hospital General Iztapalapa - Firearm Lesions"</span><span class="p">,</span>
<span class="m">19.343515</span><span class="p">,</span> <span class="m">-99.027382</span><span class="p">,</span>
<span class="m">1000</span><span class="p">,</span>
<span class="s">"LESIONES POR ARMA DE FUEGO"</span><span class="p">,</span> fill <span class="o">=</span> <span class="s">"darkgray"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-4-5.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-4-5.png"/>
</a></p>
<p>While narcos sometimes
<a href="http://internacional.elpais.com/internacional/2016/10/25/mexico/1477415665_296723.html">kill the wounded receiving care in hospitals</a>,
this is the exception rather than the rule. It looks like some
homicides are recorded with the latitude and longitude of the place of
death, and in the case of firearm lesions I’m guessing it’s where the
crime was reported to the police. Also note that there is a certain
amount of error associated with the location of each crime, while the
cuadrante where the crime was recorded is usually correct, the latitude
and longitude sometimes is off by a 100 meters or so.</p>
<p>These are the cuadrantes codes with hospitals and an unusual number of victims:</p>
<ul>
<li>O-2.5.7</li>
<li>O-2.2.4</li>
<li>N-4.4.4</li>
<li>N-1.3.10</li>
<li>C-2.1.16</li>
<li>N-2.2.1</li>
<li>P-1.5.7</li>
<li>P-3.1.1</li>
</ul>
<p>Just for fun here are the cuadrantes with the highest counts of car robbery:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Mercado Xochimilo - Car Robbery wo/violence"</span><span class="p">,</span> <span class="m">19.251478</span><span class="p">,</span> <span class="m">-99.094207</span><span class="p">,</span> <span class="m">1000</span><span class="p">,</span> <span class="s">"ROBO DE VEHICULO AUTOMOTOR S.V."</span><span class="p">,</span> fill <span class="o">=</span> <span class="s">"green"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-5-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-5-1.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>latlong_map<span class="p">(</span><span class="s">"Lindavista - Car Robbery w/violence"</span><span class="p">,</span> <span class="m">19.506460</span><span class="p">,</span> <span class="m">-99.122815</span><span class="p">,</span> <span class="m">1000</span><span class="p">,</span> <span class="s">"ROBO DE VEHICULO AUTOMOTOR C.V."</span><span class="p">,</span> fill <span class="o">=</span> <span class="s">"darkgreen"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-5-2.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-5-2.png"/>
</a></p>
<h2><span class="caps">IV</span>.</h2>
<p>Ideally we’d like to be able to map the <em>rates</em> of crimes at the
cuadrante delictivo level, like we did with the sectores, but the
crime rates can be statistically unstable due to the small size of the
cuadrantes and the relative small number of people at risk. Plus, as I
mentioned, homicides and firearm lesions are sometimes recorded as
having happened inside a hospital. To get a better sense of the crime
risk in each cuadrante we are going to smooth the rate using empirical
bayes smoothing:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28</pre></div></td><td class="code"><div class="highlight"><pre><span class="c1"># Construct neighbours list from polygon list</span>
cuad.nb <span class="o"><-</span> poly2nb<span class="p">(</span>cuadrantes<span class="p">,</span> row.names <span class="o">=</span> <span class="kp">as.character</span><span class="p">(</span>cuadrantes<span class="o">$</span>cuadrante<span class="p">))</span>
hom <span class="o"><-</span> fromJSON<span class="p">(</span>str_c<span class="p">(</span><span class="s">"https://hoyodecrimen.com"</span><span class="p">,</span>
URLencode<span class="p">(</span><span class="s">"/api/v1/cuadrantes/ALL/crimes/HOMICIDIO DOLOSO/period"</span><span class="p">)))</span><span class="o">$</span>rows
hom <span class="o"><-</span> <span class="kp">subset</span><span class="p">(</span>hom<span class="p">,</span> cuadrante <span class="o">!=</span> <span class="s">"(NO ESPECIFICADO)"</span><span class="p">)</span>
<span class="c1"># match the order with the neighborhood file</span>
hom <span class="o"><-</span> hom<span class="p">[</span><span class="kp">match</span><span class="p">(</span>cuadrantes<span class="o">$</span>cuadrante<span class="p">,</span> hom<span class="o">$</span>cuadrante<span class="p">),]</span>
<span class="c1"># fill in the population of cuadrantes with zero residents</span>
<span class="c1"># with the mean of their neighboring cuadrantes</span>
<span class="kr">for</span><span class="p">(</span>zero_cuad <span class="kr">in</span> hom<span class="o">$</span>cuadrante<span class="p">[</span><span class="kp">which</span><span class="p">(</span>hom<span class="o">$</span>population <span class="o">==</span> <span class="m">0</span><span class="p">)])</span>
hom<span class="o">$</span>population <span class="o"><-</span> <span class="kp">mean</span><span class="p">(</span>hom<span class="o">$</span>population<span class="p">[</span>cuad.nb<span class="p">[[</span><span class="kp">which</span><span class="p">(</span>hom<span class="o">$</span>cuadrante <span class="o">==</span> zero_cuad<span class="p">)]]])</span>
hom<span class="o">$</span>rate <span class="o"><-</span> hom<span class="o">$</span>count <span class="o">/</span> hom<span class="o">$</span>population <span class="o">*</span> <span class="m">10</span><span class="o">^</span><span class="m">5</span>
smth<span class="o"><-</span>empbaysmooth<span class="p">(</span>hom<span class="o">$</span>count<span class="p">,</span> hom<span class="o">$</span>population <span class="o">*</span> <span class="kp">sum</span><span class="p">(</span>hom<span class="o">$</span>count<span class="p">)</span> <span class="o">/</span> <span class="kp">sum</span><span class="p">(</span>hom<span class="o">$</span>population<span class="p">))</span>
hom<span class="o">$</span>smooth <span class="o"><-</span> smth<span class="o">$</span>smthrr
cuadrantes.f <span class="o"><-</span> fortify<span class="p">(</span>cuadrantes<span class="p">,</span> region <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
cuadrantes.f <span class="o"><-</span> <span class="kp">merge</span><span class="p">(</span>cuadrantes.f<span class="p">,</span> hom<span class="p">,</span> by.x <span class="o">=</span> <span class="s">"id"</span><span class="p">,</span> by.y <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
ggplot<span class="p">(</span>cuadrantes.f<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>aes<span class="p">(</span>fill <span class="o">=</span> smooth<span class="p">),</span> color <span class="o">=</span> <span class="s">"#555555"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span><span class="o">+</span>
scale_fill_gradientn<span class="p">(</span>colours<span class="o">=</span><span class="kp">rev</span><span class="p">(</span>brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span><span class="s">"YlOrRd"</span><span class="p">)))</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Smoothed homicide rates at the cuadrante level"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-6-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-6-1.png"/>
</a></p>
<p>The cuadrantes with hospitals still give the impression of being
extremely violent. One interesting thing about hospital with lots of
murders is that the cuadrantes surrounding them also tend to have a lot
of murders —there is a lot of violence near some hospitals.</p>
<p><a href="https://hoyodecrimen.com/cuadrantes-mapa#14/19.4048/-99.1344">
<img alt="Cuadrantes near hospitals" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/cuadrantes-hospitales.png"/>
</a></p>
<p>This makes it more likely that the people who died in a hospital were
injured in a nearby location and were then transported to the nearest
hospital. A solution to the problem of cuadrantes with
hospitals being incorrectly perceived as very violent would be to
average the rate of violence in each cuadrante with the nearest, say,
8 neighbors.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20</pre></div></td><td class="code"><div class="highlight"><pre>cuad.nb <span class="o"><-</span> knn2nb<span class="p">(</span>knearneigh<span class="p">(</span>coordinates<span class="p">(</span>cuadrantes<span class="p">),</span> k <span class="o">=</span> <span class="m">8</span><span class="p">),</span>
row.names <span class="o">=</span> <span class="kp">as.character</span><span class="p">(</span>cuadrantes<span class="o">$</span>cuadrante<span class="p">))</span>
<span class="c1">#cuad.nb <- poly2nb(cuadrantes, row.names = as.character(cuadrantes$cuadrante))</span>
plot<span class="p">(</span>cuad.nb<span class="p">,</span> coordinates<span class="p">(</span>cuadrantes<span class="p">))</span>
hom<span class="o">$</span>smooth <span class="o"><-</span> <span class="kp">sapply</span><span class="p">(</span><span class="m">1</span><span class="o">:</span><span class="kp">nrow</span><span class="p">(</span>hom<span class="p">),</span> <span class="kr">function</span><span class="p">(</span>x<span class="p">)</span> <span class="p">{</span>
w <span class="o"><-</span> <span class="kt">c</span><span class="p">(</span>hom<span class="o">$</span>population<span class="p">[</span>x<span class="p">],</span> hom<span class="o">$</span>population<span class="p">[</span>cuad.nb<span class="p">[[</span>x<span class="p">]]])</span>
r <span class="o"><-</span> <span class="kt">c</span><span class="p">(</span>hom<span class="o">$</span>rate<span class="p">[</span>x<span class="p">],</span> hom<span class="o">$</span>rate<span class="p">[</span>cuad.nb<span class="p">[[</span>x<span class="p">]]])</span>
<span class="kr">return</span><span class="p">(</span><span class="kp">sum</span><span class="p">(</span>w <span class="o">*</span> r<span class="p">)</span><span class="o">/</span><span class="kp">sum</span><span class="p">(</span>w<span class="p">))</span>
<span class="p">})</span>
cuadrantes.f <span class="o"><-</span> fortify<span class="p">(</span>cuadrantes<span class="p">,</span> region <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
cuadrantes.f <span class="o"><-</span> <span class="kp">merge</span><span class="p">(</span>cuadrantes.f<span class="p">,</span> hom<span class="p">,</span> by.x <span class="o">=</span> <span class="s">"id"</span><span class="p">,</span> by.y <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
ggplot<span class="p">(</span>cuadrantes.f<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>aes<span class="p">(</span>fill <span class="o">=</span> smooth<span class="p">),</span> color <span class="o">=</span> <span class="s">"#555555"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span><span class="o">+</span>
scale_fill_gradientn<span class="p">(</span>colours<span class="o">=</span><span class="kp">rev</span><span class="p">(</span>brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span><span class="s">"YlOrRd"</span><span class="p">)))</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Smoothed homicide rates by nearest neighbors"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/neighbors8.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/neighbors8.png"/>
</a></p>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-7-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-7-1.png"/>
</a></p>
<p>Now it looks much better, and this is what the frontpage of
<a href="https://hoyodecrimen.com">hoyodecrimen</a> uses to compare crime rates
in your cuadrante (though we’re still missing uncertainty
estimates). We can use the same averaging method for other crimes:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34</pre></div></td><td class="code"><div class="highlight"><pre>smooth_cuads <span class="o"><-</span> <span class="kr">function</span><span class="p">(</span>df<span class="p">,</span> cuad.nb<span class="p">)</span> <span class="p">{</span>
df <span class="o"><-</span> <span class="kp">subset</span><span class="p">(</span>df<span class="p">,</span> cuadrante <span class="o">!=</span> <span class="s">"(NO ESPECIFICADO)"</span><span class="p">)</span>
<span class="c1"># match the order with the neighborhood file</span>
df <span class="o"><-</span> df<span class="p">[</span><span class="kp">match</span><span class="p">(</span>cuadrantes<span class="o">$</span>cuadrante<span class="p">,</span> df<span class="o">$</span>cuadrante<span class="p">),]</span>
<span class="c1"># fill in the population of cuadrantes with zero residents</span>
<span class="c1"># with the mean of their neighboring cuadrantes</span>
<span class="kr">for</span><span class="p">(</span>zero_cuad <span class="kr">in</span> df<span class="o">$</span>cuadrante<span class="p">[</span><span class="kp">which</span><span class="p">(</span>df<span class="o">$</span>population <span class="o">==</span> <span class="m">0</span><span class="p">)])</span>
df<span class="o">$</span>population <span class="o"><-</span> <span class="kp">mean</span><span class="p">(</span>df<span class="o">$</span>population<span class="p">[</span>cuad.nb<span class="p">[[</span><span class="kp">which</span><span class="p">(</span>df<span class="o">$</span>cuadrante <span class="o">==</span> zero_cuad<span class="p">)]]])</span>
df<span class="o">$</span>rate <span class="o"><-</span> df<span class="o">$</span>count <span class="o">/</span> df<span class="o">$</span>population <span class="o">*</span> <span class="m">10</span><span class="o">^</span><span class="m">5</span>
df<span class="o">$</span>smooth <span class="o"><-</span> <span class="kp">sapply</span><span class="p">(</span><span class="m">1</span><span class="o">:</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">),</span> <span class="kr">function</span><span class="p">(</span>x<span class="p">)</span> <span class="p">{</span>
w <span class="o"><-</span> <span class="kt">c</span><span class="p">(</span>df<span class="o">$</span>population<span class="p">[</span>x<span class="p">],</span> df<span class="o">$</span>population<span class="p">[</span>cuad.nb<span class="p">[[</span>x<span class="p">]]])</span>
r <span class="o"><-</span> <span class="kt">c</span><span class="p">(</span>df<span class="o">$</span>rate<span class="p">[</span>x<span class="p">],</span> df<span class="o">$</span>rate<span class="p">[</span>cuad.nb<span class="p">[[</span>x<span class="p">]]])</span>
<span class="kr">return</span><span class="p">(</span><span class="kp">sum</span><span class="p">(</span>w <span class="o">*</span> r<span class="p">)</span><span class="o">/</span><span class="kp">sum</span><span class="p">(</span>w<span class="p">))</span>
<span class="p">})</span>
cuadrantes.f <span class="o"><-</span> fortify<span class="p">(</span>cuadrantes<span class="p">,</span> region <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
cuadrantes.f <span class="o"><-</span> <span class="kp">merge</span><span class="p">(</span>cuadrantes.f<span class="p">,</span> df<span class="p">,</span> by.x <span class="o">=</span> <span class="s">"id"</span><span class="p">,</span> by.y <span class="o">=</span> <span class="s">"cuadrante"</span><span class="p">)</span>
cuadrantes.f
<span class="p">}</span>
<span class="c1">#cuad.nb <- poly2nb(cuadrantes, row.names = as.character(cuadrantes$cuadrante))</span>
cuad_smooth_rvsv <span class="o"><-</span> smooth_cuads<span class="p">(</span>fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/ALL/crimes/ROBO DE VEHICULO AUTOMOTOR S.V./period"</span><span class="p">)</span><span class="o">$</span>rows<span class="p">,</span>
cuad.nb<span class="p">)</span>
ggplot<span class="p">(</span>cuad_smooth_rvsv<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>aes<span class="p">(</span>fill <span class="o">=</span> smooth<span class="p">),</span> color <span class="o">=</span> <span class="s">"#555555"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span><span class="o">+</span>
scale_fill_gradientn<span class="p">(</span>colours<span class="o">=</span><span class="kp">rev</span><span class="p">(</span>brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span><span class="s">"YlGn"</span><span class="p">)))</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Smoothed car robbery wo/v rates by nearest neighbors"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-8-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-8-1.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre>cuad_smooth_rvcv <span class="o"><-</span> smooth_cuads<span class="p">(</span>fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/ALL/crimes/ROBO DE VEHICULO AUTOMOTOR C.V./period"</span><span class="p">)</span><span class="o">$</span>rows<span class="p">,</span>
cuad.nb<span class="p">)</span>
ggplot<span class="p">(</span>cuad_smooth_rvcv<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>aes<span class="p">(</span>fill <span class="o">=</span> smooth<span class="p">),</span> color <span class="o">=</span> <span class="s">"#555555"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span> <span class="o">+</span>
scale_fill_gradientn<span class="p">(</span>colours<span class="o">=</span><span class="kp">rev</span><span class="p">(</span>brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span><span class="s">"BuGn"</span><span class="p">)))</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Smoothed car robbery w/v rates by nearest neighbors"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-8-2.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-8-2.png"/>
</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre>cuad_smooth_rt <span class="o"><-</span> smooth_cuads<span class="p">(</span>fromJSON<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/cuadrantes/ALL/crimes/ROBO A TRANSEUNTE C.V./period"</span><span class="p">)</span><span class="o">$</span>rows<span class="p">,</span>
cuad.nb<span class="p">)</span>
ggplot<span class="p">(</span>cuad_smooth_rt<span class="p">,</span> aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>aes<span class="p">(</span>fill <span class="o">=</span> smooth<span class="p">),</span> color <span class="o">=</span> <span class="s">"#555555"</span><span class="p">,</span> size <span class="o">=</span> <span class="m">.1</span><span class="p">)</span> <span class="o">+</span>
coord_map<span class="p">()</span> <span class="o">+</span>
scale_fill_gradientn<span class="p">(</span>colours<span class="o">=</span><span class="kp">rev</span><span class="p">(</span>brewer.pal<span class="p">(</span><span class="m">9</span><span class="p">,</span><span class="s">"Blues"</span><span class="p">)))</span><span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Smoothed street robbery rates by nearest neighbors"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-8-3.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-8-3.png"/>
</a></p>
<p>There’s still a problem in that to calculate the rates we are using as
denominator the number of people living in the cuadrante, and people
move around the city all time.</p>
<h2>V.</h2>
<p>The Mexico City subway website publishes the number of
passangers using each metro station which we can use to estimate crime
rates by station. First, we download crime data from January to March
2016 since that matches the ridership data available from the
<a href="http://www.metro.cdmx.gob.mx/operacion/afluencia.html">Sistema Colectivo website</a>.
And we’ll only estimate rates for the sum of the following crimes:</p>
<ul>
<li><span class="caps">ROBO</span> A <span class="caps">TRANSEUNTE</span> <span class="caps">C.V.</span></li>
<li><span class="caps">ROBO</span> A <span class="caps">TRANSEUNTE</span> <span class="caps">S.V.</span></li>
<li><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">TAXI</span> C.V</li>
<li><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">MICROBUS</span> <span class="caps">S.V.</span></li>
<li><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">MICROBUS</span> <span class="caps">C.V.</span></li>
<li><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">METRO</span> <span class="caps">S.V.</span></li>
<li><span class="caps">ROBO</span> A <span class="caps">BORDO</span> <span class="caps">DE</span> <span class="caps">METRO</span> <span class="caps">C.V.</span></li>
</ul>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span class="c1"># Set the distance to ridiculously large number of meters to download all CDMX data</span>
geocrimes <span class="o"><-</span> fromJSON<span class="p">(</span>str_c<span class="p">(</span><span class="s">"https://hoyodecrimen.com/api/v1/latlong/crimes/"</span><span class="p">,</span>
URLencode<span class="p">(</span><span class="s">"ROBO A TRANSEUNTE C.V.,ROBO A TRANSEUNTE S.V.,ROBO A BORDO DE TAXI C.V.,ROBO A BORDO DE MICROBUS S.V.,ROBO A BORDO DE MICROBUS C.V.,ROBO A BORDO DE METRO S.V.,ROBO A BORDO DE METRO C.V."</span><span class="p">),</span><span class="s">"/coords/-99.122815/19.506460/distance/50000000000?start_date=2016-01&end_date=2016-04"</span><span class="p">))</span><span class="o">$</span>rows
</pre></div>
</td></tr></table>
<p>Then we clean the ridership data from the
<a href="http://www.metro.cdmx.gob.mx/operacion/afluencia.html">metro website</a>. I
had to clean up the html by hand a bit since it’s so badly formed the
<a href="https://blog.rstudio.org/2014/11/24/rvest-easy-web-scraping-with-r/">rvest package</a>
was unable to parse it.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37</pre></div></td><td class="code"><div class="highlight"><pre>con <span class="o"><-</span> <span class="kp">file</span><span class="p">(</span><span class="s">"data/afluencia.html"</span><span class="p">,</span> <span class="s">"rb"</span><span class="p">)</span>
metro <span class="o"><-</span> read_html<span class="p">(</span>con<span class="p">)</span>
afluencia <span class="o"><-</span> <span class="kt">data.frame</span><span class="p">()</span>
<span class="kr">for</span><span class="p">(</span>i <span class="kr">in</span> <span class="m">1</span><span class="o">:</span><span class="m">4</span><span class="p">)</span> <span class="p">{</span>
df <span class="o"><-</span> metro <span class="o">%>%</span>
html_nodes<span class="p">(</span><span class="s">"table"</span><span class="p">)</span> <span class="o">%>%</span>
<span class="m">.</span><span class="p">[[</span>i<span class="p">]]</span> <span class="o">%>%</span>
html_table<span class="p">(</span>fill <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span>
afluencia <span class="o"><-</span> <span class="kp">rbind</span><span class="p">(</span>afluencia<span class="p">,</span>
<span class="kt">data.frame</span><span class="p">(</span>name<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">1</span><span class="p">],</span>
num<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">2</span><span class="p">],</span>
line<span class="o">=</span>df<span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">]),</span>
<span class="kt">data.frame</span><span class="p">(</span>name<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">4</span><span class="p">],</span>
num<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">5</span><span class="p">],</span>
line<span class="o">=</span>df<span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">4</span><span class="p">]),</span>
<span class="kt">data.frame</span><span class="p">(</span>name<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">7</span><span class="p">],</span>
num<span class="o">=</span>df<span class="p">[</span><span class="m">2</span><span class="o">:</span><span class="p">(</span><span class="kp">nrow</span><span class="p">(</span>df<span class="p">)</span><span class="m">-1</span><span class="p">),</span><span class="m">8</span><span class="p">],</span>
line<span class="o">=</span>df<span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">7</span><span class="p">]))</span>
<span class="p">}</span>
nbs <span class="o"><-</span> stri_escape_unicode<span class="p">(</span>afluencia<span class="o">$</span>name<span class="p">[</span><span class="m">21</span><span class="p">])</span>
<span class="c1"># \\u00a0 is actually the non-breaking space character</span>
<span class="c1"># which we have to remove from the html table</span>
afluencia <span class="o"><-</span> afluencia <span class="o">%>%</span>
mutate<span class="p">(</span>num <span class="o">=</span> <span class="kp">as.numeric</span><span class="p">(</span>str_replace_all<span class="p">(</span>num<span class="p">,</span> <span class="s">","</span><span class="p">,</span> <span class="s">""</span><span class="p">)))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> str_replace_all<span class="p">(</span>name<span class="p">,</span> <span class="s">"[\r\n]"</span> <span class="p">,</span> <span class="s">" "</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> str_replace_all<span class="p">(</span>name<span class="p">,</span> <span class="s">" "</span> <span class="p">,</span> <span class="s">" "</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> str_replace<span class="p">(</span>name<span class="p">,</span> <span class="s">"\\u00a0"</span><span class="p">,</span> <span class="s">""</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> str_replace<span class="p">(</span>name<span class="p">,</span> <span class="s">" "</span><span class="p">,</span> <span class="s">" "</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> <span class="kp">tolower</span><span class="p">(</span>name<span class="p">))</span> <span class="o">%>%</span>
filter<span class="p">(</span>name <span class="o">!=</span> <span class="s">""</span><span class="p">)</span> <span class="o">%>%</span>
mutate<span class="p">(</span>line <span class="o">=</span> str_replace_all<span class="p">(</span>line<span class="p">,</span> <span class="s">"[\r\n]"</span> <span class="p">,</span> <span class="s">" "</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>line <span class="o">=</span> str_replace_all<span class="p">(</span>line<span class="p">,</span> <span class="s">" "</span> <span class="p">,</span> <span class="s">" "</span><span class="p">))</span> <span class="o">%>%</span>
mutate<span class="p">(</span>line <span class="o">=</span> str_replace_all<span class="p">(</span>line<span class="p">,</span> <span class="s">" "</span> <span class="p">,</span> <span class="s">" "</span><span class="p">))</span>
</pre></div>
</td></tr></table>
<p>Then we merge the ridership numbers with a list of geocoded stations previously
download from <a href="http://www.mexicometro.org/Mexico-Metro.kmz">here</a> and converted to
a csv with the latitude and longitude of each metro station.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7</pre></div></td><td class="code"><div class="highlight"><pre>stations <span class="o"><-</span> read.csv<span class="p">(</span><span class="s">"data/stations.csv"</span><span class="p">)</span> <span class="o">%>%</span>
mutate<span class="p">(</span>name <span class="o">=</span> <span class="kp">tolower</span><span class="p">(</span>name<span class="p">))</span> <span class="o">%>%</span>
rename<span class="p">(</span>line <span class="o">=</span> styleUrl<span class="p">)</span> <span class="o">%>%</span>
mutate<span class="p">(</span>line <span class="o">=</span> str_replace<span class="p">(</span>line<span class="p">,</span> <span class="s">"#Line"</span><span class="p">,</span> <span class="s">"LÍNEA "</span><span class="p">))</span>
df <span class="o"><-</span> full_join<span class="p">(</span>stations<span class="p">,</span> afluencia<span class="p">,</span> by <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span> <span class="s">"line"</span><span class="p">))</span>
<span class="kp">nrow</span><span class="p">(</span>df<span class="p">[</span><span class="kp">is.na</span><span class="p">(</span>df<span class="o">$</span>X<span class="p">)</span> <span class="o">|</span> <span class="kp">is.na</span><span class="p">(</span>df<span class="o">$</span>num<span class="p">),])</span> <span class="o">==</span> <span class="m">0</span>
</pre></div>
</td></tr></table>
<p>To compute the rates by station we are going to draw a 200m buffer
around each station point. Sometimes stations are very close to each
other and we have to be sure to merge them and sum their ridership
numbers if their buffers intersect. This can be done by using Postgresql with the
following <span class="caps">SQL</span> code:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">json_build_object</span><span class="p">(</span>
<span class="s1">'type'</span><span class="p">,</span> <span class="s1">'Feature'</span><span class="p">,</span>
<span class="s1">'id'</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span>
<span class="s1">'geometry'</span><span class="p">,</span> <span class="n">ST_Union</span><span class="p">(</span><span class="n">the_geom</span><span class="p">::</span><span class="n">geometry</span><span class="p">),</span>
<span class="s1">'properties'</span><span class="p">,</span> <span class="n">json_build_object</span><span class="p">(</span>
<span class="s1">'name'</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span>
<span class="s1">'num'</span><span class="p">,</span> <span class="k">sum</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="k">FROM</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">ST_Buffer</span><span class="p">(</span><span class="n">the_geom_webmercator</span><span class="p">::</span><span class="n">geometry</span><span class="p">,</span><span class="mi">200</span><span class="p">)</span> <span class="k">as</span> <span class="n">the_geom</span><span class="p">,</span><span class="n">name</span><span class="p">,</span> <span class="n">line</span><span class="p">,</span> <span class="n">num</span>
<span class="k">FROM</span> <span class="n">geocoded_stations</span><span class="p">)</span> <span class="k">as</span> <span class="n">buffers</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">name</span>
</pre></div>
</td></tr></table>
<p>I’ve also uploaded the station points to <a href="http://www.carto.com">carto</a> so you
don’t have to install Postgresql and can download the geojson file of the station
buffers by running the <span class="caps">SQL</span> in the cloud.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre>url <span class="o"><-</span> str_c<span class="p">(</span><span class="s">"https://diegovalle.carto.com/api/v2/sql?format=GeoJSON&q="</span><span class="p">,</span>
URLencode<span class="p">(</span><span class="s">"SELECT ST_Transform(ST_Union(the_geom),4326) as the_geom, name, sum(num)</span>
<span class="s">from (SELECT ST_Buffer(the_geom_webmercator,200) as the_geom,name, line, num</span>
<span class="s"> from geocoded_stations) as buffers</span>
<span class="s">GROUP BY name"</span><span class="p">))</span>
stations_merged <span class="o"><-</span> geojson_read<span class="p">(</span><span class="kp">url</span><span class="p">,</span> method <span class="o">=</span> <span class="s">"local"</span><span class="p">,</span> what <span class="o">=</span> <span class="s">"sp"</span><span class="p">)</span>
plot<span class="p">(</span>stations_merged<span class="p">,</span> main <span class="o">=</span> <span class="s">"Metro stations with a 200m buffer"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-12-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-12-1.png"/>
</a></p>
<p>Note the merged stations. Now its just a matter of counting the number
of crimes inside each of the polygons taking into account the stations
that were merged.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre><span class="k">SELECT</span> <span class="k">count</span><span class="p">(</span><span class="n">crime_lat_long</span><span class="p">.</span><span class="n">the_geom</span><span class="p">),</span> <span class="n">stations</span><span class="p">.</span><span class="n">name</span> <span class="k">AS</span> <span class="n">name</span>
<span class="k">FROM</span>
<span class="p">(</span><span class="k">SELECT</span> <span class="n">ST_Transform</span><span class="p">(</span><span class="n">ST_Union</span><span class="p">(</span><span class="n">the_geom</span><span class="p">),</span><span class="mi">4326</span><span class="p">)</span> <span class="k">as</span> <span class="n">the_geom</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="k">sum</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
<span class="k">from</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">ST_Buffer</span><span class="p">(</span><span class="n">the_geom_webmercator</span><span class="p">,</span><span class="mi">200</span><span class="p">)</span> <span class="k">as</span> <span class="n">the_geom</span><span class="p">,</span><span class="n">name</span><span class="p">,</span> <span class="n">line</span><span class="p">,</span> <span class="n">num</span>
<span class="k">from</span> <span class="n">geocoded_stations</span><span class="p">)</span> <span class="k">as</span> <span class="n">buffers</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">name</span><span class="p">)</span> <span class="k">as</span> <span class="n">stations</span>
<span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">crime_lat_long</span>
<span class="k">ON</span> <span class="n">st_contains</span><span class="p">(</span><span class="n">stations</span><span class="p">.</span><span class="n">the_geom</span><span class="p">,</span> <span class="n">crime_lat_long</span><span class="p">.</span><span class="n">the_geom</span><span class="p">)</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">stations</span><span class="p">.</span><span class="n">name</span>
</pre></div>
</td></tr></table>
<p>Using carto:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16</pre></div></td><td class="code"><div class="highlight"><pre>url <span class="o"><-</span> str_c<span class="p">(</span><span class="s">"https://diegovalle.carto.com/api/v2/sql?q="</span><span class="p">,</span>
URLencode<span class="p">(</span><span class="s">"SELECT count(crime_lat_long.the_geom), stations.name AS name</span>
<span class="s">FROM</span>
<span class="s">(SELECT ST_Transform(ST_Union(the_geom),4326) as the_geom, name, sum(num)</span>
<span class="s">from (SELECT ST_Buffer(the_geom_webmercator,200) as the_geom,name, line, num</span>
<span class="s"> from geocoded_stations) as buffers</span>
<span class="s">GROUP BY name) as stations LEFT JOIN</span>
<span class="s">crime_lat_long</span>
<span class="s">ON st_contains(stations.the_geom, crime_lat_long.the_geom)</span>
<span class="s">GROUP BY stations.name"</span><span class="p">))</span>
numcrime <span class="o"><-</span>fromJSON<span class="p">(</span><span class="kp">url</span><span class="p">)</span><span class="o">$</span>rows
stations_merged<span class="o">@</span>data <span class="o"><-</span> left_join<span class="p">(</span>stations_merged<span class="o">@</span>data<span class="p">,</span>
numcrime<span class="p">,</span>
by <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="s">"name"</span> <span class="o">=</span> <span class="s">"name"</span><span class="p">))</span>
</pre></div>
</td></tr></table>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31</pre></div></td><td class="code"><div class="highlight"><pre>stations_merged<span class="o">@</span>data<span class="o">$</span>rate <span class="o"><-</span> stations_merged<span class="o">@</span>data<span class="o">$</span>count <span class="o">/</span> stations_merged<span class="o">@</span>data<span class="o">$</span>sum <span class="o">*</span> <span class="m">10</span><span class="o">^</span><span class="m">5</span>
<span class="c1"># Exclude stations not inside CDMX (crime data only available in CDMX)</span>
stations_merged <span class="o"><-</span> stations_merged<span class="p">[</span><span class="o">!</span>stations_merged<span class="o">@</span>data<span class="o">$</span>name <span class="o">%in%</span> <span class="kt">c</span><span class="p">(</span><span class="s">"los reyes"</span><span class="p">,</span>
<span class="s">"la paz"</span><span class="p">,</span>
<span class="s">"nezahualcóyotl"</span><span class="p">,</span>
<span class="s">"impulsora"</span><span class="p">,</span>
<span class="s">"río de los remedios"</span><span class="p">,</span>
<span class="s">"múzquiz"</span><span class="p">,</span>
<span class="s">"tecnológico"</span><span class="p">,</span>
<span class="s">"olímpica"</span><span class="p">,</span>
<span class="s">"plaza aragón"</span><span class="p">,</span>
<span class="s">"ciudad azteca"</span><span class="p">,</span>
<span class="s">"cuatro caminos"</span><span class="p">),</span> <span class="p">]</span>
<span class="c1"># Write a geojson file for the interactive html version</span>
writeOGR<span class="p">(</span>stations_merged<span class="p">,</span>
<span class="s">"html/stations.geojson"</span><span class="p">,</span>
driver <span class="o">=</span> <span class="s">"GeoJSON"</span><span class="p">,</span>
layer <span class="o">=</span> <span class="s">"stations.geojson"</span><span class="p">,</span>
verbose <span class="o">=</span> <span class="kc">FALSE</span><span class="p">)</span>
map <span class="o"><-</span> fortify<span class="p">(</span>stations_merged<span class="p">,</span> region <span class="o">=</span> <span class="s">"name"</span><span class="p">)</span>
map <span class="o"><-</span> left_join<span class="p">(</span>map<span class="p">,</span> stations_merged<span class="o">@</span>data<span class="p">,</span>by <span class="o">=</span> <span class="kt">c</span><span class="p">(</span><span class="s">"id"</span> <span class="o">=</span> <span class="s">"name"</span><span class="p">))</span>
bb <span class="o"><-</span> bbox<span class="p">(</span>stations_merged<span class="p">)</span>
ggmap<span class="p">(</span>get_map<span class="p">(</span>location <span class="o">=</span> bb<span class="p">))</span> <span class="o">+</span>
geom_polygon<span class="p">(</span>data<span class="o">=</span> <span class="kp">subset</span><span class="p">(</span>map<span class="p">,</span> rate <span class="o">!=</span> <span class="m">0</span><span class="p">),</span>
aes<span class="p">(</span>long<span class="p">,</span> lat<span class="p">,</span> group <span class="o">=</span> group<span class="p">,</span> fill <span class="o">=</span> rate<span class="p">))</span> <span class="o">+</span>
scale_fill_continuous<span class="p">(</span>low <span class="o">=</span> <span class="s">"#ffeda0"</span><span class="p">,</span> high <span class="o">=</span> <span class="s">"#f03b20"</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span>title<span class="p">)</span> <span class="o">+</span>
theme_nothing<span class="p">(</span>legend <span class="o">=</span> <span class="kc">TRUE</span><span class="p">)</span> <span class="o">+</span>
ggtitle<span class="p">(</span><span class="s">"Crime by Mexico City Metro Station"</span><span class="p">)</span>
</pre></div>
</td></tr></table>
<p><a href="/images/posts/crime-maps-of-mexico-city/unnamed-chunk-13-1.png">
<img alt="" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/unnamed-chunk-13-1.png"/>
</a></p>
<p>And there you have it, a chart with the crime rates by metro
station. There’s still a problem in that the crimes may be
systematically biased since the reporting rate is so low in Mexico
(93% according to the <span class="caps">ENVIPE</span> 2016).</p>
<p>You can also view an interactive version <a href="https://www.diegovalle.net/maps/metro/">here</a></p>
<p><a href="https://www.diegovalle.net/maps/metro/">
<img alt="Interactive crime map by metro station" class="image-process-article-image" src="/images/posts/crime-maps-of-mexico-city/derivatives/article-image/metro.png"/>
</a></p>
<p><span class="caps">P.S.</span> You can download the code from <a href="https://github.com/diegovalle/mxc.crime.maps">GitHub</a></p>Real-time air pollution data for Mexico City2016-05-03T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2016-05-03:2016/05/hoyo-de-smog.html<p><a href="https://hoyodesmog.diegovalle.net">
<img alt="Missing stations" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/idw-smog.png"/>
</a></p>
<p>Aside from having the most ridiculous possible name the state of
Mexico City has battled with air pollution for
decades. Since the official
<a href="http://www.aire.df.gob.mx/default.php">air quality website</a> looks
pretty bad, I decided to create my very own website,
<a href="https://hoyodesmog.diegovalle.net">HoyoDeSmog</a>, that is updated in
real-time every hour. To power the site I’ve also created an
<a href="https://hoyodesmog.diegovalle.net/aire.zmvm/">R package</a>.</p>
<p>The pollutants with the highest reported values are usually ozone and
<span class="caps">PM10</span> (particulate matter). Because of the high temperatures and lack of
rain May is usually the worst month of the year for ozone air pollution:</p>
<p><a href="/images/posts/hoyodesmog/tufte_o3.png">
<img alt="Ozone pollution values" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/tufte_o3.png"/>
</a></p>
<p>The peak hours for ozone pollution are in the early afternoon and for
<span class="caps">PM10</span> coincide with commuting times. Though for <span class="caps">PM10</span>
pollution a 24 hour average is what is used to quantify air quality.</p>
<p><a href="/images/posts/hoyodesmog/peak_hours.png"> <img alt="Ozone pollution
values" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/peak_hours.png"/> </a></p>
<p>Mexico City has a no circulation rule, cars which do not meet emission
standards are forbidden from being driven one day a week. A 0-500
scale is used to inform residents of the Mexico City metro area about
pollution values. If pollution values reach 151 points (from April
until June, otherwise it’s 191) a double no ciruclation rule is put
into effect which should forbid about 40% of cars from the streets.</p>
<p>Ozone is usually the pollutant with the highest values and for which
environmental contingencies are declared, so there is a <a href="https://hoyodesmog.diegovalle.net/ozone.html">whole a page</a>
to view the latest values:</p>
<p><a href="https://hoyodesmog.diegovalle.net/ozone.html">
<img alt="Ozone" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/ozone.png"/>
</a></p>
<p>You can also view <a href="https://hoyodesmog.diegovalle.net/temperature.html">temparature</a> values (interpolated by inverse distance
weigthing from the measuring station):</p>
<p><a href="https://hoyodesmog.diegovalle.net/temperature.html">
<img alt="Temp" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/temp.png"/>
</a></p>
<p>And an animated map of <a href="https://hoyodesmog.diegovalle.net/wind.html">wind speed and direction</a>:</p>
<video controls="" height="546" width="528">
<source src="/images/posts/hoyodesmog/wind.mp4" type="video/mp4">
Your browser does not support the video tag.
</source></video>
<h3>Problems with the data</h3>
<p>Like I said, the official website sucks, and one of the problems with
it was that some of the stations, like <span class="caps">MPA</span>, were missing from the
<a href="http://www.aire.df.gob.mx/estadisticas-consultas/concentraciones/index.php">webpage</a>
where you could download data. In this old screenshot you can clearly see
that there was no station named <span class="caps">MPA</span>:</p>
<p><a href="/images/posts/hoyodesmog/estaciones_old.png">
<img alt="Missing stations" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/estaciones_old.png"/>
</a></p>
<p>I reported the problem and the website now includes the missing stations:</p>
<p><a href="/images/posts/hoyodesmog/estaciones_new.png">
<img alt="Including missing stations" class="image-process-article-image" src="/images/posts/hoyodesmog/derivatives/article-image/estaciones_new.png"/>
</a></p>
<p>Sadly, in fixing the problem they broke the querying system and now
you can’t download data from before 2015 (
<a href="http://www.aire.df.gob.mx/estadisticas-consultas/concentraciones/index.php">try it here</a>
). My R package doesn’t have this problem.</p>
<p>Some stations were also missing from the list available for
<a href="http://148.243.232.112:8080/opendata/catalogos/cat_estacion.csv">download</a>
from the website. I added them manually by using Google Maps.</p>
<p>In addition to all this, when you download pollution data there is a station
called <span class="caps">CHA</span>, but in the
<a href="http://www.aire.df.gob.mx/ultima-hora-reporte.php">hourly report</a> it
is instead called <span class="caps">MON</span> (Texcoco). In the R package I always use the station
code <span class="caps">MON</span>. Of course now I’m afraid to report all these problems in case the
state of Mexico City government screws up the website even more.</p>
<h3>Problems with conversions</h3>
<p>As I mentioned the government uses a 0-500 scale in <span class="caps">IMECAS</span> to
communicate to public how polluted the air currently is. To convert to
<span class="caps">IMECAS</span> from the original units in which the pollutants are measured
the government uses stepwise functions, but I’m unable to replicate
the values you are supposed to get using the official formulas and websites.</p>
<p>For example, when I try convert an <span class="caps">NO</span><sub>2</sub> value of .150 ppm to <span class="caps">IMECAS</span>
using the formula I get a value of 72</p>
<p>I[<span class="caps">NO2</span>]=1.587+C[<span class="caps">NO2</span>]*49/0.104</p>
<p>but 71 if I use the html form on this
<a href="http://rama.edomex.gob.mx/contaminacion-atmosferica/imeca">website</a></p>
<p>There is also an issue where you have to use the 24 hour average to
calculate <span class="caps">IMECA</span> values (as with <span class="caps">PM10</span>) and it is not document what
happens when there are missing values (it’s not listwise deletion).</p>
<p>All this means that except for the frontpage map all values are reported in the
original units (ppb, µg/m³, etc) in which pollutants are measured.</p>
<p><span class="caps">P.S.</span> The R package is available from <a href="https://github.com/diegovalle/aire.zmvm">GitHub</a></p>Shapefiles from the 2015 Population Survey2016-01-27T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2016-01-27:2016/01/encuesta-intercensal-2015-shapefiles.html<p><a href="/images/posts/population-survey-shapefiles/df-streets.jpg">
<img alt="Streets and Services in the DF" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/df-streets.jpg"/>
</a></p>
<p>The <span class="caps">INEGI</span> just published the results of the latest <a href="http://www.inegi.org.mx/est/contenidos/proyectos/encuestas/hogares/especiales/ei2015/default.aspx">population survey</a>
along with updated shapefiles to reflect the changes to the
Mexican population. At the end of this post you’ll find a script to
download the updated manzanas (blocks), urban AGEBs, rural AGEBs, municipios,
streets (ejes viales), states, services, and localities
(localidades). It’s <span class="caps">7GB</span> of the latest shapefiles available for free!</p>
<p>If you don’t know how to run the script or prefer to simply
download the data, you can subscribe to my newsletter (one email per post) and you’ll
get the shapefile download links directly in your inbox as a bonus.
<br/>
</p><div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden;
text-align: left;">
<div class="form-top-left" style="float: left;
width: 75%;
padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;">Subscribe to my <span class="free" style="color: #C7B720;">free</span> newsletter</h3>
<br/>
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers to my newsletter from Harvard, Stanford, Google, McKinsey, and many more, you’ll receive as a welcome gift the 100+ shapefiles described in this post (It’s more than <span class="caps"><span class="caps">7GB</span></span> of data and totally free)</b></p>
<p></p><ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Shapefiles of Manzanas, AGEBs, Municipios, Estados, and more
</li>
<li>
The latest shapefiles from the 2020 Census
</li>
<li>Includes historical shapefiles from 2010 census</li>
<li><a href="https://www.diegovalle.net/privacy/">Privacy policy</a></li>
<li>Unsubscribe at any time</li>
<p></p></ul><p></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left;
width: 25%;
padding-top: 5px;
font-size: 66px;
color: #fff;
line-height: 100px;
text-align: right;
opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form action="https://www.diegovalle.net/api/newsletter" class="registration-form" id="Newsletter" method="post" novalidate="novalidate" role="form">
<!-- <div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="form-first-name">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name">
</div> -->
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100;
font-size: 90%;">Where should I send the newsletter and shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Email</label>
<input aria-required="true" class="form-email form-control" id="email" name="email" placeholder="Email..." required="" type="email"/>
</div>
<div style="position: absolute; left: -5000px;"><input name="website" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" tabindex="-1" type="text" value="fatcatseat2much"/>
<input name="referrer" tabindex="-1" type="text" value="2015shapefiles"/>
</div>
<input class="hiddenRecaptcha_post required" id="hiddenRecaptcha_post" name="hiddenRecaptcha_post" type="hidden"/>
<div class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd" id="recaptcha_post"></div><br/>
<button class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" type="submit">Get your free newsletter</button>
</form>
</div>
</div>
<br/>
<p><a href="/images/posts/population-survey-shapefiles/muns.png">
<img alt="States and municipios of Mexico" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/muns.png"/>
</a></p>
<p>The script creates a directory for each of the 32 states and
Federal District where you’ll find all the shapefiles.</p>
<table>
<thead>
<tr>
<th>File</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>entidad</td>
<td>Entidad (states)</td>
</tr>
<tr>
<td>municipio</td>
<td>Municipio (counties)</td>
</tr>
<tr>
<td>localidad_urbana_y_rural_amanzanada</td>
<td>Localidad Urbana y Rural Amanzanada</td>
</tr>
<tr>
<td>localidad_rural_no_amanzanada</td>
<td>Localidad Rural</td>
</tr>
<tr>
<td>ageb_urbana</td>
<td>Área Geoestadística Básica (<span class="caps">AGEB</span>) [census tracts]</td>
</tr>
<tr>
<td>ageb_rural</td>
<td>Área Geoestadística Básica Rural (<span class="caps">AGEB</span>) [census tracts]</td>
</tr>
<tr>
<td>manzana</td>
<td>Polígonos de Manzanas (census blocks)</td>
</tr>
<tr>
<td>frentes_de_manazana</td>
<td>Frentes de Manzana (census blocks)</td>
</tr>
<tr>
<td>eje_vial</td>
<td>Ejes de vialidad (streets)</td>
</tr>
<tr>
<td>servicios_area</td>
<td>Servicios con Información complementaria de tipo Área (Áreas Verdes, Camellones, glorietas)</td>
</tr>
<tr>
<td>servicios_linea</td>
<td>Servicios con Información complementaria de tipo Línea (Ríos, Ferrocarriles)</td>
</tr>
<tr>
<td>servicios_puntual</td>
<td>Servicios con Información complementaria de tipo Puntual (Palacios Municipales o Ayudantías, Parques o Jardines)</td>
</tr>
<tr>
<td>territorio_insular</td>
<td>Territorio Insular (insular territory)</td>
</tr>
</tbody>
</table>
<p>The shapefiles didn’t change much from 2010 to 2015, but there were a few changes. Here’s and example of new services in Cancún (new ones are yellow):</p>
<p><a href="/images/posts/population-survey-shapefiles/cancun.jpg">
<img alt="Cancún" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/cancun.jpg"/>
</a></p>
<p><small></small></p>
<p>Like I said, there weren’t that many changes. Urban and rural AGEBs in Jalisco:</p>
<p><a href="/images/posts/population-survey-shapefiles/jal.jpg">
<img alt="Jalisco" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/jal.jpg"/>
</a></p>
<p>Urban AGEBs and roads in Baja California:</p>
<p><a href="/images/posts/population-survey-shapefiles/bc.jpg">
<img alt="Baja California AGEB" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/bc.jpg"/>
</a></p>
<p>Manzanas (blocks) in Morelos:</p>
<p><a href="/images/posts/population-survey-shapefiles/mor.jpg">
<img alt="Morelos" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/mor.jpg"/>
</a></p>
<p>Roads, localidades, rural and urban AGEBs in Acapulco:</p>
<p><a href="/images/posts/population-survey-shapefiles/gro.jpg">
<img alt="Acapulco" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/gro.jpg"/>
</a></p>
<p>Since the shapefiles are divided by state, you can use the bash code
below to merge all the individual state shapefiles into one big
national file.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#! /bin/bash</span>
<span class="c"># The filename of the merged file</span>
<span class="nv">FILEOUT</span><span class="o">=</span><span class="s2">"municipio.shp"</span>
<span class="c"># The names of the files to merge, you can change this to</span>
<span class="c"># "*entidad.shp" or "*eje_vial.shp", etc</span>
<span class="nv">TYPE</span><span class="o">=</span><span class="s2">"*municipio.shp"</span>
<span class="k">for</span> i in <span class="k">$(</span>find . -maxdepth <span class="m">3</span> -name <span class="nv">$TYPE</span><span class="k">)</span>
<span class="k">do</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$FILEOUT</span><span class="s2">"</span> <span class="o">]</span>
<span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"adding state </span><span class="nv">$i</span><span class="s2"> to </span><span class="nv">$FILEOUT</span><span class="s2">"</span>
ogr2ogr -f <span class="s1">'ESRI Shapefile'</span> -update -append <span class="nv">$FILEOUT</span> <span class="nv">$i</span> -nln <span class="k">$(</span>basename -s .shp <span class="nv">$FILEOUT</span><span class="k">)</span>
<span class="k">else</span>
<span class="nb">echo</span> <span class="s2">"startin merge..."</span>
<span class="nb">echo</span> <span class="s2">"adding state </span><span class="nv">$i</span><span class="s2"> to </span><span class="nv">$FILEOUT</span><span class="s2">"</span>
ogr2ogr -f <span class="s1">'ESRI Shapefile'</span> <span class="nv">$FILEOUT</span> <span class="nv">$i</span>
<span class="k">fi</span>
<span class="k">done</span>
</pre></div>
</td></tr></table>
<p>All shapefiles come from the <span class="caps">INEGI</span>’s “Cartografía Geoestadística
Urbana y Rural Amanzanada. Cierre de la Encuesta Intercensal 2015.”
Here’s the code to download them:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#! /bin/bash</span>
<span class="c"># Author: Diego Valle-Jones</span>
<span class="c"># Web: https://www.diegovalle.net</span>
<span class="c"># LICENSE: Apache 2.0</span>
<span class="c"># Purpose: Download shapefiles of manzanas (blocks), agebs (census areas), ejes</span>
<span class="c"># viales (streets), interesting areas and a whole bunch of other stuff from</span>
<span class="c"># the Encuesta Intercensal 2015</span>
<span class="c"># As of now, this script has not been tested on Windows,</span>
<span class="c"># only on Ubuntu and Macs. The script will create a directory</span>
<span class="c"># called 'shps' where all the shapefiles are located, if something</span>
<span class="c"># goes wrong when dowloading be sure to delete it and try again</span>
<span class="c">#Exit on error</span>
<span class="nb">set</span> -e
<span class="c"># Projection compatible with Google Maps</span>
<span class="nv">PROJECTION</span><span class="o">=</span><span class="s2">"+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"</span>
<span class="c"># wget command</span>
<span class="nv">CURL</span><span class="o">=</span><span class="s2">"curl"</span>
<span class="c">#The way the INEGI download url starts</span>
<span class="nv">URL</span><span class="o">=</span><span class="s2">"http://internet.contenidos.inegi.org.mx/contenidos/productos//prod_serv/contenidos/espanol/bvinegi/productos/geografia/Cinter_2015/"</span>
<span class="c">#File ends in</span>
<span class="nv">SUFFIX</span><span class="o">=</span><span class="s2">"_s.zip"</span>
<span class="c">#States as numbers</span>
<span class="c">#I have no idea why the INEGI used these numbers to represent the states</span>
<span class="nb">declare</span> -a <span class="nv">states_numbers</span><span class="o">=(</span><span class="s2">"702825209025"</span> <span class="s2">"702825209032"</span> <span class="s2">"702825209049"</span> <span class="s2">"702825209056"</span> <span class="s2">"702825209087"</span> <span class="s2">"702825209094"</span> <span class="s2">"702825209063"</span> <span class="s2">"702825209070"</span> <span class="s2">"702825209100"</span> <span class="s2">"702825209117"</span> <span class="s2">"702825209124"</span> <span class="s2">"702825209131"</span> <span class="s2">"702825209148"</span> <span class="s2">"702825209155"</span> <span class="s2">"702825209162"</span> <span class="s2">"702825209179"</span> <span class="s2">"702825209186"</span> <span class="s2">"702825209193"</span> <span class="s2">"702825209209"</span> <span class="s2">"702825209216"</span> <span class="s2">"702825209223"</span> <span class="s2">"702825209230"</span> <span class="s2">"702825209247"</span> <span class="s2">"702825209254"</span> <span class="s2">"702825209261"</span> <span class="s2">"702825209278"</span> <span class="s2">"702825209285"</span> <span class="s2">"702825209292"</span> <span class="s2">"702825209308"</span> <span class="s2">"702825209315"</span> <span class="s2">"702825209322"</span> <span class="s2">"702825209339"</span><span class="o">)</span>
<span class="c">#State names in the URL</span>
<span class="nb">declare</span> -a <span class="nv">state_names</span><span class="o">=(</span><span class="s2">"Aguascalientes"</span> <span class="s2">"Baja_California"</span> <span class="s2">"Baja_California_Sur"</span> <span class="s2">"Campeche"</span> <span class="s2">"Coahuila_de_Zaragoza"</span> <span class="s2">"Colima"</span> <span class="s2">"Chiapas"</span> <span class="s2">"Chihuahua"</span> <span class="s2">"Distrito_Federal"</span> <span class="s2">"Durango"</span> <span class="s2">"Guanajuato"</span> <span class="s2">"Guerrero"</span> <span class="s2">"Hidalgo"</span> <span class="s2">"Jalisco"</span> <span class="s2">"Mexico"</span> <span class="s2">"Michoacan_de_Ocampo"</span> <span class="s2">"Morelos"</span> <span class="s2">"Nayarit"</span> <span class="s2">"Nuevo_Leon"</span> <span class="s2">"Oaxaca"</span> <span class="s2">"Puebla"</span> <span class="s2">"Queretaro"</span> <span class="s2">"Quintana_Roo"</span> <span class="s2">"San_Luis_Potosi"</span> <span class="s2">"Sinaloa"</span> <span class="s2">"Sonora"</span> <span class="s2">"Tabasco"</span> <span class="s2">"Tamaulipas"</span> <span class="s2">"Tlaxcala"</span> <span class="s2">"Veracruz_de_Ignacio_de_la_Llave"</span> <span class="s2">"Yucatan"</span> <span class="s2">"Zacatecas"</span> <span class="o">)</span>
<span class="c"># The list of shapefiles of manzanas, agebs, etc</span>
<span class="nb">declare</span> -a <span class="nv">files</span><span class="o">=(</span><span class="s2">"ar.shp"</span> <span class="s2">"ent.shp"</span> <span class="s2">"lpr.shp"</span> <span class="s2">"m.shp"</span> <span class="s2">"fm.shp"</span> <span class="s2">"sia.shp"</span> <span class="s2">"sip.shp"</span>
<span class="s2">"a.shp"</span> <span class="s2">"e.shp"</span> <span class="s2">"l.shp"</span> <span class="s2">"mun.shp"</span> <span class="s2">"sil.shp"</span> <span class="s2">"territorioinsular.shp"</span><span class="o">)</span><span class="p">;</span>
<span class="c">#The INEGI filenames are unreadable</span>
<span class="nb">declare</span> -a <span class="nv">files_nice</span><span class="o">=(</span><span class="s2">"ageb_rural.shp"</span> <span class="s2">"entidad.shp"</span> <span class="s2">"localidad_rural_no_amanzanada.shp"</span> <span class="s2">"manzana.shp"</span> <span class="s2">"frente_de_manzana.shp"</span> <span class="s2">"servicios_area.shp"</span> <span class="s2">"servicios_puntual.shp"</span>
<span class="s2">"ageb_urbana.shp"</span> <span class="s2">"eje_vial.shp"</span> <span class="s2">"localidad_urbana_y_rural_amanzanada.shp"</span> <span class="s2">"municipio.shp"</span> <span class="s2">"servicios_linea.shp"</span> <span class="s2">"territorio_insular.shp"</span><span class="o">)</span><span class="p">;</span>
<span class="c"># State abbreviations</span>
<span class="nb">declare</span> -a <span class="nv">states</span><span class="o">=(</span><span class="s2">"ags"</span> <span class="s2">"bc"</span> <span class="s2">"bcs"</span> <span class="s2">"camp"</span> <span class="s2">"coah"</span> <span class="s2">"col"</span> <span class="s2">"chis"</span> <span class="s2">"chih"</span>
<span class="s2">"df"</span> <span class="s2">"dgo"</span> <span class="s2">"gto"</span> <span class="s2">"gro"</span> <span class="s2">"hgo"</span> <span class="s2">"jal"</span> <span class="s2">"mex"</span> <span class="s2">"mich"</span> <span class="s2">"mor"</span> <span class="s2">"nay"</span> <span class="s2">"nl"</span> <span class="s2">"oax"</span>
<span class="s2">"pue"</span> <span class="s2">"qro"</span> <span class="s2">"qroo"</span> <span class="s2">"slp"</span> <span class="s2">"sin"</span> <span class="s2">"son"</span> <span class="s2">"tab"</span> <span class="s2">"tamps"</span> <span class="s2">"tlax"</span> <span class="s2">"ver"</span> <span class="s2">"yuc"</span>
<span class="s2">"zac"</span><span class="o">)</span><span class="p">;</span>
<span class="nb">declare</span> -a <span class="nv">state_num</span><span class="o">=(</span><span class="sb">`</span>seq -s <span class="s2">" "</span> -w <span class="m">1</span> 32<span class="sb">`</span><span class="o">)</span><span class="p">;</span>
<span class="c"># Use gdal to reproject, and then rename the shapefiles to include</span>
<span class="c"># a user friendly abbreviation instead of a number</span>
<span class="c"># First argument: directory of shapefiles shps/state_abbreviation</span>
<span class="c"># Second argument: the state abbreviation</span>
<span class="c"># Third argument: the shapefiles inside the zip file as an array</span>
<span class="c"># Fourth argument: the state number</span>
<span class="c"># TODO: convert the encoding from windows-1252 to utf-8</span>
<span class="k">function</span> reproject <span class="o">{</span>
<span class="nv">name</span><span class="o">=</span><span class="nv">$3</span><span class="o">[</span>@<span class="o">]</span>
<span class="nv">arr</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="p">!name</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
<span class="nv">len</span><span class="o">=</span><span class="sb">`</span>expr <span class="si">${#</span><span class="nv">files</span><span class="p">[*]</span><span class="si">}</span> - 1<span class="sb">`</span>
<span class="c"># Has to match he number of files in the array</span>
<span class="k">for</span> i in <span class="sb">`</span>seq <span class="m">0</span> <span class="nv">$len</span><span class="sb">`</span>
<span class="k">do</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="nv">$1</span>/conjunto_de_datos/<span class="nv">$4</span><span class="si">${</span><span class="nv">files</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> <span class="o">]</span><span class="p">;</span>
<span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"Creating... "</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span>
ogr2ogr <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> <span class="nv">$1</span>/conjunto_de_datos/<span class="nv">$4</span><span class="si">${</span><span class="nv">files</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> -t_srs <span class="s2">"</span><span class="nv">$PROJECTION</span><span class="s2">"</span>
<span class="k">else</span>
<span class="nb">echo</span> <span class="s2">"No territorio insular in "</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span>
<span class="k">fi</span>
<span class="k">done</span>
rm -rf <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/conjunto_de_datos
<span class="o">}</span>
<span class="nv">counter</span><span class="o">=</span>0
<span class="k">for</span> state_number in <span class="s2">"</span><span class="si">${</span><span class="nv">states_numbers</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span>
<span class="k">do</span>
<span class="nv">FILENAME</span><span class="o">=</span><span class="s2">"</span><span class="nv">$URL</span><span class="si">${</span><span class="nv">state_names</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span><span class="s2">/</span><span class="nv">$state_number$SUFFIX</span><span class="s2">"</span>
<span class="c"># download the files from the inegi server.</span>
<span class="nv">$CURL</span> <span class="nv">$FILENAME</span> -o <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>.zip
<span class="c"># Extract the shapefiles from the zip file</span>
mkdir -p shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
unzip -o -L <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>.zip -d shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
reproject shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span> <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span> files <span class="si">${</span><span class="nv">state_num</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
<span class="nv">counter</span><span class="o">=</span><span class="sb">`</span>expr <span class="nv">$counter</span> + 1<span class="sb">`</span>
<span class="k">done</span>
<span class="c"># Delete the downloaded zip files</span>
rm -rf *.zip
<span class="c"># You could use the code below to merge all the states into one giant</span>
<span class="c"># shapefile of Mexico. Change "*localidad_urbana.shp" to</span>
<span class="c"># '*ageb_urbana.shp' or '*eje_vial.shp' or whatever</span>
<span class="c">#</span>
<span class="c"># FILEOUT="municipio.shp"</span>
<span class="c"># TYPE="*municipio.shp"</span>
<span class="c"># for i in $(find . -maxdepth 3 -name $TYPE)</span>
<span class="c"># do</span>
<span class="c"># if [ -f "$FILEOUT" ]</span>
<span class="c"># then</span>
<span class="c"># echo "adding state $i to $FILEOUT"</span>
<span class="c"># ogr2ogr -f 'ESRI Shapefile' -update -append $FILEOUT $i -nln $(basename -s .shp $FILEOUT)</span>
<span class="c"># else</span>
<span class="c"># echo "startin merge..."</span>
<span class="c"># echo "adding state $i to $FILEOUT"</span>
<span class="c"># ogr2ogr -f 'ESRI Shapefile' $FILEOUT $i</span>
<span class="c"># fi</span>
<span class="c"># done</span>
</pre></div>
</td></tr></table>
<p><strong><span class="caps">P.S.</span></strong> The frente de manzana shapefile for Sonora contains an error
in its attribute table, hopefully the <span class="caps">INEGI</span> will fix it in a future version.</p>
<p><strong><span class="caps">P.P.S.</span></strong> Unlike the
<a href="https://blog.diegovalle.net/2013/06/shapefiles-of-mexico-agebs-manzanas-etc.html">2010 census shapefiles</a>,
these ones don’t contain demographic variables. (the Encuesta
Intercensal is valid for all municipios and the localidades with more
than 50,000 people)</p>Mexico’s Black Population2016-01-05T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2016-01-05:2016/01/afro-mexicans.html<p>The 2015 population survey marked the first time since the 19<sup>th</sup>
century that the Mexican government included a distinct category for
people of Afro-Mexican descent. As of 2015, the <span class="caps">INEGI</span> found that
1,973,555 persons or 1.7% of the population self-identified as
Afro-Mexican or partially Afro-Mexican (1.2% of the population
excluding people who self-identified as only partially Afro-Mexican).</p>
<p><a href="https://www.diegovalle.net/maps/afromexicanos/afromexicanos.html"> <img alt="Afro-Mexican population in Mexico" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/afromexicanos.png"/> </a><br/>
<small><a href="https://www.diegovalle.net/maps/afromexicanos/afromexicanos.html">Click</a> to visit the interactive version</small></p>
<p>A map of the percentage of the population that self-identifies as
Afro-Mexican at the municipio level shows that they tend to live in
the Costa Chica of Guerrero and Oaxaca, and the state of
Veracruz. This is no surprise since the isolated mountainous
geography of the Costa Chica served to keep Afro-Mexican communities
separate from the rest of Mexico.</p>
<p><a href="https://www.diegovalle.net/maps/terrain/costa-chica.html">
<img alt="3D terrain of the Costa Chica de Guerrero and Oaxaca" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/costa_chica.html.png"/>
</a><br/>
<small><a href="https://www.diegovalle.net/maps/terrain/costa-chica.html">Click</a> to visit the interactive version</small></p>
<p>This 3D terrain map of the Costa Chica from Acapulco to Huatulco zooms
in on the area with the highest percentage of Afro-Mexicans and shows
how it is surrounded by mountains. The prevailing theory of how
Afro-Mexicans arrived in the Costa Chica is that escaped slaves
brought by Spanish galleons settled here, and found freedom and refuge
thanks to the area’s isolation.</p>
<p>One problem with using self-identification to determine ethnic origin
—as the population survey did— is that there have now been many
genetic studies of Mexican populations and a robust finding is that the
vast majority of Mexicans are part Black. Here’s an image of several
individuals from different Mexican states taken from
<em><a href="http://www.sciencemag.org/content/344/6189/1280.full">The genetics of Mexico recapitulates Native American substructure and affects biomedical traits</a></em></p>
<p><a href="/images/posts/afro-mexicans/admixture-states.png">
<img alt="Admixture in selected Mexican states" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/admixture-states.png"/> </a></p>
<p>The red bars represent European ancestry, the green bars Sub-Saharan
African (Yoruba), and the blue bars indigenous ancestry. Granted,
genetics is a fast changing field<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup>, but the results shouldn’t change
much, and you can clearly see how just about everyone in Mexico has
some very minor <span class="caps">SSA</span> ancestry, with a low variance, except for the
states of Guerrero, Veracruz and Oaxaca where there were individuals
with high African admixture. Also, note how those individuals have a
high percentage of indigenous ancestry.</p>
<p><a href="/images/posts/afro-mexicans/states_afro.png">
<img alt="Afro-Mexican and partially Afro-Mexican population by state" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/states_afro.png"/>
</a></p>
<p>More than 200,000 slaves were brought to Mexico, compared to 450,000
in the <span class="caps">US</span>, and 4.5 million in Brazil. In the 1742 and 1793 censuses,
the Black and Mulatto population of Mexico came in at about 10%, being
much less numerous than the indigenous and mestizo population, and
with no strictures against intermarriage, with time they were absorbed
into the general Mexican population.</p>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-0ord{text-align:right}
.tg .tg-e3zv{font-weight:bold}
.tg .tg-lqy6{text-align:right;vertical-align:top}
.tg .tg-hgcj{font-weight:bold;text-align:center}
.tg .tg-amwm{font-weight:bold;text-align:center;vertical-align:top}
</style>
<table>
<thead>
<tr>
<th class="tg-031e">Census Year</th>
<th class="tg-hgcj">1570</th>
<th class="tg-hgcj">1646</th>
<th class="tg-amwm">1742</th>
<th class="tg-amwm">1793</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-e3zv">Indians</td>
<td class="tg-0ord">3,336,860 (98.7%)</td>
<td class="tg-0ord">1,269,607 (74.1%)</td>
<td class="tg-lqy6">1,540,256 (62.2%)</td>
<td class="tg-lqy6">2,319,741 (61.1%)</td>
</tr>
<tr>
<td class="tg-e3zv">Europeans</td>
<td class="tg-0ord">6,644 (0.2%)</td>
<td class="tg-0ord">13,780 (0.8%)</td>
<td class="tg-lqy6">9,814 (0.4%)</td>
<td class="tg-lqy6">7,904 (0.2%)</td>
</tr>
<tr>
<td class="tg-e3zv">Mestizos</td>
<td class="tg-0ord">1,3504 (0.4%)</td>
<td class="tg-0ord">277,610 (16.2%)</td>
<td class="tg-lqy6">640,880 (25.9%)</td>
<td class="tg-lqy6">1,096,026 (28.8%)</td>
</tr>
<tr>
<td class="tg-e3zv">Blacks</td>
<td class="tg-0ord">20,569 (0.6%)</td>
<td class="tg-0ord">35,089 (2%)</td>
<td class="tg-lqy6">20,131 (0.8%)</td>
<td class="tg-lqy6">6,100 (0.2%)</td>
</tr>
<tr>
<td class="tg-e3zv">Mulattos</td>
<td class="tg-0ord">2,435 (0.1%)</td>
<td class="tg-0ord">116,529 (6.8%)</td>
<td class="tg-lqy6">266,196 (10.7%)</td>
<td class="tg-lqy6">369,790 (9.7%)</td>
</tr>
</tbody>
</table>
<p><small>Source: The History of Mexico From Pre-Conquest to Present</small></p>
<p>Looking at the table, a big part of the recovery of the Indian
population during the colonial period must have been due to Indian women
having children with Mestizos and Mulattos, and with the forging of Mexico’s mestizo
identity, the ‘afromestizos’ were simply forgotten.</p>
<p>The states with large populations of Afro-Mexicans are also states with
large indigenous populations as the following map shows:</p>
<p><a href="/images/posts/afro-mexicans/indigenous.png">
<img alt="Indigenous population in Mexico" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/indigenous.png"/>
</a></p>
<p>Some Native Mexicans also present <span class="caps">SSA</span> admixture. If you squint really
hard at the <span class="caps">SSA</span> admixture for the Mayan Native Mexicans in the chart
below you can see that they have some African ancestry. In the
<a href="https://books.google.com/books?id=l0L5_lzURQkC&pg=PA93&lpg=PA93&dq=1789+censo+yucatan&source=bl&ots=S2LlMNSAE2&sig=xRktUfdJcG31OUmeYiw5g6toY3A&hl=en&sa=X&redir_esc=y#v=onepage&q=1789%20censo%20yucatan&f=false">1789 census</a>,
12% of the population in Yucatán was Black or Mulatto. And today there
are several municipios in Yucatan that have a high Afro-Mexican or part Afro-Mexican
presence (wether you consider yourself Afro-Mexican or part Afro-Mexican seems to vary somewhat by state): Dzoncauich (17.5%), Mama (5.2%) and Chikindzonot (5.1%).</p>
<p><a href="/images/posts/afro-mexicans/F2.large.jpg">
<img alt="Admixture in Mayas and Cosmopolitan Hipsters" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/F2.large.jpg"/>
</a></p>
<p><small>Source: The genetics of Mexico recapitulates Native American substructure and affects biomedical traits</small></p>
<p>I tried to find a genetic study that focused specifically on
Afro-Mexicans, but I couldn’t find one. My best guess is that one
would find much higher <span class="caps">SSA</span> ancestry among self-identified
Afro-Mexicans, but with a large variance, unlike the rest of Mexico
which consistently shows low variance.</p>
<p>Indigenous and Afro-Mexican are not exclusive categories. People who
consider themselves both Afro-Mexican and indigenous outnumber those
who consider themselves to be solely Afro-Mexican.</p>
<p><a href="/images/posts/afro-mexicans/total_race.png">
<img alt="Total population by ethnic group and combinations" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/total_race.png"/>
</a></p>
<p>This tendency to belong to more than one group could bias some
measurements. If you want to predict literacy in Guerrero and Veracruz
it seems to be more important to be indigenous than to be Afro-Mexican.</p>
<p><a href="/images/posts/afro-mexicans/read_race.png">
<img alt="Literacy rates by ethnic group and combinations" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/read_race.png"/>
</a></p>
<p>In fact, people who consider themselves to be only Afro-Mexican have
the highest literacy rates in Veracruz and second highest in Guerrero,
while in Oaxaca, for some reason, they cluster with the indigenous
population. This certainly merits further research. When comparing
literacy rates to the Mexican average, keep in mind that the three
states with the highest proportion of Afro-Mexicans together with
Chiapas have the lowest rates of literacy in Mexico.</p>
<p>In Brazil and the United States the Black population suffers from
much higher rates of violence, but in Mexico the percentage of the
population that is Black is not correlated with the homicide rate in
Veracruz, is positively correlated in Oaxaca, and the correlation is
actually negative in Guerrero. Though, that is mostly because drug
trafficking routes don’t go through the areas Afro-Mexicans live in
and there has been some spillover of violence into Oaxaca from
Guerrero (Mexico’s <a href="https://elcri.men/en/">most violent</a> state). Even if less violent than the
rest of Guerrero, the Costa Chica region is still
<a href="http://www.excelsior.com.mx/nacional/2015/11/10/1056163">very violent</a>
by any standard.</p>
<p><a href="/images/posts/afro-mexicans/homicides_drugwar.png">
<img alt="Homicide correlations during the drug war" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/homicides_drugwar.png"/>
</a></p>
<p>Before the drug war, there was no correlation between the percentage of
the population that is Afro-Mexican and the homicide rate.</p>
<p><a href="/images/posts/afro-mexicans/homicides_before.png">
<img alt="Homicide correlations before the drug war" class="image-process-article-image" src="/images/posts/afro-mexicans/derivatives/article-image/homicides_before.png"/>
</a></p>
<p><strong>Municipios with the highest percentage of Afro-Mexicans</strong>
<br/>
</p><table class="gmisc_table" style="border-collapse: collapse;">
<thead>
<tr>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">State</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Municipio</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Total Population</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Afro-Mexicans
(totally or partially)</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Percent</th>
<p></p></tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Oaxaca</td>
<td style="text-align: left;">Santiago Tapextla</td>
<td style="text-align: center;">3208</td>
<td style="border-right: 1px solid black; text-align: center;">2756</td>
<td style="text-align: center;">85.9%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Oaxaca</td>
<td style="background-color: #f7f7f7; text-align: left;">Santo Domingo Armenta</td>
<td style="background-color: #f7f7f7; text-align: center;">3469</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">2678</td>
<td style="background-color: #f7f7f7; text-align: center;">77.2%</td>
</tr>
<tr>
<td style="text-align: left;">Oaxaca</td>
<td style="text-align: left;">San Juan Bautista Lo de Soto</td>
<td style="text-align: center;">2593</td>
<td style="border-right: 1px solid black; text-align: center;">1920</td>
<td style="text-align: center;">74%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Guerrero</td>
<td style="background-color: #f7f7f7; text-align: left;">Cuajinicuilapa</td>
<td style="background-color: #f7f7f7; text-align: center;">27266</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">16907</td>
<td style="background-color: #f7f7f7; text-align: center;">62%</td>
</tr>
<tr>
<td style="text-align: left;">Oaxaca</td>
<td style="text-align: left;">Santa María Cortijo</td>
<td style="text-align: center;">1075</td>
<td style="border-right: 1px solid black; text-align: center;">660</td>
<td style="text-align: center;">61.4%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Oaxaca</td>
<td style="background-color: #f7f7f7; text-align: left;">Santiago Llano Grande</td>
<td style="background-color: #f7f7f7; text-align: center;">3284</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">1934</td>
<td style="background-color: #f7f7f7; text-align: center;">58.9%</td>
</tr>
<tr>
<td style="text-align: left;">Oaxaca</td>
<td style="text-align: left;">Santa María Huazolotitlán</td>
<td style="text-align: center;">11400</td>
<td style="border-right: 1px solid black; text-align: center;">6201</td>
<td style="text-align: center;">54.4%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Oaxaca</td>
<td style="background-color: #f7f7f7; text-align: left;">Magdalena Mixtepec</td>
<td style="background-color: #f7f7f7; text-align: center;">1375</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">742</td>
<td style="background-color: #f7f7f7; text-align: center;">54%</td>
</tr>
<tr>
<td style="text-align: left;">Oaxaca</td>
<td style="text-align: left;">Villa de Tututepec de Melchor Ocampo</td>
<td style="text-align: center;">46152</td>
<td style="border-right: 1px solid black; text-align: center;">20669</td>
<td style="text-align: center;">44.8%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: left;">Veracruz de Ignacio de la Llave</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: left;">Xoxocotla</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: center;">5446</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; border-right: 1px solid black; text-align: center;">2312</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: center;">42.5%</td>
</tr>
</tbody>
</table>
<p><strong>Municipios with the largest population of Afro-Mexicans</strong></p>
<table class="gmisc_table" style="border-collapse: collapse;">
<thead>
<tr>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">State</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Municipio</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Total Population</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Afro-Mexicans
(totally or partially)</th>
<th style="border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;">Percent</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Guerrero</td>
<td style="text-align: left;">Acapulco de Juárez</td>
<td style="border-right: 1px solid black; text-align: center;">810669</td>
<td style="text-align: center;">86157</td>
<td style="text-align: center;">10.6%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">México</td>
<td style="background-color: #f7f7f7; text-align: left;">Ecatepec de Morelos</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">1677678</td>
<td style="background-color: #f7f7f7; text-align: center;">37638</td>
<td style="background-color: #f7f7f7; text-align: center;">2.2%</td>
</tr>
<tr>
<td style="text-align: left;">Distrito Federal</td>
<td style="text-align: left;">Iztapalapa</td>
<td style="border-right: 1px solid black; text-align: center;">1827868</td>
<td style="text-align: center;">34239</td>
<td style="text-align: center;">1.9%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Nuevo León</td>
<td style="background-color: #f7f7f7; text-align: left;">General Escobedo</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">425148</td>
<td style="background-color: #f7f7f7; text-align: center;">33849</td>
<td style="background-color: #f7f7f7; text-align: center;">8%</td>
</tr>
<tr>
<td style="text-align: left;">Veracruz de Ignacio de la Llave</td>
<td style="text-align: left;">Veracruz</td>
<td style="border-right: 1px solid black; text-align: center;">609964</td>
<td style="text-align: center;">30688</td>
<td style="text-align: center;">5%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">México</td>
<td style="background-color: #f7f7f7; text-align: left;">Chimalhuacán</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">679811</td>
<td style="background-color: #f7f7f7; text-align: center;">30190</td>
<td style="background-color: #f7f7f7; text-align: center;">4.4%</td>
</tr>
<tr>
<td style="text-align: left;">Jalisco</td>
<td style="text-align: left;">Guadalajara</td>
<td style="border-right: 1px solid black; text-align: center;">1460148</td>
<td style="text-align: center;">26018</td>
<td style="text-align: center;">1.8%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; text-align: left;">Jalisco</td>
<td style="background-color: #f7f7f7; text-align: left;">Zapopan</td>
<td style="background-color: #f7f7f7; border-right: 1px solid black; text-align: center;">1332272</td>
<td style="background-color: #f7f7f7; text-align: center;">22275</td>
<td style="background-color: #f7f7f7; text-align: center;">1.7%</td>
</tr>
<tr>
<td style="text-align: left;">Distrito Federal</td>
<td style="text-align: left;">Coyoacán</td>
<td style="border-right: 1px solid black; text-align: center;">608479</td>
<td style="text-align: center;">21101</td>
<td style="text-align: center;">3.5%</td>
</tr>
<tr style="background-color: #f7f7f7;">
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: left;">Distrito Federal</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: left;">Álvaro Obregón</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; border-right: 1px solid black; text-align: center;">749982</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: center;">20806</td>
<td style="background-color: #f7f7f7; border-bottom: 2px solid grey; text-align: center;">2.8%</td>
</tr>
</tbody>
</table>
<p><br/></p>
<p><br/>
<span class="caps">P.S.</span> <a href="https://github.com/diegovalle/afromexicans">Source Code</a></p>
<div class="footnote">
<hr/>
<ol>
<li id="fn:1">
<p><strong>Update</strong>: Removed the part about the back migration into Africa because it
<a href="https://dl.dropboxusercontent.com/u/26978112/Erratum%20with%20figures.pdf">was wrong</a> <a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">↩</a></p>
</li>
</ol>
</div>Up-to-date Crime Information2015-08-24T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2015-08-24:2015/08/up-to-date-crime-information.html<p><a href="https://elcri.men/en/">
<img alt="Hexbin of Mexico Crime Rates" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/homepage.png"/>
</a></p>
<p>Each month the Secretariado Ejecutivo del Sistema Nacional de Seguridad Pública publishes crime information on its website. The <a href="https://elcri.men/en/">crimenmexico</a> website downloads, processes the data, and presents it in an easy to interpret format. Even better, there’s also a Spanich version at <a href="https://elcri.men/">https://elcri.men/</a>
Besides the really cool interactive hexbin map on the homepage you can:</p>
<p><strong>View a time series of crimes by state</strong></p>
<p><a href="https://elcri.men/en/states.html">
<img alt="Crime by State" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/states.png"/>
</a></p>
<p><strong>View an interactive map that lets you filter by homicide rate</strong></p>
<p><a href="https://elcri.men/en/municipios-map.html">
<img alt="Municipio map" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/municipio-map.png"/>
</a></p>
<p><strong>View a time series of crimes in the most important municipios of Mexico</strong></p>
<p><a href="https://elcri.men/en/municipios.html">
<img alt="Crime by municipio" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/municipios.png"/>
</a></p>
<p><strong>Detect municipios with an unusual number of crimes</strong></p>
<p><a href="https://elcri.men/en/anomalies.html">
<img alt="Crime anomalies" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/anomalies.png"/>
</a></p>
<p><strong>View <a href="https://elcri.men/en/infographics.html">infographics</a></strong></p>
<p><a href="/images/posts/up-to-date-crime-information/infographic_jul_2015.png">
<img alt="Infographic" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/infographic_jul_2015.png"/>
</a></p>
<p><a href="/images/posts/up-to-date-crime-information/municipios_jul_2015.png">
<img alt="Infographic" class="image-process-article-image" src="/images/posts/up-to-date-crime-information/derivatives/article-image/municipios_jul_2015.png"/>
</a></p>
<p>I plan to update the data each month, hopefully the <span class="caps">SNSP</span> won’t change
the download format anymore.</p>Maps of the 2015 Mexican Election2015-06-15T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2015-06-15:2015/06/mexican-2015-election.html<p><a href="https://www.diegovalle.net/maps/election2015/election2015.html">
<img alt="Interactive Map of the 2015 Election" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/map-election-2015.png"/>
</a></p>
<p>According to official estimates (pending <span class="caps">TRIFE</span> approval) from the National Electoral Institute, the alliance led by President’s Peña Nieto party is set to retain its majority in the lower house of congress. However; a larger number of congressmen will belong to smaller parties. The Green Party, in alliance with the <span class="caps">PRI</span>, was projected to win 45 seats and a new leftist party, <span class="caps">MORENA</span>, founded by former Mexico City mayor and perennial presidential runner-up Andres Manuel Lopez Obrador, was projected to win 35 seats.</p>
<p>One thing that characterizes the smaller parties is their geographical clustering. My <a href="https://www.diegovalle.net/maps/election2015/election2015.html">interactive map</a> and charts should clarify the spatial patterns. All votes were computed using the coalition formula described in <em>Art. 12, inciso 2; Art. 311 inciso c) of the <span class="caps">LEGIPE</span></em></p>
<p><strong>The <span class="caps">PRI</span></strong> doesn’t have much support among residents of the Distrito Federal and some other urban areas.</p>
<p><a href="/images/posts/mexican-2015-election/PRI-estados.png">
<img alt="Map of the most evil party to have ever existed" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PRI-estados.png"/>
</a></p>
<p>And here is an equal area cartogram (where the area equals the population) of the <span class="caps">PRI</span> vote in the 300 electoral districts.</p>
<p><a href="/images/posts/mexican-2015-election/PRI-cartograma.png">
<img alt="Equal area cartogram of the most evil party to have ever existed" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PRI-cartograma.png"/>
</a></p>
<p><strong>The <span class="caps">PAN</span></strong> has always been very strong in the Bajio, though it has lost lots of votes since Calderón was elected president.</p>
<p><a href="/images/posts/mexican-2015-election/PAN-estados.png">
<img alt="Map of incompetents who don't know how to rule" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PAN-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PAN-cartograma.png">
<img alt="Equal area cartogram of incompetents who don't know how to rule" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PAN-cartograma.png"/>
</a></p>
<p><strong>The <span class="caps">PRD</span></strong> has very little support in northern Mexico.</p>
<p><a href="/images/posts/mexican-2015-election/PRD-estados.png">
<img alt="Map of chairos" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PRD-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PRD-cartograma.png">
<img alt="Equal area cartogram of chairos" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PRD-cartograma.png"/>
</a></p>
<p>Former <span class="caps">PRD</span> presidential candidate <span class="caps">AMLO</span> left to found his own party, <strong><span class="caps">MORENA</span></strong>, and split the left-wing vote. He has a lot of support in the Federal District where he used to be mayor and seems to have more support than the <span class="caps">PRD</span> in northern Mexico.</p>
<p><a href="/images/posts/mexican-2015-election/MORENA-estados.png">
<img alt="Map of the true chairos" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/MORENA-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/MORENA-cartograma.png">
<img alt="Equal area cartogram of the true chairos" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/MORENA-cartograma.png"/>
</a></p>
<p><strong><span class="caps">MORENA</span> vs <span class="caps">PRD</span></strong></p>
<p><a href="/images/posts/mexican-2015-election/morenavsprd-estados.png">
<img alt="Map of the cgairo vs chairos" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/morenavsprd-estados.png"/>
</a></p>
<p>Corrupt to its core, the <strong>Green Party</strong> is strong in Chiapas.</p>
<p><a href="/images/posts/mexican-2015-election/PVEM-estados.png">
<img alt="Map of the PRI satellite" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PVEM-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PVEM-cartograma.png">
<img alt="Equal area cartogram of PRI satellite" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PVEM-cartograma.png"/>
</a></p>
<p><strong>Movimiento Ciudadano</strong> was the party with the most votes in the state of Jalisco.</p>
<p><a href="/images/posts/mexican-2015-election/MC-estados.png">
<img alt="Map of the Movimiento Ciudadano" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/MC-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/MC-cartograma.png">
<img alt="Equal area cartogram of Movimiento Ciudadano" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/MC-cartograma.png"/>
</a></p>
<p><strong>Nueva Alianza</strong> (<span class="caps">PANAL</span>)</p>
<p><a href="/images/posts/mexican-2015-election/PANAL-estados.png">
<img alt="Map of Nueva Alianza" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PANAL-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PANAL-cartograma.png">
<img alt="Equal area cartogram of Nueva Alianza" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PANAL-cartograma.png"/>
</a></p>
<p><strong>Partido Encuentro Social</strong> (<span class="caps">PS</span>) - A sort of conservative party rumored to have ties with the
<em>Secretaría de Gobernación</em>, not surprisingly it captured its largest share of the vote in Hidalgo</p>
<p><a href="/images/posts/mexican-2015-election/ES-estados.png">
<img alt="Map of Partido Encuentro Social" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/ES-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/ES-cartograma.png">
<img alt="Equal area cartogram of Partido Encuentro Social" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/ES-cartograma.png"/>
</a></p>
<p>An <strong>Independent candidate</strong> won a federal electoral district for the first time ever</p>
<p><a href="/images/posts/mexican-2015-election/INDEP1-estados.png">
<img alt="Equal area hexbin of Independent votes" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/INDEP1-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/INDEP1-cartograma.png">
<img alt="Equal area cartogram of Independent votes" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/INDEP1-cartograma.png"/>
</a></p>
<p>With only 3132 more votes the <strong><span class="caps">PT</span></strong> would have reached the threshold of 3% of the effective vote to remain a registered party, but thanks to massive fraud it failed. This comes as no surprise in a country where imperialist lackey, western interloper, and former presidential candidate <a href="https://twitter.com/g_quadri/status/586214560945672192">Gabriel Quadri</a> advocates the bombing of the peaceful and happy people of Korea.</p>
<p><a href="/images/posts/mexican-2015-election/PT-estados.png">
<img alt="Map of the PT" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PT-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PT-cartograma.png">
<img alt="Equal area cartogram of the PT" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PT-cartograma.png"/>
</a></p>
<p>The <strong>Partido Humanista</strong> also didn’t reach the threshold to maintain its registration.</p>
<p><a href="/images/posts/mexican-2015-election/PH-estados.png">
<img alt="Map of the PT" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PH-estados.png"/>
</a></p>
<p><a href="/images/posts/mexican-2015-election/PH-cartograma.png">
<img alt="Equal area cartogram of the PT" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/PH-cartograma.png"/>
</a></p>
<p>There was a campaign to promote the <strong>null vote</strong>, but it was actually lower than in other years.</p>
<p><a href="/images/posts/mexican-2015-election/nulo-estados.png">
<img alt="Map of Null Vote" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/nulo-estados.png"/>
</a></p>
<p>Winner by party or coalition.</p>
<p><a href="/images/posts/mexican-2015-election/winner.png">
<img alt="Equal area cartogram of the winning party or coalition in each district" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/winner.png"/>
</a></p>
<p>Winner by party (showing the party with the most votes where a coalition won)</p>
<p><a href="/images/posts/mexican-2015-election/winner-party.png">
<img alt="Equal area cartogram of winning party by district" class="image-process-article-image" src="/images/posts/mexican-2015-election/derivatives/article-image/winner-party.png"/>
</a></p>
<p><span class="caps">P.S.</span> The code is available from <a href="https://github.com/diegovalle/elections2015">GitHub</a><br/>
<span class="caps">P.P.S.</span> Seriously, check out the <a href="https://www.diegovalle.net/maps/election2015/election2015.html">interactive map</a></p>Municipios with missing persons anomalies2015-03-26T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2015-03-26:2015/03/municipios-with-missing-persons.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-WSrm4l94k3E_VRQanTnSNfI_AAAAAAAAJIU_0xKru0c_ofc_s1600_map.png" imageanchor="1" ><img border="0" height="258" src="/images/blogger_images/2.bp.blogspot.com_-WSrm4l94k3E_VRQanTnSNfI_AAAAAAAAJIU_0xKru0c_ofc_s1600_map.png" width="320"/></a></div>
<br/>
The <i>Secretaría de Gobernación</i> just updated the missing persons database (<a href="https://rnped.segob.gob.mx/"><span class="caps">RNPED</span></a>) to include data up to January 2015. The database now contains information on 25,293 missing persons from the *fuero común* (local government) and 443 from the *fuero federal* (federal government).<br/>
<a name="more"></a><br/>
To make it easier to understand the data and make it actionable, I plotted all the municipios containing outliers during the period from August 2014 (just before the mass kidnapping in Ayotzinapa) to January 2015 (the last date available). The chart includes data from both the fuero federal and común.<br/>
<br/>
I used the <a href="https://github.com/twitter/AnomalyDetection">AnomalyDetection</a> R package to detect the anomalies.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-yKB1MYCcrIQ_VRN3g1cD29I_AAAAAAAAJIA_7EMwZPrbD7k_s1600_sm.png" imageanchor="1" ><img border="0" height="263" src="/images/blogger_images/2.bp.blogspot.com_-yKB1MYCcrIQ_VRN3g1cD29I_AAAAAAAAJIA_7EMwZPrbD7k_s1600_sm.png" width="400"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
</div>
Not surprisingly, Iguala, which saw the disappearance of 43 students on September 26, 2014 appears first on the list. The Mexican government should pay particular attention to these <i>municipios</i> if it wants to solve the missing persons problem in Mexico.<br/>
<br/>
This is a cartogram of the rates of disappearances at the state level. Obviously, some states like Guerrero and Nayarit (zero disappearances in 2014) under report disappearances.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-PDHFngmq6Ys_VRNyI0oFiVI_AAAAAAAAJHo_ZPkwbjoXWXI_s1600_cartogram.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/1.bp.blogspot.com_-PDHFngmq6Ys_VRNyI0oFiVI_AAAAAAAAJHo_ZPkwbjoXWXI_s1600_cartogram.png" width="330"/></a></div>
<br/>
<span class="caps">P.S.</span> Code is available <a href="https://github.com/diegovalle/rnped">here</a>
<div style="clear: both;"></div>
</div>The most partisan first names2015-02-09T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2015-02-09:2015/02/the-most-partisan-first-names.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-MTAL3sWStDs_VNqwgWrIUWI_AAAAAAAAI7U_BK05TWfxwSI_s1600_prd_names.svg.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-MTAL3sWStDs_VNqwgWrIUWI_AAAAAAAAI7U_BK05TWfxwSI_s1600_prd_names.svg.png" width="496"/></a></div>
I downloaded data from the <a href="http://www.ine.mx/archivos3/portal/historico/contenido/I_El_padron_afiliados_militantes_partidos_politicos_nacionales/">Instituto Nacional Electoral</a> to find out which names are the most overrepresented among the three main political parties in Mexico (<span class="caps">PRI</span>, <span class="caps">PAN</span>, and <span class="caps">PRD</span>). As was to be expected <span style="background-color: white; color: #545454; font-family: arial, sans-serif; font-size: x-small; line-height: 18.2000007629395px;">—</span>names are markers of class, income, religion, and geographical regions<span style="background-color: white; color: #545454; font-family: arial, sans-serif; font-size: x-small; line-height: 18.2000007629395px;">—</span> there are some major differences in which names the members of each political party bear.<br/>
<a name="more"></a><br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-xIr7_lAqQck_VNf9p2Nk3gI_AAAAAAAAI6k_eWUVEGEsefc_s1600_parties.svg.png" imageanchor="1" ><img border="0" height="290" src="/images/blogger_images/1.bp.blogspot.com_-xIr7_lAqQck_VNf9p2Nk3gI_AAAAAAAAI6k_eWUVEGEsefc_s1600_parties.svg.png" width="400"/></a></div>
The parties differ not only in their politics, but also in their internal structures and regions where they have support. The right wing <span class="caps">PAN</span> likes to keep its enrollment small and has 220,568 members or 3% of the total membership of the three major parties, the left wing <span class="caps">PRD</span> has 2,590,972 members or 33% of the total, and the <span class="caps">PRI</span> has 5,044,528 members or 64% of the total. And obviously, the political support of the parties varies by region, with <a href="https://www.diegovalle.net/maps/mordor/mordor.html">not that much overlap</a> between the <span class="caps">PAN</span> and <span class="caps">PRD</span>.<br/>
<br/>
In the following charts I’m showing first names with at least a total count (for all parties) of a hundred and a party memebership of at least 30 (for the party displayed in the chart).<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-n5PRKxFODQk_VNqxQNCL6-I_AAAAAAAAI7c_0JnNo1VnJhw_s1600_pan_names.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/4.bp.blogspot.com_-n5PRKxFODQk_VNqxQNCL6-I_AAAAAAAAI7c_0JnNo1VnJhw_s1600_pan_names.svg.png" width="310"/></a></div>
Notice how having more than one name is popular among members of the <span class="caps">PAN</span>, also that very few female names are overrepresented. The data you can download from the <span class="caps">INE</span> doesn’t include sex, but using an older dataset the membership of the <span class="caps">PAN</span> was 52% female a couple of years ago.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-ood5psTdJn8_VNqxYjitKYI_AAAAAAAAI7k_uCXklmbVtJ4_s1600_prd_names.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/4.bp.blogspot.com_-ood5psTdJn8_VNqxYjitKYI_AAAAAAAAI7k_uCXklmbVtJ4_s1600_prd_names.svg.png" width="310"/></a></div>
Note all the alternate spellings of Anayeli, Isabel, etc and how, unlike the <span class="caps">PAN</span>, people with two names are rare among the popular names.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-jEo2FA437og_VNqxe88MNfI_AAAAAAAAI7s_OZvXTPxgC8g_s1600_pri_names.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/4.bp.blogspot.com_-jEo2FA437og_VNqxe88MNfI_AAAAAAAAI7s_OZvXTPxgC8g_s1600_pri_names.svg.png" width="310"/></a></div>
I’ll just use this picture of the Guerrero Chimalli to illustrate the <span class="caps">PRI</span>:<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-1jP23F_hmLU_VNgWVn5N6KI_AAAAAAAAI7E_zic5jBJDwkM_s1600_Guerrero_chimalli.jpg" imageanchor="1" ><img border="0" height="216" src="/images/blogger_images/4.bp.blogspot.com_-1jP23F_hmLU_VNgWVn5N6KI_AAAAAAAAI7E_zic5jBJDwkM_s1600_Guerrero_chimalli.jpg" width="320"/></a></div>
<br/>
In the previous charts I used the full first name as a single name (Luis Miguel is different from Miguel Luis) but we can also analyse the names as single entities:<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-sLuWzvN6NR8_VNqxlNyG2sI_AAAAAAAAI70_GrhLhx8V_so_s1600_pan_names_single.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/2.bp.blogspot.com_-sLuWzvN6NR8_VNqxlNyG2sI_AAAAAAAAI70_GrhLhx8V_so_s1600_pan_names_single.svg.png" width="310"/></a></div>
Female names are more common among PANistas when analyzing each name as a separate entity<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-gYJWwOEoaFs_VNqxqvMd4TI_AAAAAAAAI78_YVftNCKlAdo_s1600_prd_names_single.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/4.bp.blogspot.com_-gYJWwOEoaFs_VNqxqvMd4TI_AAAAAAAAI78_YVftNCKlAdo_s1600_prd_names_single.svg.png" width="310"/></a></div>
Again notice all the alternate spellings (Brayan/Bryan, Jocelyn/Jocelin, etc)<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-2d17BOufJpo_VNqxvy3tiWI_AAAAAAAAI8E_3XWmIifd428_s1600_pri_names_single.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/2.bp.blogspot.com_-2d17BOufJpo_VNqxvy3tiWI_AAAAAAAAI8E_3XWmIifd428_s1600_pri_names_single.svg.png" width="310"/></a></div>
I also created a <a href="https://en.wikipedia.org/wiki/Ternary_plot#Reading_values_on_the_ternary_plot">ternary plot</a> so you can view how common the names are in each political party at the same time (remember the <span class="caps">PAN</span> has a very small membership)<br/>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-NVkXH8ar-oM_VNfx2fTc1JI_AAAAAAAAI5w_MDOLdz3O5vA_s1600_triforce.svg.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/2.bp.blogspot.com_-NVkXH8ar-oM_VNfx2fTc1JI_AAAAAAAAI5w_MDOLdz3O5vA_s1600_triforce.svg.png" width="400"/></a></div>
<br/>
I was curious about all the alternate spellings of Anayeli, though in the table below I’m only showing the most common ones <span style="background-color: white; color: #545454; font-family: arial, sans-serif; font-size: x-small; line-height: 18.2000007629395px;">—</span>there literally are dozens and dozens of variations<span style="background-color: white; color: #545454; font-family: arial, sans-serif; font-size: x-small; line-height: 18.2000007629395px;">—</span> and, well, <span class="caps">PAN</span> members just don’t like that name.<br/>
<br/>
<table style="border-collapse: collapse; border-spacing: 0px; color: black; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; max-width: 100%; vertical-align: middle;"><thead>
<tr><th align="left" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Name</th><th align="right" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Count for All Parties</th><th align="left" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Party</th><th align="right" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Count for Party</th><th align="right" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Expected Percentage</th><th align="right" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Percent Named Belonging to Party</th></tr>
</thead><tbody>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1730</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PAN</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">39</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.03</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.02</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANALLELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">387</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">278</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.72</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1449</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1015</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.70</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANALLELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">110</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">74</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.67</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANA</span> <span class="caps">YELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">138</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">92</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.67</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELLI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">134</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">88</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.66</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">115</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">74</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1730</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1084</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.63</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NALLELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">837</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">501</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.60</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YANELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">301</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">176</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.58</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">217</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRD</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">124</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.33</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.57</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">217</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">92</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.42</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YANELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">301</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">121</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.40</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NALLELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">837</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">319</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.38</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1730</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">607</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.35</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">115</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">39</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.34</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANA</span> <span class="caps">YELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">138</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">44</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.32</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANALLELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">110</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">35</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.32</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAYELLI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">134</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">42</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.31</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANAYELI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">1449</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">426</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.29</td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ANALLELY</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">387</td><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRI</span></td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">104</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.64</td><td align="right" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">0.27</td></tr>
</tbody></table>
<br/>
I figured it would be a good idea to count the percentage of first names that are only present in one party, and to my surprise the <span class="caps">PAN</span> has the highest percentage of unique names by far. I also measured the complexity of the names using Levenshtein and Soundex distances, and again the <span class="caps">PAN</span> had the most similarly spelled/sounding names.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-CqQQcyjaAhU_VNqx_skYuCI_AAAAAAAAI8M_lt50QTC9Gvc_s1600_unique_name.svg.png" imageanchor="1" ><img border="0" height="210" src="/images/blogger_images/1.bp.blogspot.com_-CqQQcyjaAhU_VNqx_skYuCI_AAAAAAAAI8M_lt50QTC9Gvc_s1600_unique_name.svg.png" width="320"/></a></div>
Here are random samples of some unique by party names:</div>
<div>
<br/>
<table style="border-collapse: collapse; border-spacing: 0px; color: black; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; max-width: 100%; vertical-align: middle;"><thead>
<tr><th align="left" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Names that are only present in the <span class="caps">PAN</span></th></tr>
</thead><tbody>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ADALGOT</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">BLERIATH</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">EDONE</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">EMIDGIO</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">EROILIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">GIBSON</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">HABANA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">JAUDEL</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">JOLANI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">GLORESBINDA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">LIUVITZA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MYLTHON</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NUYHIAVI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ORSIRIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">RICCO</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">VEUDY</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YAMICLET</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YECIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YURINTZI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ZAADIA</span></td></tr>
</tbody></table>
<table style="border-collapse: collapse; border-spacing: 0px; color: black; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; max-width: 100%; vertical-align: middle;"><thead>
<tr><th align="left" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Names that are only present in the <span class="caps">PRD</span></th></tr>
</thead><tbody>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">BASELIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MUYKEY</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ERAMIS</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">GUILSONI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">HAIRA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">HEREDINDA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">HORANA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">IGILVIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ISBELI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">JASSINA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PAARIS</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">LLARIDEY</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MAFAIDA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MARVITA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PRYTSCILIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">SARIDH</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YARHELI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YESSMIT</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YSAYCHU</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ZIRIACO</span></td></tr>
</tbody></table>
<table style="border-collapse: collapse; border-spacing: 0px; color: black; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; max-width: 100%; vertical-align: middle;"><thead>
<tr><th align="left" style="background-color: #dddddd; border: 1px solid rgb(238, 238, 238); padding: 5px 10px;">Names that are only present in the <span class="caps">PRI</span></th></tr>
</thead><tbody>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">AAGAR</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ADIRAI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">BEGAIN</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">BERENIZA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ELIOTZEL</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ELISAMARIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">ENIZAEL</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">GLENIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">JARASED</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">MOSAISELA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NARCIDELIA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">NAZDRY</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">POLEN</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">PONPOM</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">RUTHYALITH</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">SELENICO</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">SHADIRA</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">SICLALI</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">WUDRUM</span></td></tr>
<tr><td align="left" style="border: 1px solid rgb(238, 238, 238); padding: 5px 10px;"><span class="caps">YENIZEN</span></td></tr>
</tbody></table>
Hopefully your parents never gave you the misspelled name of a famous Mexican stripper!<br/>
<br/>
<iframe width="560" height="315" src="https://www.youtube.com/embed/tZXmBbLoEIU" frameborder="0" allowfullscreen></iframe><br/>
<br/>
Where people have unique first names they, unsurprisingly, also have unique last names<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-f2qa9at07d0_VNqyN62NiAI_AAAAAAAAI8U_YrjzMtDt6s4_s1600_unique_name_map.svg.png" imageanchor="1" ><img border="0" height="310" src="/images/blogger_images/2.bp.blogspot.com_-f2qa9at07d0_VNqyN62NiAI_AAAAAAAAI8U_YrjzMtDt6s4_s1600_unique_name_map.svg.png" width="400"/></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-VUh0HY8x8IU_VNqySZcgGjI_AAAAAAAAI8c_iM96W24JwuA_s1600_unique_lastnames_map.svg.png" imageanchor="1" ><img border="0" height="310" src="/images/blogger_images/3.bp.blogspot.com_-VUh0HY8x8IU_VNqySZcgGjI_AAAAAAAAI8c_iM96W24JwuA_s1600_unique_lastnames_map.svg.png" width="400"/></a></div>
As you probably noticed the names play into some deep seated stereotypes in Mexican culture (some worse than others). Simply perform a search in Google Images for “Brayan” or visit <a href="http://eldeforma.com/2012/05/24/3-adolescentes-de-apellido-compuesto-posan-para-la-seccion-gente-del-periodico-reforma/">El Deforma</a> to see how they routinely use long names to make fun of the mirreyes. Brayan is in fact more common among members of <span class="caps">PRD</span> (even if unique names are more common in the <span class="caps">PAN</span>) and long names do seem to be more common among PANistas:<br/>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-cTxD4suu0J0_VNfyN7FU-CI_AAAAAAAAI6I_NH9arP3W6wc_s1600_length_distribution_parties.svg.png" imageanchor="1" ><img border="0" height="291" src="/images/blogger_images/1.bp.blogspot.com_-cTxD4suu0J0_VNfyN7FU-CI_AAAAAAAAI6I_NH9arP3W6wc_s1600_length_distribution_parties.svg.png" width="400"/></a></div>
The longest name in the database belongs to <span class="caps">GUADALUPE</span> <span class="caps">DEL</span> <span class="caps">SAGRADO</span> <span class="caps">CORAZON</span> <span class="caps">ESPINOSA</span> <span class="caps">DE</span> <span class="caps">LOS</span> <span class="caps">MONTEROS</span> Y <span class="caps">GOLZARRI</span>, and I bet I don’t even have to tell you what party she belong to (<span class="caps">PAN</span>). Well, actually, it seems the name field at the time of entering the data in the <span class="caps">INE</span> database had a length limit and some names got clipped off, or abbreviated. I tried to somewhat clean up the data when possible.<br/>
<br/>
Using a logistic regression to predict left wing or right wing party membership (I excluded the <span class="caps">PRI</span> since they only care about power and are corrupt, yay stereotypes!) gives exactly the results you would expect:<br/>
<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-y34kS4ijBZg_VNfyUtgFCoI_AAAAAAAAI6Q_UTknGUUZFZY_s1600_length_reg.svg.png" imageanchor="1" ><img border="0" height="291" src="/images/blogger_images/4.bp.blogspot.com_-y34kS4ijBZg_VNfyUtgFCoI_AAAAAAAAI6Q_UTknGUUZFZY_s1600_length_reg.svg.png" width="400"/></a></div>
<br/></div>
<div>
<br/></div>
<div>
<span class="caps">P.S.</span> Code is available from <a href="https://github.com/diegovalle/caste-war">GitHub</a></div>
<div>
<span class="caps">P.P.S.</span> My next post will explain the following chart. If you don’t want to miss it <b>subscribe</b> to my <a href="http://eepurl.com/_Carj">email newsletter</a>.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-vnzgFLAoZuE_VNgQ4jE_JnI_AAAAAAAAI60_YOjJurv4NMk_s1600_prd.png" imageanchor="1" ><img border="0" height="400" src="/images/blogger_images/2.bp.blogspot.com_-vnzgFLAoZuE_VNgQ4jE_JnI_AAAAAAAAI60_YOjJurv4NMk_s1600_prd.png" width="400"/></a></div>
<div>
<br/></div>
</div>
<div style="clear: both;"></div>
</div>The 74 most violent cities in Mexico (2013)2015-01-14T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2015-01-14:2015/01/the-74-most-violent-cities-in-mexico.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-MRLIYf2Wako_VLXlXyLqPKI_AAAAAAAAIzc_5GbtAkFZ1Uc_s1600_change2012-2013.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-MRLIYf2Wako_VLXlXyLqPKI_AAAAAAAAIzc_5GbtAkFZ1Uc_s1600_change2012-2013.png" width="481"/></a></div>
I’ve updated the <a href="https://github.com/diegovalle/mxmortalitydb">mxmortalitydb</a> package to include 2013 data. This data only package includes all injury intent deaths (accidents, homicides, suicides, and unspcified intent) that were registered in Mexico from 2004 to 2013. You can use the package to calculate changes and trends in homicide rates in the most violent metro areas (or large municipios) or at the national level.<br/>
<a name="more"></a><br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-k5Slsj78fPU_VLXopC_wBxI_AAAAAAAAI0I_EPG9M3y3wfk_s1600_unnamed-chunk-4-1.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/1.bp.blogspot.com_-k5Slsj78fPU_VLXopC_wBxI_AAAAAAAAI0I_EPG9M3y3wfk_s1600_unnamed-chunk-4-1.png" width="320"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
</div>
You can also use the package to explore the deaths whose intent was left unspecified (note the large increase in firearm deaths in 2011, the year Mexico had the highest homicide rate in recent history)<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-G-1Ee56oeZ4_VLXlhvwiIjI_AAAAAAAAIzs_EpcDIGLcbO8_s1600_unnamed-chunk-4-2.png" imageanchor="1" ><img border="0" height="266" src="/images/blogger_images/4.bp.blogspot.com_-G-1Ee56oeZ4_VLXlhvwiIjI_AAAAAAAAIzs_EpcDIGLcbO8_s1600_unnamed-chunk-4-2.png" width="400"/></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
And make pretty plots of the most violent metro areas or large municipios which are not part of a metro area (in Mexico by definition a metro area has to consist of more than one municipio, so it is worthwhile to include single municipios with large populations). I should also note that the database only includes deaths where a death certificate was issued, so if there are clandestine mass graves that haven’t been found (as was the case recently in Iguala) or where the deaths somehow were not registered (as was the case with the Taxco mass grave) then the deaths are not included in the counts.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-MRLIYf2Wako_VLXlXyLqPKI_AAAAAAAAIzc_5GbtAkFZ1Uc_s1600_change2012-2013.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-MRLIYf2Wako_VLXlXyLqPKI_AAAAAAAAIzc_5GbtAkFZ1Uc_s1600_change2012-2013.png" width="481"/></a></div>
While violence has decreased in recent years it still has a long way to drop before it reaches the levels seen in 2006.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-RW4kPfwWfYU_VLXlxuE9brI_AAAAAAAAIz8_4iLCGw84fs4_s1600_change2006-2013.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/4.bp.blogspot.com_-RW4kPfwWfYU_VLXlxuE9brI_AAAAAAAAIz8_4iLCGw84fs4_s1600_change2006-2013.png" width="482"/></a></div>
Note the mixed trend in Michoacán.<br/>
<br/>
Do note that the charts of homicides from 2006 were made with the 2010 population according to the <span class="caps">CONAPO</span>, so the homicide rate was underestimated by a little bit. Also, rather than using the raw homicide numbers I adjusted them by classifying deaths of unknown intent as described in the <a href="https://github.com/diegovalle/mxmortalitydb">mxmortalitydb package</a> and this <a href="http://blog.diegovalle.net/2012/12/mexicos-drug-war-63000-extra-deaths-in.html">post</a>.<br/>
<div>
<br/></div>
<div>
The code for generating the charts is available from <a href="https://gist.github.com/diegovalle/f6275ac1aa83e0a7d9e3">GitHub</a></div>
<div style="clear: both;"></div>
</div>Nobody lives here2014-12-10T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2014-12-10:2014/12/nobody-lives-here.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.diegovalle.net/maps/nobody-lives-here" imageanchor="1" ><img border="0" height="257" src="/images/blogger_images/3.bp.blogspot.com_-HKCUjsSGE_M_VIdhlcIf1dI_AAAAAAAAIjk_FYJpv6vsEUY_s1600_a1.png" width="400"/></a></div>
This is an interactive <a href="https://www.diegovalle.net/maps/nobody-lives-here">map</a> of all rural AGEBs that contain no localities and thus are empty of permanent residents. If you compare it to the <a href="http://mapsbynik.tumblr.com/post/82791188950/nobody-lives-here-the-nearly-5-million-census"><span class="caps">US</span> version</a>, the total area with no people living inside it is much smaller since the data in Mexico is only available at the <span class="caps">AGEB</span> level (kind of like Census Tracts), whereas the data in the <span class="caps">US</span> is available at the Census Block level which are much smaller. Since there are no polygons available for rural localities, only points, I counted all rural AGEBs that contained a locality as being inhabited.<br/>
<br/>
<a name="more"></a>With a relief map<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-Sfgfs_YCc1c_VIiSaFp5-kI_AAAAAAAAIj0_8acZ4pjdpio_s1600_sdfg.jpg" imageanchor="1" ><img border="0" height="226" src="/images/blogger_images/4.bp.blogspot.com_-Sfgfs_YCc1c_VIiSaFp5-kI_AAAAAAAAIj0_8acZ4pjdpio_s1600_sdfg.jpg" width="320"/></a></div>
With dense vegetation<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-kRJD3HtMMU4_VIiSglPizhI_AAAAAAAAIj8_JnFkZ-_beYI_s1600_vegetacion_densa.png" imageanchor="1" ><img border="0" height="226" src="/images/blogger_images/2.bp.blogspot.com_-kRJD3HtMMU4_VIiSglPizhI_AAAAAAAAIj8_JnFkZ-_beYI_s1600_vegetacion_densa.png" width="320"/></a></div>
<br/>
By type of climate<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-1sNj6yJKxN4_VIiSnYM3cII_AAAAAAAAIkE_QTYI-vbkVzk_s1600_a.png" imageanchor="1" ><img border="0" height="226" src="/images/blogger_images/2.bp.blogspot.com_-1sNj6yJKxN4_VIiSnYM3cII_AAAAAAAAIkE_QTYI-vbkVzk_s1600_a.png" width="320"/></a></div>
With protected areas (Área Nacional Protegida)<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-6AUDjuxHrUU_VIiSzPSDUGI_AAAAAAAAIkM_G7MlYtVUPfg_s1600_anp.png" imageanchor="1" ><img border="0" height="226" src="/images/blogger_images/2.bp.blogspot.com_-6AUDjuxHrUU_VIiSzPSDUGI_AAAAAAAAIkM_G7MlYtVUPfg_s1600_anp.png" width="320"/></a></div>
<br/>
<br/>
The code is available from <a href="https://gist.github.com/diegovalle/2d997631d08f894d64e6">GitHub</a><br/>
<br/>
<div style="clear: both;"></div>
</div>HoyodeCrimen.com - Crime information for the Distrito Federal2014-11-10T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2014-11-10:2014/11/hoyodecrimencom-crime-information-for.html<div class="post-body entry-content" itemprop="articleBody">
Crime information for the Federal District now has its own website with updated data<br/>
<br/>
<a href="https://hoyodecrimen.com/en">https://hoyodecrimen.com/en</a>/ - English version<br/>
<a href="https://hoyodecrimen.com/">https://hoyodecrimen.com/</a> - Spanish version<br/>
<br/>
I’ve also added a <a href="https://hoyodecrimen.com/en/trends">trends</a> section where you can look up which cuadrantes experienced a rise in crime<br/>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="/images/blogger_images/3.bp.blogspot.com_-_wyTP_VtNUY_VGC4js4s5sI_AAAAAAAAIW0_IbXYaZdg2Hk_s1600_https%2B%2B%2Bhoyodecrimen.com%2Ben%2Btrends.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="236" src="/images/blogger_images/3.bp.blogspot.com_-_wyTP_VtNUY_VGC4js4s5sI_AAAAAAAAIW0_IbXYaZdg2Hk_s1600_https%2B%2B%2Bhoyodecrimen.com%2Ben%2Btrends.png" width="400"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">There seems to a be big problem with car robberies near where the new airport will be built</td></tr>
</tbody></table>
<br/>
<br/>
Since the crime data comes from <span class="caps">FOIA</span> requests to the <span class="caps">SSPDF</span> (Mexico City Police), I’ve added free email announcements to keep you informed of when new data is available:<br/>
<br/>
<a href="http://eepurl.com/71l2n">Notifications in English</a><br/>
<a href="http://eepurl.com/7XKNT">Notifications in Spanish</a><br/>
<br/>
<br/>
There’s even an <a href="https://hoyodecrimen.com/api/"><span class="caps">API</span></a> with lots of cools stuff:<br/>
<a name="more"></a><br/>
<table border="1" class="docutils" style="background-color: white; border-collapse: collapse; border: 0px; color: #3e4349; font-family: Arial, sans-serif; font-size: 14px;"><thead valign="bottom">
<tr class="row-odd"><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Service</th><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Action</th><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><span class="caps">URI</span></th></tr>
</thead><tbody valign="top">
<tr class="row-even"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Point in Polygon</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Given a longitude and latitude return the corresponding cuadrante and sector</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
<tr class="row-odd"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Time Series</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Crime counts ordered by month of occurrence for a cuadrante or sector</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
<tr class="row-even"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">List Cuadrantes or Sectores</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Sum of crimes that occurred in a cuadrante or sector for a specified period of time</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
<tr class="row-odd"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Top Most Violent</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">A list of the cuadrantes and sectors with the highest rates (sectores), crime counts (cuadrantes) or change in crime counts (cuadrantes)</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
<tr class="row-even"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><span class="caps">DF</span> data</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">A time series of the sum of all crimes that occurred in the Federal District</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
<tr class="row-odd"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Enumerate</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;">Get a list of the names of all cuadrantes, sectores or crimes</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-width: 0px 0px 1px; padding: 1px 8px 1px 5px;"><div class="first last line-block" style="margin-bottom: 1em; margin-top: 1em;">
<div class="line">
<br/></div>
</div>
</td></tr>
</tbody></table>
<br/>
<span class="caps">P.S.</span> Yes, I know the Spanish translation is not complete, but I’ll finish it someday<br/>
<span class="caps">P.P.S.</span> The code is available at <a href="https://github.com/diegovalle/hoyodecrimen.api">GitHub</a>. It was built with Python + Flask + PostgreSQL + PotsGIS + Redis + D3 and an unholy combination of jQuery and AngularJS
<div style="clear: both;"></div>
</div>Important notice regarding crimenmexico2014-09-25T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2014-09-25:2014/09/important-notice-regarding-crimenmexico.html<div class="post-body entry-content" itemprop="articleBody">
The website from which <a href="https://elcri.men/">crimenmexico</a> downloads crime information hasn’t been responding for quite a while now. The <span class="caps">SESNSP</span> server’s uptime has never been good but it has never stayed down for so long.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-REBmOYTs0Rg_VCN02fOOonI_AAAAAAAAHVE_z4atf3nxccI_s1600_uptime.png" imageanchor="1" ><img border="0" height="221" src="/images/blogger_images/2.bp.blogspot.com_-REBmOYTs0Rg_VCN02fOOonI_AAAAAAAAHVE_z4atf3nxccI_s1600_uptime.png" width="400"/></a></div>
which I guess means that <i>Secretariado Ejecutivo del Sistema Nacional de Seguridad Pública</i> has suspended its open data policy of providing crime information. Apparently crime info is now only downloadable from a couple of <a href="http://www.secretariadoejecutivo.gob.mx/es/SecretariadoEjecutivo/09121420">zip files</a>, but <span class="caps">SESNSP</span> made sure to:<span id="goog_1246066625"></span><br/>
<ul>
<li>Change the names of the crimes to include whitespace at the end (e.g “<span class="caps">ROBOS</span>” to “<span class="caps">ROBOS</span> ”)</li>
<li>Not include the <span class="caps">INEGI</span> code for each state and municipality, thus making it really difficult to merge with other data</li>
<li>Spell state names both with and without accents (YUCATÁN and <span class="caps">YUCATAN</span>)</li>
<li>Include subtotals (e.g. total crimes with violence) at the municipality level but not at the state level</li>
<li>Change the file format from csv to xlsx (Excel)</li>
</ul>
It’s almost as if they didn’t want anyone analyzing the data. It used to be that <a href="https://elcri.men/es/">crimenmexico</a> processed all the information in an automatic manner and made new data available immediately, but with these changes that has become impossible (I’m betting next month there will be more changes). There will now be a delay of a few weeks or so while I figure how to process the data.<br/>
<br/>
At the <a href="http://secretariadoejecutivo.gob.mx/incidencia-delictiva/incidencia-delictiva-fuero-comun.php">webpage for downloading the crime information</a> the <span class="caps">SESNSP</span> claims that [emphasis added]:<br/>
<div>
<blockquote class="tr_bq">
La presentación de los datos sobre incidencia delictiva en este portal electrónico obedece a los principios de acceso a la información y transparencia y a la<b> adopción de las mejores prácticas internacionales en gobierno abierto</b>.</blockquote>
If you disagree you can contact the <span class="caps">SESNSP</span> at: <a href="mailto:cni@secretariadoejecutivo.gob.mx">cni@secretariadoejecutivo.gob.mx</a></div>
<div style="clear: both;"></div>
</div>Crime in Mexico City at the cuadrante delictivo level2014-05-27T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2014-05-27:2014/05/crime-in-mexico-city-at-cuadrante.html<p><b>Update:</b> This post has been superceded by <a href="https://hoyodecrimen.com">hoyodecrimen.com</a>
<div class="post-body entry-content" itemprop="articleBody">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://hoyodecrimen.com/en/" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="266" src="/images/blogger_images/3.bp.blogspot.com_-FRABFGdX-AY_U4PeuMWvMtI_AAAAAAAAGqM_kIYdCPl8NVI_s1600_Screenshot+-+05262014+-+07-37-58+PM.png" width="400"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the image to visit the <a href="https://hoyodecrimen.com/en/">interactive visualization</a></td></tr>
</tbody></table>
I recently made a <a href="http://www.infomexdf.org.mx/InfomexDF/Default.aspx"><span class="caps">FOIA</span> request</a> to the <a href="http://www.ssp.df.gob.mx/Pages/Ini.aspx"><span class="caps">SSPDF</span></a> requesting information on crime at the <i>cuadrante delictivo</i> level (in-between size a municipio and a <a href="http://blog.diegovalle.net/2013/06/shapefiles-of-mexico-agebs-manzanas-etc.html">manzana</a>), and to my surprise they actually answered with a <a href="https://github.com/diegovalle/crimeDF/tree/9f96d6ed41ae3e3a025c8f78d771cba11735e49c/sspdf-data"><span class="caps">PDF</span> file</a> containing homicides, robbery to businesses with violence, and car robbery with and without violence, from Jan 2013 to April 2014. I also asked for data on extortion, kidnapping, etc but the <span class="caps">SSPDF</span> claimed not to have any records on those crimes.<br/>
<br/>
To be able to display the data on a map I scraped the polygon coordinates of each <i>cuadrante</i> from the <a href="http://201.144.220.174/pid/gps/cuadrantesWeb.php">find the cop assigned to your quadrant </a>website. The data was supplemented with population figures obtained by using a point-in-polygon algorithm from the 2010 Census at the manzana level.<br/>
<br/>
The data for April 2014 was clearly incomplete and I excluded it from the visualizations. The numbers provided by the <span class="caps">SSPDF</span> compare favorably to those provided by the <span class="caps">SNSP</span>, though you have to remember these are<i> averiguaciones previas</i> (reports) and that they undercount the number of victims, especially for the crime of homicide.<br/>
<br/></p>
<table>
<thead>
<tr>
<th><a href="http://www.secretariadoejecutivo.gob.mx/work/models/SecretariadoEjecutivo/Resource/131/1/images/2013Act_052014.pdf#11">Crime (2013) </a></th>
<th><span class="caps">SNSP</span></th>
<th><span class="caps">SSPDF</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>Homicidio doloso</td>
<td>749</td>
<td>899</td>
</tr>
<tr>
<td>Robo a negocio C/V</td>
<td>4,239</td>
<td>4290</td>
</tr>
<tr>
<td>Robo de vehiculo automotor C/V</td>
<td>5,223</td>
<td>5,211</td>
</tr>
<tr>
<td>Robo de vehiculo automotor S/V</td>
<td>12,056</td>
<td>12,014</td>
</tr>
</tbody>
</table>
<p><br/>
The data at the cuadrante level is visualized as counts because the daytime population of a cuadrante is probably different from the number of people who actually live there.<br/>
<br/>
<a href="https://hoyodecrimen.com/en/counts">Quadrants</a><br/>
<a href="https://hoyodecrimen.com/en/rates">Sectors</a> (Each sector contains many quadrants)<br/>
<a href="https://hoyodecrimen.com/en/">Website</a><br/>
<br/>
<span class="caps">P.S.</span> The code and data are on <a href="https://github.com/diegovalle/crimeDF">GitHub</a>
<div style="clear: both;"></div>
</div></p>Analysis of the UNAM’s entrance exam2014-04-07T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2014-04-07:2014/04/analisis-exam-de-admision-unam.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-W024CTuRmSA_UzOZeyqzFpI_AAAAAAAAGlY_sHWd5TcNwow_s1600_Physical+Sciences%252C+Mathematics+and+Engineering-majors.svg.png" imageanchor="1" ><img border="0" height="300" src="/images/blogger_images/1.bp.blogspot.com_-W024CTuRmSA_UzOZeyqzFpI_AAAAAAAAGlY_sHWd5TcNwow_s1600_Physical+Sciences%252C+Mathematics+and+Engineering-majors.svg.png" width="540"/></a></div>
The <span class="caps">UNAM</span> is Mexico’s biggest and most important university. To enter it students must either take an exam or graduate from a high school run by the <span class="caps">UNAM</span> in less than 4 years with a grade point average of at least 70% (although some majors like medicine require 90% for <i>pase directo</i>). The admission exam is given twice a year, in February and June, and any student from any high school with at least a grade point average of 70% can take it. If the student meets the requirements for entering the <span class="caps">UNAM</span>, passing the exam guarantees him admission. The exam has 120 questions.<br/>
<a name="more"></a><br/>
Depending on the student’s choice of major, the admission exam emphasizes one of four basic areas of study. Let’s say you want to study math: in addition to being tested on the topics every high school student is supposed to know, you’ll get a couple of extra questions about integration by parts; if you want to study biology the extra questions will be about the the Krebs cycle; if you want to study philosophy the exam will probably include extra references to the great works of literature; and if you want to study a social science you’ll be asked about the differences between a <a href="http://eldeforma.com/2014/03/22/unam-ofrecera-la-carrera-de-licenciatura-en-filantropia/">grand macchiato and a caffè latte</a>.<br/>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.diegovalle.net/charts/unam/all-unam.html"><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-qb0xz0yZ8A8_UzORAIretuI_AAAAAAAAGk4_cP_dRh5EHxA_s1600_SankeyID612f45f26c41.png" style="margin-left: auto; margin-right: auto;" width="392"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the chart to visit the interactive version</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.diegovalle.net/charts/unam/all-unam.html" imageanchor="1" ></a><br class="Apple-interchange-newline"/></div>
<a href="http://www.diegovalle.net/charts/unam/all-unam.html" imageanchor="1" ></a><br/>
Apart from <span class="caps">UNAM</span>’s main (and most prestigious) campus of Ciudad Universitaria (<span class="caps">CU</span>), the university has several satellite campuses in the Mexico City metro area as well as many others across Mexico. In this post I will only analyse those located in Mexico City, and only for the scholarized system (<i>sistema escolarizado</i>) where the students have to actually sit in a classroom (the <span class="caps">UNAM</span> also offers remote <span class="caps">TV</span>/Internet classes and under an open system).<span style="background-color: white; color: #252525; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span>The admission exam to the <span class="caps">UNAM</span> is quite competitive and only a small percentage of those who apply actually get in.<br/>
<br/>
<table><thead>
<tr> <th>Date</th> <th>Location</th> <th>Percentage <br/>
admitted</th> <th>Applied</th> <th>Completed<br/>
Test </th> <th>Admitted</th> </tr>
</thead> <tbody>
<tr> <td>2011-06 </td> <td><span class="caps">CU</span> </td> <td>8.6</td> <td>30,615 </td> <td>27,515 </td> <td>2,626 </td> </tr>
<tr> <td>2011-06 </td> <td>Not <span class="caps">CU</span> </td> <td>9.1</td> <td>32,215 </td> <td>29,667 </td> <td>2,916 </td> </tr>
<tr> <td>2012-02 </td> <td><span class="caps">CU</span> </td> <td>5.2</td> <td>61,262 </td> <td>55,793 </td> <td>3,192 </td> </tr>
<tr> <td>2012-02 </td> <td>Not <span class="caps">CU</span> </td> <td>6.4</td> <td>56,012 </td> <td>52,287 </td> <td>3,597 </td> </tr>
<tr> <td>2012-06 </td> <td><span class="caps">CU</span> </td> <td>5.1 </td> <td>30,944 </td> <td>28,084 </td> <td>1,573 </td> </tr>
<tr> <td>2012-06 </td> <td>Not <span class="caps">CU</span> </td> <td>10.1</td> <td>32,741 </td> <td>30,354 </td> <td>3,299 </td> </tr>
<tr> <td>2013-02 </td> <td><span class="caps">CU</span> </td> <td>5.4</td> <td>63,562 </td> <td>59,425 </td> <td>3,424 </td> </tr>
<tr> <td>2013-02 </td> <td>Not <span class="caps">CU</span> </td> <td>6.7</td> <td>56,348 </td> <td>53,547 </td> <td>3,800 </td> </tr>
<tr> <td>2013-06 </td> <td><span class="caps">CU</span> </td> <td>6.3 </td> <td>29,872 </td> <td>26,052 </td> <td>1,868 </td> </tr>
<tr> <td>2013-06 </td> <td>Not <span class="caps">CU</span> </td> <td>13.8 </td> <td>33,744 </td> <td>30,403 </td> <td>4,656 </td> </tr>
</tbody> </table>
<br/>
This year Harvard sent out 2,023 offers out of 34,295 applications for an admission rate of 5.9%, which is exactly the same overall admission rate as the <span class="caps">UNAM</span> (<span class="caps">CU</span>) from June 2011 to June 2013 (though, of course, Harvard has much much <a href="http://www.eluniversal.com.mx/notas/860687.html">lower standards</a> in who it <a href="http://www.hks.harvard.edu/news-events/news/press-releases/felipe-calderon-appointment">admits</a>).<br/>
<br/>
Admissions by major<br/>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.diegovalle.net/charts/unam/major-major.html" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-gpIWyXhnrwY_UzOhxbR4AyI_AAAAAAAAGl0_CZPGRcMl4Y0_s1600_MEDICO+CIRUJANO+CU+31+219+persons.png" width="544"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the chart to visit the interactive version</td></tr>
</tbody></table>
<br/>
Admissions by area<br/>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.diegovalle.net/charts/unam/area-area.html"><img border="0" height="279" src="/images/blogger_images/2.bp.blogspot.com_-bwjiCvN-jC4_UzOm2SNv8YI_AAAAAAAAGmE_T-sS6YTeDPw_s1600_Sankeyarea.png" style="margin-left: auto; margin-right: auto;" width="320"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the chart to visit the interactive version</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-bwjiCvN-jC4_UzOm2SNv8YI_AAAAAAAAGmE_T-sS6YTeDPw_s1600_Sankeyarea.png" imageanchor="1" ></a><br class="Apple-interchange-newline"/></div>
<a href="/images/blogger_images/2.bp.blogspot.com_-bwjiCvN-jC4_UzOm2SNv8YI_AAAAAAAAGmE_T-sS6YTeDPw_s1600_Sankeyarea.png" imageanchor="1" ></a><br/>
<div>
I scrapped all admission results from the <a href="https://www.dgae.unam.mx/noticias/primingr/primingr.html"><span class="caps">UNAM</span>’s website</a> from June 2011 to June 2013. There were some problems with the data at the <span class="caps">UNAM</span>’s end since the listings didn’t always match the summary statistics included in the web pages. If you visit the results for <a href="https://servicios.dgae.unam.mx/Junio2012/resultados/4/4337005.html">Historia del Arte</a> you’ll see that the summary statistics claim that zero students applied to take the test, but the listing includes 3 students (given the <a href="http://www.diegovalle.net/charts/unam/scores.html">test scores of infomatics students</a> I’m not surprised by the mistakes). Anyways, this kind of mismatch was rare and didn’t involve that many students. I took the actual listing to be definitive. In addition the results sometimes include data from students whose result is <i>Cita para aclarar situación escolar</i>, I simply interpreted this as being a <a href="http://www.statmethods.net/input/missingdata.html">missing value</a>.</div>
<div>
<br/></div>
<div>
Physical Sciences, Mathematics and Engineering</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-OR_nW6bpjw4_U0HS18xq6pI_AAAAAAAAGmc_pnGpJw045Mc_s1600_Physical+Sciences,+Mathematics+and+Engineering-majors.svg.png" imageanchor="1" ><img border="0" height="182" src="/images/blogger_images/3.bp.blogspot.com_-OR_nW6bpjw4_U0HS18xq6pI_AAAAAAAAGmc_pnGpJw045Mc_s1600_Physical+Sciences,+Mathematics+and+Engineering-majors.svg.png" width="320"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-HS67EjH3MBw_U0HS16RWYhI_AAAAAAAAGmg_fJTIy2vhs64_s1600_Physical+Sciences%252C+Mathematics+and+Engineering-faculty.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/3.bp.blogspot.com_-HS67EjH3MBw_U0HS16RWYhI_AAAAAAAAGmg_fJTIy2vhs64_s1600_Physical+Sciences%252C+Mathematics+and+Engineering-faculty.svg.png" width="320"/></a></div>
<br/>
Biological Sciences and Health<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-6a24UiCR57k_U0HS-DFMkRI_AAAAAAAAGnA_ZtZWTLa7N8Y_s1600_Biological+Sciences+and+Health-majors.svg.png" imageanchor="1" ><img border="0" height="182" src="/images/blogger_images/4.bp.blogspot.com_-6a24UiCR57k_U0HS-DFMkRI_AAAAAAAAGnA_ZtZWTLa7N8Y_s1600_Biological+Sciences+and+Health-majors.svg.png" width="320"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-UQP1ST7BeKM_U0HS-Pa9OmI_AAAAAAAAGm8_2WykQkhbB4Q_s1600_Biological+Sciences+and+Health-faculty.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/4.bp.blogspot.com_-UQP1ST7BeKM_U0HS-Pa9OmI_AAAAAAAAGm8_2WykQkhbB4Q_s1600_Biological+Sciences+and+Health-faculty.svg.png" width="320"/></a></div>
<br/>
Social Sciences<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-zCkSPBDiIVA_U0HS-178WzI_AAAAAAAAGnQ_73Fnf2TrHV0_s1600_Social+Sciences-majors.svg.png" imageanchor="1" ><img border="0" height="182" src="/images/blogger_images/4.bp.blogspot.com_-zCkSPBDiIVA_U0HS-178WzI_AAAAAAAAGnQ_73Fnf2TrHV0_s1600_Social+Sciences-majors.svg.png" width="320"/></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-XqDGiuVZi_Y_U0HS-pvUn5I_AAAAAAAAGnI_pdnibLdci9w_s1600_Social+Sciences-faculty.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/4.bp.blogspot.com_-XqDGiuVZi_Y_U0HS-pvUn5I_AAAAAAAAGnI_pdnibLdci9w_s1600_Social+Sciences-faculty.svg.png" width="320"/></a></div>
<br/>
<br/>
Humanities and Arts<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-NocvMsnOvPw_U0HS-vaJRkI_AAAAAAAAGnU_5M0TARxL9no_s1600_Humanities+and+Arts-majors.svg.png" imageanchor="1" ><img border="0" height="182" src="/images/blogger_images/1.bp.blogspot.com_-NocvMsnOvPw_U0HS-vaJRkI_AAAAAAAAGnU_5M0TARxL9no_s1600_Humanities+and+Arts-majors.svg.png" width="320"/></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-RqKYkhbGyI8_U0HS95_XDaI_AAAAAAAAGm0_LdRWvFsCyls_s1600_Humanities+and+Arts-faculty.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/4.bp.blogspot.com_-RqKYkhbGyI8_U0HS95_XDaI_AAAAAAAAGm0_LdRWvFsCyls_s1600_Humanities+and+Arts-faculty.svg.png" width="320"/></a></div>
<br/>
Highest scoring majors in each area<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-jK_laWGXNCs_U0HdbjuBuQI_AAAAAAAAGoQ__u6vrA_ajyU_s1600_top-majors.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/3.bp.blogspot.com_-jK_laWGXNCs_U0HdbjuBuQI_AAAAAAAAGoQ__u6vrA_ajyU_s1600_top-majors.svg.png" width="320"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-svPjq-rOAxU_U0HjnyO4kwI_AAAAAAAAGog_UqVXyPj6z3w_s1600_percent-admitted-top.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/3.bp.blogspot.com_-svPjq-rOAxU_U0HjnyO4kwI_AAAAAAAAGog_UqVXyPj6z3w_s1600_percent-admitted-top.png" width="320"/></a></div>
<br/>
Changes in median admission scores from exam to exam (first differences)<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-7z8jZsCxVmQ_U0HUF0a-UqI_AAAAAAAAGnc_uRsbct3d56U_s1600_change-in-trend.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/1.bp.blogspot.com_-7z8jZsCxVmQ_U0HUF0a-UqI_AAAAAAAAGnc_uRsbct3d56U_s1600_change-in-trend.svg.png" width="320"/></a></div>
Median scores each year<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-3YgR1uu5X2Q_U0HU4hV2hLI_AAAAAAAAGnk_6RYzSWUSrfQ_s1600_median-admit.svg.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/1.bp.blogspot.com_-3YgR1uu5X2Q_U0HU4hV2hLI_AAAAAAAAGnk_6RYzSWUSrfQ_s1600_median-admit.svg.png" width="320"/></a></div>
<br/>
(a standard deviation is 17 points)<br/>
<br/>
One big problem with the admission process at the <span class="caps">UNAM</span> is that it doesn’t use <a href="http://en.wikipedia.org/wiki/Stable_marriage_problem">Gale-Shapley</a> and thus students have an incentive to not reveal their true preferences:<br/>
<br/>
Imagine a student who is deciding between studying <i>ingeniería mecatrónica</i> and<i> ingeniería mecánica</i>, because mechatronics is very hard to get into, and students only get to apply to one major at each exam, he decides to list mechanical engineering as his choice even when there was a chance (albeit not as big) that he would have been admitted to mechatronics.<br/>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.diegovalle.net/charts/unam/wasted.html" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="213" src="/images/blogger_images/1.bp.blogspot.com_-nzYPzDdZQGQ_U0HdAmOf-zI_AAAAAAAAGoI_ikXUBkJOo6s_s1600_mecatronica.svg.png" width="320"/></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the chart to visit the interactive version</td></tr>
</tbody></table>
<br/>
Another consequence of not using Gale-Shapley is that <b>some students who do list their true preference are rejected in favor of lower scoring students</b> (this is probably a really big deal).<br/>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="http://www.diegovalle.net/charts/unam/wasted.html" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="213" src="/images/blogger_images/3.bp.blogspot.com_-eh_wRlVfro0_U0Hc19TdSuI_AAAAAAAAGoA_gC8C0dI6sD4_s1600_rejected-area.svg.png" width="320"/></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px;">Click on the chart to visit the interactive version<br/>
<div>
<br/></div>
</td></tr>
</tbody></table>
Imagine a student who lists his or her true preference but who would be willing to entertain studying at an alternative campus with a lower admission score (international relations at <span class="caps">CU</span> vs international relations at <span class="caps">FES</span> Aragón) or a similar major with lower admittance requirements (international relations vs political science for example) who is rejected from his first choice but obtains a test score higher than the minimum requirement for his alternative.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-AzHg0DKTJZM_U0HaOjR06NI_AAAAAAAAGn0_tU1ZxSjTqo4_s1600_percent-admit.svg.png" imageanchor="1" ><img border="0" height="200" src="/images/blogger_images/3.bp.blogspot.com_-AzHg0DKTJZM_U0HaOjR06NI_AAAAAAAAGn0_tU1ZxSjTqo4_s1600_percent-admit.svg.png" width="320"/></a></div>
We can see in the above chart how the percentage of students admitted increases at the lower requirement campuses during the June exam, but there is no such increase at the main <span class="caps">CU</span> campus. This is probably a consequence of students who had been rejected after the February exam having another go at being admitted at the lower requirement satellite campuses.<br/>
<br/>
The easiest way to remedy this would be to copy the <a href="http://blog.diegovalle.net/2013/07/the-best-high-schools-in-mexico-city.html"><span class="caps">COMIPEMS</span></a> exam —which the <span class="caps">UNAM</span> helped design— and allow students to list more than one major/campus when applying. Obviously there are a lot of variations and complications the <span class="caps">UNAM</span> could use to make its admission process better, for example they could start admitting students from different areas than their first choice major if they had really high test scores. I’m sure the <strike>applied math and computing</strike> international relations students are up to the task of designing an admittance mechanism that satisfies Gale-Shapley.<br/>
<br/>
There’s also a positive correlation between average test scores and the starting salaries of university graduates (of any university in Mexico City, not just the <span class="caps">UNAM</span>) in a poll conducted by Reforma in Mexico City.<br/>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-gSA--D5fK5g_U0H_MmUgySI_AAAAAAAAGo4_SUCFV_z7LEs_s1600_score_vs_salary.png" imageanchor="1" ><img border="0" height="213" src="/images/blogger_images/2.bp.blogspot.com_-gSA--D5fK5g_U0H_MmUgySI_AAAAAAAAGo4_SUCFV_z7LEs_s1600_score_vs_salary.png" width="320"/></a></div>
<br/>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br/>
<span class="caps">P.S.</span> I bet the <a href="http://www.diegovalle.net/charts/unam/treemap-unam.html">Escuela Nacional de Artes Plásticas</a> is full of <a href="http://www.npr.org/blogs/money/2014/03/18/289013884/who-had-richer-parents-doctors-or-arists">rich kids</a><br/>
<span class="caps">P.P.S.</span> Visit the <a href="http://www.diegovalle.net/charts/unam/scores.html">companion website</a> full of interactive charts<br/>
<span class="caps">P.P.P.S.</span> <a href="https://github.com/diegovalle/unam">Source code</a><br/>
<div>
<span style="color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"> </span></span></div>
<div>
<span style="color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"> </span></span></div>
<div>
</div>
<div style="clear: both;"></div>
</div>Interactive map of the drug war in Mexico - 20122014-01-07T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2014-01-07:2014/01/interactive-map-of-drug-war-in-mexico-2014.html<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.diegovalle.net/narcomap" imageanchor="1"><img border="0" src="/images/blogger_images/2.bp.blogspot.com_-y5RwP2K6PoQ_UstuYtWXYOI_AAAAAAAAGjs_qXHtaJTjALI_s1600_Map+of+the+Drug+War+in+Mexico+(18).png" height="251" width="400" /></a></div>
<p>It’s that time of the year again when I update the <a href="http://www.diegovalle.net/narcomap">interactive map of the drug war in Mexico</a>. The map now uses 30 day months to calculate homicide rates and the new <span class="caps">CONAPO</span> population estimates. As usual there is also a <a href="http://www.diegovalle.net/narcomapa">Spanish version</a>. All deaths registered without a date of occurrence were assumed to have occurred in the same month they were registered and all deaths without a municipio of occurrence were assumed to have taken place where they were registered. Various events are worth checking out:
<!--more-->
<ul>
<li><a href="http://www.diegovalle.net/narcomap#city=Polygon&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false&polygon=-102.9638671875+23.725011735951796%2C-103.5791015625+22.350075806124867%2C-102.65625+21.69826549685252%2C-101.6015625+22.998851594142923%2C-102.9638671875+23.725011735951796">Zacatecas/Fresnillo</a></li>
<li><a href="http://www.diegovalle.net/narcomap#city=Nuevo+Laredo&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false">The increase in violence in Nuevo Laredo</a>, which proved to be much <a href="http://www.lmtonline.com/articles/2012/09/17/front/news/doc5057dd74c282f329288134.txt">worse than thought </a></li>
<li><a href="http://www.diegovalle.net/narcomap#city=San+Fernando%2C+Tamps&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false">San Fernando</a></li>
<li><a href="http://www.diegovalle.net/narcomap#city=Polygon&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=7&homtype=INEGI&clat=20.74954939679734&clong=-100.5479736328125&statadj=true&names=true&polygon=-103.20556640625+20.117839630491634%2C-102.908935546875+19.818390093844958%2C-102.052001953125+20.29311344754411%2C-102.1728515625+20.68418377935239%2C-103.20556640625+20.117839630491634">The Michoacán/Jalisco border</a> (where a mass grave with over 60 bodies was recently found)</li>
<li><a href="http://www.diegovalle.net/narcomap#city=Polygon&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false&polygon=-118.0810546875+33.7243396617476%2C-119.1796875+31.541089879585808%2C-107.2705078125+29.764377375163125%2C-103.7548828125+28.69058765425071%2C-103.359375+32.99023555965106%2C-118.0810546875+33.7243396617476">Western border</a> vs <a href="http://www.diegovalle.net/narcomap#city=Polygon&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false&polygon=-101.4697265625+30.14512718337613%2C-102.392578125+28.536274512989912%2C-98.5693359375+24.44714958973082%2C-96.416015625+24.287026865376447%2C-95.9765625+26.58852714730864%2C-101.4697265625+30.14512718337613">Eastern border</a></li>
<li>More bodies from the <a href="http://www.diegovalle.net/narcomap#city=Durango%2C+Dgo&start=2012-01-15&end=2012-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=true&names=false">Durango mass grave</a>s that apparently were not reported</li>
<li><a href="http://www.diegovalle.net/narcomap#city=All+of+M%C3%A9xico&start=2006-12-15&end=2012-11-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=5&homtype=INEGI&clat=23.61796278994952&clong=-95.02734375&statadj=false&names=false">Homicides for the whole sexenio</a></li>
</ul>
For the adjusted homicide data I did the following:</p>
<p>I again classified all deaths of unknown intent into accidents, suicides and homicides based on the age, sex of the victim and injury mechanism by which the death occurred. The method I used is similar to the one I used in my <a href="http://blog.diegovalle.net/2012/07/machine-learning-for-better-homicide.html">Juarez post</a> (with a penalized regression for Sinaloa and knn for the rest of Mexico). For example, if someone told you to guess the intent of the death of a 70 year old woman who died in Merida by motor vehicle, you’d probably guess it was an accident. If you had to guess the intent of the death of a young male in Acapulco who died by firearm, you’d probably think it was an homicide.
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-U_plDPotY5Y_UrYzp_RrKXI_AAAAAAAAGjY_yNEk_zOIpRE_s1600_sen-spe.png" imageanchor="1" ><br class="Apple-interchange-newline" /><img border="0" src="/images/blogger_images/4.bp.blogspot.com_-U_plDPotY5Y_UrYzp_RrKXI_AAAAAAAAGjY_yNEk_zOIpRE_s1600_sen-spe.png" height="346" width="400" /></a></div></p>
<div>
</div>
<p>I also recoded all deaths by legal intervention as homicides in the adjusted version since it seems legal intervention deaths are not always classified correctly (the <a href="http://mexico.cnn.com/nacional/2010/09/16/al-menos-19-personas-mueren-en-enfrentamientos-en-nl-y-tamaulipas">19 deaths from the shootout</a> between the army and the narcos in <a href="http://www.diegovalle.net/mapa-guerra-narco.html#city=Polygon&start=2010-01-15&end=2010-12-15&mariguana=true&poppy=false&meth=false&cocaine=false&zoom=9&homtype=INEGI&clat=26.050476281176586&clong=-98.817626953125&statadj=false&names=true&polygon=-99.5965576171875+26.256472923285344%2C-99.4427490234375+26.148041726002866%2C-99.06097412109375+26.44844313751643%2C-99.13787841796875+26.539394329017032%2C-99.5965576171875+26.256472923285344">General Treviño and Mier were recorded as homicides</a>).</p>
<p>The problems with the data in the <a href="http://blog.diegovalle.net/2012/09/more-errors-in-mexican-mortality.html">Federal District</a> and <a href="http://blog.diegovalle.net/2012/12/how-mexican-state-ended-up-with-more.html">Sinaloa</a> were also corrected.</p>
<p>Since firearm accidents in Baja California went from 6 in 2006 to a 100 in 2007 and again to 6 in 2008 I reclassified all firearm accidents as if their intent were unknown in 2007.</p>
<p>I also added the mass grave in Taxco and the one in San Fernando since they either don’t appear or are incomplete in the dataset from the <span class="caps">INEGI</span>.</p>
<p><span class="caps">P.S.</span> You can download a csv with the data from the <a href="http://www.diegovalle.net/projects.html#url=%23datasets">projects page</a> </p>Changes in homicide rates2013-12-18T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2013-12-18:2013/12/changes-in-homicide-rates.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-Ss28AOrxjlM_UrEPajK4ieI_AAAAAAAAGfo_Y7-ccrj1tFk_s1600_change2011-2012.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-Ss28AOrxjlM_UrEPajK4ieI_AAAAAAAAGfo_Y7-ccrj1tFk_s640_change2011-2012.png" width="532"/></a></div>
More examples of using the <a href="https://github.com/diegovalle/mxmortalitydb">mxmortalitydb</a> package! Changes and trends in homicide rates in the most violent metro areas or big municipios. There was a big increase in violence in Nuevo Laredo. For comparison the homicide rate in Chicago (metro area) was 8.2.<br/>
<style>
pre {overflow-x:hidden;padding:0;}
</style><br/>
<div class="markdown-here-wrapper" data-md-original="%3Cp%3ELook%2C%20another%20example%20of%20using%20the%20%5Bmxmortalitydb%5D(https%3A%2F%2Fgithub.com%2Fdiegovalle%2Fmxmortalitydb)%20package!%20Changes%20and%20trend%20in%20homicide%20rates%20in%20the%20most%20violent%20metro%20areas%20or%20big%20municipios%20(note%20the%20log%20scales).%20For%20comparison%20the%20homicide%20rate%20in%20Chicago%20(metro%20area)%20was%208.2%3Cbr%3E%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3Elibrary(mxmortalitydb)%3Cbr%3Elibrary(stringr)%3Cbr%3Elibrary(plyr)%3Cbr%3Elibrary(ggplot2)%3Cbr%3Elibrary(grid)%26nbsp%3B%20%23%23%20needed%20for%20arrow%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3EplotMetro%20%26lt%3B-%20function(metro.name%2C%20metro.areas)%20%7B%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Plot%20the%20homicide%20counts%20in%20a%20metro%20area%20or%20municipio%20metro.name%20-%20name%20of%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20the%20metro%20area%20to%20plot%20metro.areas%20-%20data%20frame%20containing%20a%20list%20of%20metro%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20areas%20in%20the%20same%20format%20as%20the%20metro.area%20dataframe%20from%20mxmortalitydb%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20data.frame%20metro.areas%20contains%20the%202010%20CONAPO%20metro%20areas%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20merge(injury.intent%2C%20metro.areas%2C%20by.x%20%3D%20c(%22state_reg%22%2C%20%22mun_reg%22)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20by.y%20%3D%20c(%22state_code%22%2C%20%22mun_code%22))%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Yearly%20homicides%20in%20Mexico%20City%2C%20by%20state%20of%20registration%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df2%20%26lt%3B-%20ddply(subset(df%2C%20metro_area%20%3D%3D%20metro.name%20%26amp%3B%20intent.imputed%20%3D%3D%20%22Homicide%22)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.(year_reg)%2C%20summarise%2C%20count%20%3D%20length(state_reg))%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ggplot(df2%2C%20aes(year_reg%2C%20count))%20%2B%20geom_line()%20%2B%20labs(title%20%3D%20str_c(%22Homicides%20(plus%20deaths%20of%20unknown%20intent%20classified%20as%20homicide)%20in%5Cn%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20metro.name))%20%2B%20ylim(0%2C%20max(df2%24count))%20%2B%20ylab(%22homicide%20count%22)%20%2B%20xlab(%22year%20of%20registration%22)%20%2B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20theme_bw()%3Cbr%3E%7D%3Cbr%3E%3Cbr%3EplotChanges%20%26lt%3B-%20function(df%2C%20metro.areas%2C%20country.rate%2C%20years)%20%7B%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Plot%20of%20rates%20and%20trends%20df%20-%20injury.intent%20dataframr%20metro.areas%20-%20data%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20frame%20containing%20a%20list%20of%20metro%20areas%20in%20the%20same%20format%20as%20the%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20metro.area%20dataframe%20from%20mxmortalitydb%20country.rate%20-%20rate%20to%20show%20as%20a%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20gray%20dotted%20line%20years%20-%20start%20and%20end%20year%20to%20compare%20changes%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Where%20the%20municipio%20where%20the%20death%20occurred%20is%20unknown%20use%20the%20municipio%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20where%20it%20was%20registered%20as%20place%20of%20occurrance%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%5Bdf%24mun_occur_death%20%3D%3D%20999%2C%20%5D%24mun_occur_death%20%26lt%3B-%20df%5Bdf%24mun_occur_death%20%3D%3D%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20999%2C%20%5D%24mun_reg%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Counts%20of%20homicide%20by%20state%20and%20municipio%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20ddply(subset(df%2C%20year_reg%20%25in%25%20years%20%26amp%3B%20intent.imputed%20%3D%3D%20%22Homicide%22)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.(state_occur_death%2C%20mun_occur_death%2C%20year_reg)%2C%20summarise%2C%20count%20%3D%20length(state_reg))%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Merge%20the%20counts%20with%20our%20fake%20metro%20areas%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20merge(df%2C%20metro.areas%2C%20by.x%20%3D%20c(%22state_occur_death%22%2C%20%22mun_occur_death%22)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20by.y%20%3D%20c(%22state_code%22%2C%20%22mun_code%22))%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Now%20get%20the%20counts%20by%20metro%20area%20(which%20may%20contain%20more%20than%20one%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20municipio)%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20ddply(df%2C%20.(metro_area%2C%20year_reg)%2C%20summarise%2C%20count%20%3D%20sum(count)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20population%20%3D%20sum(mun_population_2010)%2C%20rate%20%3D%20count%2Fpopulation%20*%2010%5E5)%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20We%20are%20only%20interesed%20if%20the%20metro%20area%20at%20some%20time%20had%20a%20homicide%20rate%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20of%20at%20least%2015%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20subset(df%2C%20metro_area%20%25in%25%20subset(df%2C%20rate%20%26gt%3B%2015)%24metro_area)%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Make%20sure%20the%20dataframe%20is%20ordered%20by%20metro%20and%20year%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%20%26lt%3B-%20df%5Border(df%24metro_area%2C%20df%24year_reg)%2C%20%5D%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Order%20the%20chart%20by%20homicide%20rate%20in%202012%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20df%24metro_area%20%26lt%3B-%20reorder(df%24metro_area%2C%20df%24rate%2C%20function(x)%20x%5B%5B2%5D%5D)%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%23%20Data%20frame%20for%20the%20arrow%20structure%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20arrows%20%26lt%3B-%20ddply(df%2C%20.(metro_area)%2C%20summarise%2C%20start%20%3D%20rate%5B1%5D%2C%20end%20%3D%20rate%5B2%5D%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20metro_area%20%3D%20metro_area%5B1%5D%2C%20change%20%3D%20ifelse(rate%5B1%5D%20%26gt%3B%3D%20rate%5B2%5D%2C%20%22decrease%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22increase%22))%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ggplot(df%2C%20aes(rate%2C%20metro_area%2C%20group%20%3D%20as.factor(year_reg)%2C%20color%20%3D%20as.factor(year_reg)))%20%2B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20geom_point(aes(size%20%3D%20log(count)))%20%2B%20labs(title%20%3D%20%22Homicide%20(plus%20deaths%20of%20unknown%20intent%20classified%20as%20homicide)%20rates%20and%20trends%22)%20%2B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20scale_size(%22number%5Cnof%5Cnhomicides%22%2C%20breaks%20%3D%20c(log(50)%2C%20log(500)%2C%20log(3000))%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20labels%20%3D%20c(50%2C%20500%2C%203000))%20%2B%20geom_segment(data%20%3D%20arrows%2C%20aes(x%20%3D%20start%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20y%20%3D%20metro_area%2C%20xend%20%3D%20end%2C%20yend%20%3D%20metro_area%2C%20group%20%3D%20change%2C%20color%20%3D%20change)%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20arrow%20%3D%20arrow(length%20%3D%20unit(0.3%2C%20%22cm%22))%2C%20alpha%20%3D%200.8)%20%2B%20scale_color_manual(%22year%5Cnand%5Cntrend%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20values%20%3D%20c(%22gray%22%2C%20%22black%22%2C%20%22blue%22%2C%20%22red%22))%20%2B%20ylab(%22metro%20area%20or%20municipio%22)%20%2B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20xlab(%22homicide%20rate%22)%20%2B%20%23%20scale_x_log10()%2B%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20geom_vline(xintercept%20%3D%20country.rate%2C%20linetype%20%3D%202%2C%20color%20%3D%20%22%23666666%22)%20%2B%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20annotate(%22text%22%2C%20y%20%3D%20%22Tapachula%22%2C%20x%20%3D%2025%2C%20label%20%3D%20%22country%5Cnaverage%5Cn2012%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20hjust%20%3D%20-0.1%2C%20size%20%3D%204%2C%20color%20%3D%20%22%23666666%22)%20%2B%20theme_bw()%3Cbr%3E%7D%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3E%23%23%20Let's%20treat%20the%20big%20municipalities%20which%20are%20not%20part%20of%20a%20metro%20area%20as%3Cbr%3E%23%23%20if%20they%20were%20one%20rename%20big.municipios%20to%20merge%20with%20metro.areas%3Cbr%3Ebig.municipios2%20%26lt%3B-%20big.municipios%3Cbr%3Enames(big.municipios2)%20%26lt%3B-%20c(%22state_code%22%2C%20%22mun_code%22%2C%20%22mun_population_2010%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22metro_area%22)%3Cbr%3Emetro.areas.fake%20%26lt%3B-%20rbind.fill(metro.areas%2C%20big.municipios2)%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E%3Cbr%3EAnd%20changes%20from%202006%20to%202012%3A%3Cbr%3E%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3EplotChanges(injury.intent%2C%20metro.areas.fake%2C%2024.5%2C%20c(2011%2C%202012))%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-4%5D(figure%2Funnamed-chunk-41.png)%20%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3Eggsave(%22change2011-2012.svg%22%2C%20dpi%20%3D%20100%2C%20width%20%3D%208%2C%20height%20%3D%209.6)%3Cbr%3EplotChanges(injury.intent%2C%20metro.areas.fake%2C%2024.5%2C%20c(2006%2C%202012))%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-4%5D(figure%2Funnamed-chunk-42.png)%20%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3Eggsave(%22change2006-2012.svg%22%2C%20dpi%20%3D%20100%2C%20width%20%3D%208%2C%20height%20%3D%209.6)%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E%3Cbr%3EInteresting%20that%20Tijuana%20had%20about%20the%20same%20homicide%20rate%20in%202012%20as%20in%202006.%20The%20rest%20of%20the%20violent%20metro%20areas%2Fbig%20municipios%20which%20saw%20decreases%20are%20in%20Michoac%C3%A1n.%20Sadly%2C%20it%20doesn%E2%80%99t%20look%20like%20pattern%20will%20hold%20in%202013%20(according%20to%20%5Bcrimenmexico%5D(http%3A%2F%2Fcrimenmexico.diegovalle.net%2F)%20Michoac%C3%A1n%20is%20experiencing%20a%20surge%20of%20violence%3Cbr%3E%3Cbr%3EDo%20note%20that%20the%20charts%20were%20made%20using%20the%202010%20population%20according%20to%20the%20CONAPO%20that%20comes%20with%20mxmortalitydb%2C%20so%20homicides%20in%202012%20were%20overestimated%20by%20a%20little%20bit%20and%20underestimated%20by%20a%20little%20bit%20in%202006.%20Also%20rather%20%3Cbr%3E%3Cbr%3E%3Cbr%3E%3Cbr%3E%60%60%60r%3Cbr%3Ell%20%26lt%3B-%20list(%22Acapulco%22%2C%20%22Nuevo%20Laredo%22%2C%20%22La%20Laguna%22%2C%20%22Chihuahua%22%2C%20%22Tecom%C3%A1n%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Ju%C3%A1rez%22%2C%20%22Culiac%C3%A1n%22%2C%20%22Victoria%22%2C%20%22Hidalgo%20del%20Parral%22%2C%20%22Zihuatanejo%20de%20Azueta%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22El%20Mante%22%2C%20%22Ciudad%20Valles%22%2C%20%22Ciudad%20Valles%22%2C%20%22Durango%22%2C%20%22Cuernavaca%22%2C%20%22Zacatecas-Guadalupe%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Monterrey%22%2C%20%22Piedras%20Negras%22%2C%20%22Mazatl%C3%A1n%22%2C%20%22Veracruz%22%2C%20%22Tijuana%22%2C%20%22Guadalajara%22%2C%20%3Cbr%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Tepic%22%2C%20%22Coatzacoalcos%22)%3Cbr%3Enames(ll)%20%26lt%3B-%20ll%26nbsp%3B%20%23%20make%20lapply%20print%20the%20names%20of%20the%20metro%20areas%3Cbr%3Elapply(ll%2C%20plotMetro%2C%20metro.areas.fake)%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%24Acapulco%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-51.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Nuevo%20Laredo%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-52.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60La%20Laguna%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-53.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Chihuahua%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-54.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Tecom%C3%A1n%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-55.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Ju%C3%A1rez%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-56.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Culiac%C3%A1n%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-57.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Victoria%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-58.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Hidalgo%20del%20Parral%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-59.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Zihuatanejo%20de%20Azueta%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-510.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60El%20Mante%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-511.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Ciudad%20Valles%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-512.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Ciudad%20Valles%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-513.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Durango%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-514.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Cuernavaca%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-515.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Zacatecas-Guadalupe%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-516.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Monterrey%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-517.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24%60Piedras%20Negras%60%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-518.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Mazatl%C3%A1n%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-519.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Veracruz%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-520.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Tijuana%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-521.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Guadalajara%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-522.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Tepic%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-523.png)%20%3Cbr%3E%3Cbr%3E%60%60%60%3Cbr%3E%23%23%20%3Cbr%3E%23%23%20%24Coatzacoalcos%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3E!%5Bplot%20of%20chunk%20unnamed-chunk-5%5D(figure%2Funnamed-chunk-524.png)%20%3Cbr%3E%3Cbr%3E%3Cbr%3ECheck%20out%20the%20%5Bsource%20code%5D(https%3A%2F%2Fgist.github.com%2Fdiegovalle%2F7998868)%20as%20an%20R%20markdown%20file.%3Cbr%3E%3C%2Fp%3E" data-md-url="http://www.blogger.com/blogger.g?blogID=3280550716273637581#editor/target=post;postID=7831142791700560024" id="markdown-here-wrapper-626200">
<div style="margin: 1.2em 0px ! important;">
<a name="more"></a></div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;"><span class="keyword" style="color: #333333; font-weight: bold;">library</span>(mxmortalitydb)
<span class="keyword" style="color: #333333; font-weight: bold;">library</span>(stringr)
<span class="keyword" style="color: #333333; font-weight: bold;">library</span>(plyr)
<span class="keyword" style="color: #333333; font-weight: bold;">library</span>(ggplot2)
<span class="keyword" style="color: #333333; font-weight: bold;">library</span>(grid) <span class="comment" style="color: #999988; font-style: italic;">## needed for arrow</span></code></pre>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">plotMetro <- <span class="keyword" style="color: #333333; font-weight: bold;">function</span>(metro.name, metro.areas) {
<span class="comment" style="color: #999988; font-style: italic;">## Plot the homicide counts in a metro area or municipio metro.name - name of</span>
<span class="comment" style="color: #999988; font-style: italic;">## the metro area to plot metro.areas - data frame containing a list of metro</span>
<span class="comment" style="color: #999988; font-style: italic;">## areas in the same format as the metro.area dataframe from mxmortalitydb</span>
<span class="comment" style="color: #999988; font-style: italic;">## data.frame metro.areas contains the 2010 CONAPO metro areas</span>
df <- merge(injury.intent, metro.areas, by.x = c(<span class="string" style="color: #dd1144;">"state_reg"</span>, <span class="string" style="color: #dd1144;">"mun_reg"</span>),
by.y = c(<span class="string" style="color: #dd1144;">"state_code"</span>, <span class="string" style="color: #dd1144;">"mun_code"</span>))
<span class="comment" style="color: #999988; font-style: italic;">## Yearly homicides in Mexico City, by state of registration</span>
df2 <- ddply(subset(df, metro_area == metro.name & intent.imputed == <span class="string" style="color: #dd1144;">"Homicide"</span>),
.(year_reg), summarise, count = length(state_reg))
ggplot(df2, aes(year_reg, count)) + geom_line() + labs(title = str_c(<span class="string" style="color: #dd1144;">"Homicides (plus deaths of unknown intent classified as homicide) in\n"</span>,
metro.name)) + ylim(<span class="number" style="color: #009999;">0</span>, max(df2$count)) + ylab(<span class="string" style="color: #dd1144;">"homicide count"</span>) + xlab(<span class="string" style="color: #dd1144;">"year of registration"</span>) +
theme_bw()
}
plotChanges <- <span class="keyword" style="color: #333333; font-weight: bold;">function</span>(df, metro.areas, country.rate, years) {
<span class="comment" style="color: #999988; font-style: italic;">## Plot of rates and trends df - injury.intent dataframr metro.areas - data</span>
<span class="comment" style="color: #999988; font-style: italic;">## frame containing a list of metro areas in the same format as the</span>
<span class="comment" style="color: #999988; font-style: italic;">## metro.area dataframe from mxmortalitydb country.rate - rate to show as a</span>
<span class="comment" style="color: #999988; font-style: italic;">## gray dotted line years - start and end year to compare changes</span>
<span class="comment" style="color: #999988; font-style: italic;">## Where the municipio where the death occurred is unknown use the municipio</span>
<span class="comment" style="color: #999988; font-style: italic;">## where it was registered as place of occurrance</span> </code><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;"> df[df$mun_occur_death == <span class="number" style="color: #009999;">999</span>, ]$mun_occur_death <- df[df$mun_occur_death ==
<span class="number" style="color: #009999;">999</span>, ]$mun_reg
<span class="comment" style="color: #999988; font-style: italic;">## Counts of homicide by state and municipio</span>
df <- ddply(subset(df, year_reg %<span class="keyword" style="color: #333333; font-weight: bold;">in</span>% years & intent.imputed == <span class="string" style="color: #dd1144;">"Homicide"</span>),
.(state_occur_death, mun_occur_death, year_reg), summarise, count = length(state_reg))
<span class="comment" style="color: #999988; font-style: italic;">## Merge the counts with our fake metro areas</span>
df <- merge(df, metro.areas, by.x = c(<span class="string" style="color: #dd1144;">"state_occur_death"</span>, <span class="string" style="color: #dd1144;">"mun_occur_death"</span>),
by.y = c(<span class="string" style="color: #dd1144;">"state_code"</span>, <span class="string" style="color: #dd1144;">"mun_code"</span>))
<span class="comment" style="color: #999988; font-style: italic;">## Now get the counts by metro area (which may contain more than one</span>
<span class="comment" style="color: #999988; font-style: italic;">## municipio)</span>
df <- ddply(df, .(metro_area, year_reg), summarise, count = sum(count),
population = sum(mun_population_2010), rate = count/population * <span class="number" style="color: #009999;">10</span>^<span class="number" style="color: #009999;">5</span>)
<span class="comment" style="color: #999988; font-style: italic;">## We are only interesed if the metro area at some time had a homicide rate</span>
<span class="comment" style="color: #999988; font-style: italic;">## of at least 15</span>
df <- subset(df, metro_area %<span class="keyword" style="color: #333333; font-weight: bold;">in</span>% subset(df, rate > <span class="number" style="color: #009999;">15</span>)$metro_area)
<span class="comment" style="color: #999988; font-style: italic;">## Make sure the dataframe is ordered by metro and year</span>
df <- df[order(df$metro_area, df$year_reg), ]
<span class="comment" style="color: #999988; font-style: italic;">## Order the chart by homicide rate in 2012</span>
df$metro_area <- reorder(df$metro_area, df$rate, <span class="keyword" style="color: #333333; font-weight: bold;">function</span>(x) x[[<span class="number" style="color: #009999;">2</span>]])
<span class="comment" style="color: #999988; font-style: italic;">## Data frame for the arrow structure</span>
arrows <- ddply(df, .(metro_area), summarise, start = rate[<span class="number" style="color: #009999;">1</span>], end = rate[<span class="number" style="color: #009999;">2</span>],
metro_area = metro_area[<span class="number" style="color: #009999;">1</span>], change = ifelse(rate[<span class="number" style="color: #009999;">1</span>] >= rate[<span class="number" style="color: #009999;">2</span>], <span class="string" style="color: #dd1144;">"decrease"</span>,
<span class="string" style="color: #dd1144;">"increase"</span>))
ggplot(df, aes(rate, metro_area, group = as.factor(year_reg), color = as.factor(year_reg))) +
geom_point(aes(size = log(count))) + labs(title = <span class="string" style="color: #dd1144;">"Homicide (plus deaths of unknown intent classified as homicide) rates and trends"</span>) +
scale_size(<span class="string" style="color: #dd1144;">"number\nof\nhomicides"</span>, breaks = c(log(<span class="number" style="color: #009999;">50</span>), log(<span class="number" style="color: #009999;">500</span>), log(<span class="number" style="color: #009999;">3000</span>)),
labels = c(<span class="number" style="color: #009999;">50</span>, <span class="number" style="color: #009999;">500</span>, <span class="number" style="color: #009999;">3000</span>)) + geom_segment(data = arrows, aes(x = start,
y = metro_area, xend = end, yend = metro_area, group = change, color = change),
arrow = arrow(length = unit(<span class="number" style="color: #009999;">0.3</span>, <span class="string" style="color: #dd1144;">"cm"</span>)), alpha = <span class="number" style="color: #009999;">0.8</span>) + scale_color_manual(<span class="string" style="color: #dd1144;">"year\nand\ntrend"</span>,
values = c(<span class="string" style="color: #dd1144;">"gray"</span>, <span class="string" style="color: #dd1144;">"black"</span>, <span class="string" style="color: #dd1144;">"blue"</span>, <span class="string" style="color: #dd1144;">"red"</span>)) + ylab(<span class="string" style="color: #dd1144;">"metro area or municipio"</span>) +
xlab(<span class="string" style="color: #dd1144;">"homicide rate"</span>) + <span class="comment" style="color: #999988; font-style: italic;"># scale_x_log10()+</span>
geom_vline(xintercept = country.rate, linetype = <span class="number" style="color: #009999;">2</span>, color = <span class="string" style="color: #dd1144;">"#666666"</span>) +
annotate(<span class="string" style="color: #dd1144;">"text"</span>, y = <span class="string" style="color: #dd1144;">"Tapachula"</span>, x = <span class="number" style="color: #009999;">25</span>, label = <span class="string" style="color: #dd1144;">"country\naverage\n2012"</span>,
hjust = -<span class="number" style="color: #009999;">0.1</span>, size = <span class="number" style="color: #009999;">4</span>, color = <span class="string" style="color: #dd1144;">"#666666"</span>) + theme_bw()
}</code></pre>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;"><span class="comment" style="color: #999988; font-style: italic;">## Let's treat the big municipalities which are not part of a metro area as</span>
<span class="comment" style="color: #999988; font-style: italic;">## if they were one rename big.municipios to merge with metro.areas</span>
big.municipios2 <- big.municipios
names(big.municipios2) <- c(<span class="string" style="color: #dd1144;">"state_code"</span>, <span class="string" style="color: #dd1144;">"mun_code"</span>, <span class="string" style="color: #dd1144;">"mun_population_2010"</span>,
<span class="string" style="color: #dd1144;">"metro_area"</span>)
metro.areas.fake <- rbind.fill(metro.areas, big.municipios2)</code></pre>
<div style="margin: 1.2em 0px ! important;">
Changes from 2011 to 2012 and from the year before the drug war was declared to 2012:</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">plotChanges(injury.intent, metro.areas.fake, <span class="number" style="color: #009999;">24.5</span>, c(<span class="number" style="color: #009999;">2011</span>, <span class="number" style="color: #009999;">2012</span>))</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-Ss28AOrxjlM_UrEPajK4ieI_AAAAAAAAGfo_Y7-ccrj1tFk_s1600_change2011-2012.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/1.bp.blogspot.com_-Ss28AOrxjlM_UrEPajK4ieI_AAAAAAAAGfo_Y7-ccrj1tFk_s640_change2011-2012.png" width="532"/></a></div>
</div>
<code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">plotChanges(injury.intent, metro.areas.fake, <span class="number" style="color: #009999;">24.5</span>, c(<span class="number" style="color: #009999;">2006</span>, <span class="number" style="color: #009999;">2012</span>))</code> <br/>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-Mz9Tm4MI25w_UrEPn32KnZI_AAAAAAAAGfs_JO39hf5Yt94_s1600_change2006-2012.png" imageanchor="1" ><img border="0" height="640" src="/images/blogger_images/3.bp.blogspot.com_-Mz9Tm4MI25w_UrEPn32KnZI_AAAAAAAAGfs_JO39hf5Yt94_s640_change2006-2012.png" width="532"/></a></div>
</div>
Interesting that Tijuana had about the same homicide rate in 2012 as in 2006. The rest of the violent metro areas/large municipios which saw decreases are in Michoacán. Sadly, it doesn’t look like pattern will hold in 2013 (according to <a href="https://elcri.men/">crimenmexico</a> Michoacán is experiencing a surge of violence and is at a maximum)<br/>
<div style="margin: 1.2em 0px ! important;">
Do note that the charts were made using the 2010 population according to the <span class="caps">CONAPO</span> that comes with mxmortalitydb, so homicides in 2012 were overestimated by a little bit and underestimated by a little bit in 2006. Also rather than using the raw homicide numbers I adjusted them by classifying deaths of unknown intent.</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code class="language-r" style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">ll <- list(<span class="string" style="color: #dd1144;">"Acapulco"</span>, <span class="string" style="color: #dd1144;">"Nuevo Laredo"</span>, <span class="string" style="color: #dd1144;">"La Laguna"</span>, <span class="string" style="color: #dd1144;">"Chihuahua"</span>, <span class="string" style="color: #dd1144;">"Tecomán"</span>,
<span class="string" style="color: #dd1144;">"Juárez"</span>, <span class="string" style="color: #dd1144;">"Culiacán"</span>, <span class="string" style="color: #dd1144;">"Victoria"</span>, <span class="string" style="color: #dd1144;">"Hidalgo del Parral"</span>, <span class="string" style="color: #dd1144;">"Zihuatanejo de Azueta"</span>,
<span class="string" style="color: #dd1144;">"El Mante"</span>, <span class="string" style="color: #dd1144;">"Ciudad Valles"</span>, <span class="string" style="color: #dd1144;">"Ciudad Valles"</span>, <span class="string" style="color: #dd1144;">"Durango"</span>, <span class="string" style="color: #dd1144;">"Cuernavaca"</span>, <span class="string" style="color: #dd1144;">"Zacatecas-Guadalupe"</span>,
<span class="string" style="color: #dd1144;">"Monterrey"</span>, <span class="string" style="color: #dd1144;">"Piedras Negras"</span>, <span class="string" style="color: #dd1144;">"Mazatlán"</span>, <span class="string" style="color: #dd1144;">"Veracruz"</span>, <span class="string" style="color: #dd1144;">"Tijuana"</span>, <span class="string" style="color: #dd1144;">"Guadalajara"</span>,
<span class="string" style="color: #dd1144;">"Tepic"</span>, <span class="string" style="color: #dd1144;">"Coatzacoalcos"</span>)
names(ll) <- ll <span class="comment" style="color: #999988; font-style: italic;"># make lapply print the names of the metro areas</span>
lapply(ll, plotMetro, metro.areas.fake)</code></pre>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">## $Acapulco</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-ORDmlTmq2DA_UrEP6ZzOGtI_AAAAAAAAGf0_Ti1vlfehsHc_s1600_unnamed-chunk-51.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-ORDmlTmq2DA_UrEP6ZzOGtI_AAAAAAAAGf0_Ti1vlfehsHc_s320_unnamed-chunk-51.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Nuevo Laredo`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-FmTVpSWBlhU_UrEQIoEoSMI_AAAAAAAAGf8_FmzSwJhbwB8_s1600_unnamed-chunk-52.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-FmTVpSWBlhU_UrEQIoEoSMI_AAAAAAAAGf8_FmzSwJhbwB8_s320_unnamed-chunk-52.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`La Laguna`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-iQkmyWyY_YM_UrEQN4irbMI_AAAAAAAAGgE_TiE9VySgQs8_s1600_unnamed-chunk-53.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/3.bp.blogspot.com_-iQkmyWyY_YM_UrEQN4irbMI_AAAAAAAAGgE_TiE9VySgQs8_s320_unnamed-chunk-53.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><div class="separator" style="clear: both; text-align: center;">
</div>
<code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Chihuahua</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-cEQxPQmT0j8_UrEQZexn8XI_AAAAAAAAGgU_JxTNa-HXx5E_s1600_unnamed-chunk-54.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-cEQxPQmT0j8_UrEQZexn8XI_AAAAAAAAGgU_JxTNa-HXx5E_s320_unnamed-chunk-54.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Tecomán</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-i1JLpESwryM_UrEQft3L8wI_AAAAAAAAGgc_EtOlw09cITk_s1600_unnamed-chunk-55.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/3.bp.blogspot.com_-i1JLpESwryM_UrEQft3L8wI_AAAAAAAAGgc_EtOlw09cITk_s320_unnamed-chunk-55.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Juárez</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-HnhZbgMrNEQ_UrEQmwVfq0I_AAAAAAAAGgk_K5ZUk1x5YTg_s1600_unnamed-chunk-56.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-HnhZbgMrNEQ_UrEQmwVfq0I_AAAAAAAAGgk_K5ZUk1x5YTg_s320_unnamed-chunk-56.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Culiacán</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-DS8jzxkJzZo_UrEQvYsMw_I_AAAAAAAAGgs_5HVJnjR2jSY_s1600_unnamed-chunk-57.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/2.bp.blogspot.com_-DS8jzxkJzZo_UrEQvYsMw_I_AAAAAAAAGgs_5HVJnjR2jSY_s320_unnamed-chunk-57.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Victoria</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-0K1l1w8bcqg_UrEQ0Ryt1NI_AAAAAAAAGg0_wgVzYuZmpJE_s1600_unnamed-chunk-58.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/3.bp.blogspot.com_-0K1l1w8bcqg_UrEQ0Ryt1NI_AAAAAAAAGg0_wgVzYuZmpJE_s320_unnamed-chunk-58.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Hidalgo del Parral`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-pAQpdWykc5M_UrEQ6nWprWI_AAAAAAAAGg8_d6U9aQrRqec_s1600_unnamed-chunk-59.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-pAQpdWykc5M_UrEQ6nWprWI_AAAAAAAAGg8_d6U9aQrRqec_s320_unnamed-chunk-59.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Zihuatanejo de Azueta`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-ZpMr2Blfn28_UrERBIOUK1I_AAAAAAAAGhE__bi4Cl056VU_s1600_unnamed-chunk-510.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-ZpMr2Blfn28_UrERBIOUK1I_AAAAAAAAGhE__bi4Cl056VU_s320_unnamed-chunk-510.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`El Mante`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-2KdXpex_xPs_UrERHAuSMaI_AAAAAAAAGhM_YvpV6HxNH-o_s1600_unnamed-chunk-511.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-2KdXpex_xPs_UrERHAuSMaI_AAAAAAAAGhM_YvpV6HxNH-o_s320_unnamed-chunk-511.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Ciudad Valles`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-y7MR64HVGhw_UrERNawfTTI_AAAAAAAAGhU_Uk_2hpQRng4_s1600_unnamed-chunk-513.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-y7MR64HVGhw_UrERNawfTTI_AAAAAAAAGhU_Uk_2hpQRng4_s320_unnamed-chunk-513.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Durango</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-rUaryQDdEUE_UrERcEFv6NI_AAAAAAAAGhc_O6oBw2TGG9I_s1600_unnamed-chunk-514.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-rUaryQDdEUE_UrERcEFv6NI_AAAAAAAAGhc_O6oBw2TGG9I_s320_unnamed-chunk-514.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Cuernavaca</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-JPQ3Si0UIQ8_UrERiAJpFwI_AAAAAAAAGhk_1TpSCjwjMrQ_s1600_unnamed-chunk-515.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-JPQ3Si0UIQ8_UrERiAJpFwI_AAAAAAAAGhk_1TpSCjwjMrQ_s320_unnamed-chunk-515.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><div class="separator" style="clear: both; text-align: center;">
</div>
<code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Zacatecas-Guadalupe`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-x0U6mDkaeOk_UrERndD-rKI_AAAAAAAAGhs_WHJ184IjsUc_s1600_unnamed-chunk-516.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-x0U6mDkaeOk_UrERndD-rKI_AAAAAAAAGhs_WHJ184IjsUc_s320_unnamed-chunk-516.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Monterrey</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/3.bp.blogspot.com_-1qycVSFcW_M_UrERspBTJDI_AAAAAAAAGh0_wOV_TLpQv_A_s1600_unnamed-chunk-517.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/3.bp.blogspot.com_-1qycVSFcW_M_UrERspBTJDI_AAAAAAAAGh0_wOV_TLpQv_A_s320_unnamed-chunk-517.png" width="320"/></a></div>
<br/></div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $`Piedras Negras`</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-yJ7xv35EWJE_UrER4Y_S0TI_AAAAAAAAGiE_3cJl-g9rWEY_s1600_unnamed-chunk-518.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-yJ7xv35EWJE_UrER4Y_S0TI_AAAAAAAAGiE_3cJl-g9rWEY_s320_unnamed-chunk-518.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Mazatlán</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-oWaQOvtrN6o_UrER-G4qUtI_AAAAAAAAGiM_HMuwjBsREbQ_s1600_unnamed-chunk-519.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-oWaQOvtrN6o_UrER-G4qUtI_AAAAAAAAGiM_HMuwjBsREbQ_s320_unnamed-chunk-519.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Veracruz</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-dJrHpDSmWsI_UrESHa_v7oI_AAAAAAAAGiU_2rCUKULsBpA_s1600_unnamed-chunk-520.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/4.bp.blogspot.com_-dJrHpDSmWsI_UrESHa_v7oI_AAAAAAAAGiU_2rCUKULsBpA_s320_unnamed-chunk-520.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Tijuana</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-CrnEmATGcww_UrESM2wibxI_AAAAAAAAGic_SfbfxrxwWjE_s1600_unnamed-chunk-521.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/2.bp.blogspot.com_-CrnEmATGcww_UrESM2wibxI_AAAAAAAAGic_SfbfxrxwWjE_s320_unnamed-chunk-521.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Guadalajara</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/2.bp.blogspot.com_-IK_HNkEVrRA_UrESSaQL5nI_AAAAAAAAGik_noY_GC3-aVE_s1600_unnamed-chunk-522.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/2.bp.blogspot.com_-IK_HNkEVrRA_UrESSaQL5nI_AAAAAAAAGik_noY_GC3-aVE_s320_unnamed-chunk-522.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Tepic</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-EARaW-4KLCw_UrESXur4VZI_AAAAAAAAGis_2LLNVcnIf5s_s1600_unnamed-chunk-523.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/1.bp.blogspot.com_-EARaW-4KLCw_UrESXur4VZI_AAAAAAAAGis_2LLNVcnIf5s_s320_unnamed-chunk-523.png" width="320"/></a></div>
</div>
<pre style="font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; font-size: 1em; line-height: 1.2em; margin: 1.2em 0px;"><code style="background-color: #f8f8f8; background: none repeat scroll 0% 0% rgb(248, 248, 255); border-radius: 3px; border-radius: 3px; border: 1px solid rgb(204, 204, 204); border: 1px solid rgb(234, 234, 234); color: #333333; display: block ! important; display: block; display: inline; font-family: Consolas,Inconsolata,Courier,monospace; font-size: 0.85em; margin: 0px 0.15em; overflow: auto; padding: 0.5em 0.7em; padding: 0.5em; padding: 0px 0.3em; white-space: pre-wrap; white-space: pre;">##
## $Coatzacoalcos</code></pre>
<div style="margin: 1.2em 0px ! important;">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="http://www.blogger.com/blogger.g?blogID=3280550716273637581" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="/images/blogger_images/3.bp.blogspot.com_-u1hoCv0_6mY_UrESdDuUjuI_AAAAAAAAGi0_FWmreSa2Es0_s1600_unnamed-chunk-524.png" imageanchor="1" ><img border="0" height="274" src="/images/blogger_images/3.bp.blogspot.com_-u1hoCv0_6mY_UrESdDuUjuI_AAAAAAAAGi0_FWmreSa2Es0_s320_unnamed-chunk-524.png" width="320"/></a></div>
</div>
<div style="margin: 1.2em 0px ! important;">
Check out the <a href="https://gist.github.com/diegovalle/7998868">source code</a> as an R markdown file.</div>
</div>
<div style="clear: both;"></div>
</div>An R package with all injury intent deaths registered in Mexico 2004-20122013-12-17T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2013-12-17:2013/12/r-package-mexican-homicides.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
</div>
This is a data only <a href="https://github.com/diegovalle/mxmortalitydb">package</a> containing all injury intent deaths (accidents, suicides, homicides, legal interventions, and deaths of unspecified intent) registered by the <span class="caps">SSA</span>/<span class="caps">INEGI</span> from 2004 to 2012. The data source for the database is the <a href="http://www.inegi.org.mx/est/contenidos/proyectos/registros/vitales/mortalidad/default.aspx"><span class="caps">INEGI</span></a>. In addition the data was coded with the Injury Mortality Matrix provided by the <a href="http://www.cdc.gov/nchs/data/ice/icd10_transcode.pdf"><span class="caps">CDC</span></a>.<br/>
<br/>
The package is only available from github, to install:<br/>
<br/>
<span style='font-family: "Courier New",Courier,monospace;'>devtools::install_github(“diegovalle/mxmortalitydb”)</span><br/>
<br/>
be sure to visit its <a href="https://github.com/diegovalle/mxmortalitydb">github</a> page to find out more!
<div style="clear: both;"></div>
</div>Continuously updated crime information2013-09-30T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2013-09-30:2013/09/continuously-updated-crime-information.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-6ItLjBMaZ_k_Uki7ibzHHNI_AAAAAAAAGdw_4RkkPSvKglg_s1600_download.png" imageanchor="1" ><img border="0" height="265" src="/images/blogger_images/4.bp.blogspot.com_-6ItLjBMaZ_k_Uki7ibzHHNI_AAAAAAAAGdw_4RkkPSvKglg_s400_download.png" width="400"/></a></div>
I’ve put together a simple website to keep people up to date on the latest crime information. The site polls the <a href="http://www.secretariadoejecutivo.gob.mx/"><span class="caps">SESNSP</span> website</a> many times a day to see if there is new crime information, and if there is, it cleans up the data and makes it available for download.<br/>
<br/>
<a href="https://elcri.men/en/data.html">https://elcri.men/en/csv/</a> (Engish)<br/>
<a href="https://elcri.men/es/data.html">https://elcri.men/es/csv/</a> (Spanish)<br/>
<br/>
There’s also a <a href="https://elcri.men/">simple report</a> based on the data. In the future I hope to also include homicide data from the <span class="caps">INEGI</span>,<strike> and municipio population from the <span class="caps">CONAPO</span></strike> (the data now includes municipio population and information for all state level and federal crimes), so the data is bound to change at some point. If you’d like to see another crime or municipio added to the data or report feel free to contact me.<br/>
<br/>
For major updates or announcements <a href="https://twitter.com/diegovalle">follow me on twitter</a><br/>
<br/>
<span class="caps">P.S.</span> Keep in mind that the numbers refer to police reports and not number of victims.
<div style="clear: both;"></div>
</div>