<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Martin Siron, Ph.D.</title><description>Quantum Chemistry, AI4Science, Researcher</description><link>https://martinsiron.com/</link><item><title>Mapping the evolution of the most dangerous areas of Los Angeles for pedestrians and bicyclists</title><link>https://martinsiron.com/2022/11/24/mapping-the-evolution-of-the-most-dangerous-areas-of-los-angeles-for-pedestrians-and-bicyclists/</link><guid isPermaLink="true">https://martinsiron.com/2022/11/24/mapping-the-evolution-of-the-most-dangerous-areas-of-los-angeles-for-pedestrians-and-bicyclists/</guid><pubDate>Thu, 24 Nov 2022 19:30:39 GMT</pubDate><content:encoded>&lt;p&gt;I recently started biking…in Los Angeles. Los Angeles could be one of the most bike-friendly cities in the United States: it boasts plenty of annual sunshine, it has a mostly flat terrain, and quite mild weather. Unfortunately, many parts of the city lack proper bike infrastructure, making it dangerous when it comes to traffic collisions and traffic violence. In 2021, over 230 people lost their lives to the streets of Los Angeles.&lt;/p&gt;
&lt;p&gt;With this in the background, I wanted to figure out the most dangerous streets in Los Angeles. I had been following the &lt;a href=&quot;https://twitter.com/sfa_alerts&quot;&gt;Streets For All Twitter&lt;/a&gt; account for a while and knew that they had a bot which posted any traffic violence involving pedestrians or bikes. This account had records dating back to just over one year. So I started with that (&lt;a href=&quot;https://twitter.com/martin_siron/status/1573049679406940165&quot;&gt;old results here&lt;/a&gt;). I used the Twitter API to extract all of the Tweets from the bot account, and then used the Google Maps API to convert the text-based location to a series of latitude and longitude.&lt;/p&gt;
&lt;p&gt;I soon stumbled upon &lt;a href=&quot;https://data.lacity.org/Public-Safety/Traffic-Collision-Data-from-2010-to-Present/d5tf-ez2w&quot;&gt;LA City’s records&lt;/a&gt;, dating back 2010-Present. This uses MO codes to detail the accident. After converting the MO codes for vehicle collision with pedestrian, and bikes, I had all the data needed to plot all collisions:&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 800px) 800px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;800&quot; height=&quot;800&quot; src=&quot;https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_O86BA.webp&quot; srcset=&quot;https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_ZH3YQJ.webp 192w, https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_Z14rJim.webp 384w, https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_Z1YWMaG.webp 640w, https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_Z2mFcRt.webp 750w, https://martinsiron.com/_astro/overall_collisions-2.ClEBO0tC_O86BA.webp 800w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;&lt;strong&gt;Overall traffic collisions, 2010-2020&lt;/strong&gt;. &lt;em&gt;Source: LA City.&lt;/em&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;For plotting, I am using Plotly with the Mapbox API.&lt;/p&gt;
&lt;p&gt;How does this look year over year since the data started? First, a quick decline occurs after 2013 followed by similarly looking collision patterns year over year. We can see some streets always have a dense amount of collisions. &lt;em&gt;Venice, Figueroa, Pico, Olympic, Wilshire, Santa Monica and Vermont&lt;/em&gt; appear to be big incident streets year over year.&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;picture&gt;&lt;source media=&quot;(prefers-reduced-motion: reduce)&quot; srcset=&quot;https://martinsiron.com/stills/2022/11/collision_per_year_larger_radius-1.webp&quot;&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 800px) 800px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;800&quot; height=&quot;800&quot; src=&quot;https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_Z29RVRK.webp&quot; srcset=&quot;https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_mxcMx.webp 192w, https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_Z1HjUvY.webp 384w, https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_2vCBRP.webp 640w, https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_2d9O02.webp 750w, https://martinsiron.com/_astro/collision_per_year_larger_radius-1.CWJjGOr0_Z29RVRK.webp 800w&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;Animated year over year traffic collision patterns.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Of course, many have pointed out that the pandemic has switched typical traffic flows for the city, as such, here are the pre-pandemic vs. post-pandemic collision map densities:&lt;/p&gt;
&lt;figure&gt;













&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th align=&quot;center&quot;&gt;&lt;strong&gt;2017-2020&lt;/strong&gt;&lt;/th&gt;&lt;th align=&quot;center&quot;&gt;&lt;strong&gt;2020-2022&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td align=&quot;center&quot;&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 450px) 450px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;450&quot; height=&quot;450&quot; src=&quot;https://martinsiron.com/_astro/post_2017.IvR8BP7g_1vF8aC.webp&quot; srcset=&quot;https://martinsiron.com/_astro/post_2017.IvR8BP7g_Z1kvJGk.webp 192w, https://martinsiron.com/_astro/post_2017.IvR8BP7g_Z1oMlvO.webp 384w, https://martinsiron.com/_astro/post_2017.IvR8BP7g_1vF8aC.webp 450w, https://martinsiron.com/_astro/post_2017.IvR8BP7g_2wXLN.webp 640w, https://martinsiron.com/_astro/post_2017.IvR8BP7g_1vy4Kp.webp 750w&quot;&gt;&lt;/td&gt;&lt;td align=&quot;center&quot;&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 450px) 450px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;450&quot; height=&quot;450&quot; src=&quot;https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_ZTzY2J.webp&quot; srcset=&quot;https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_1nixGe.webp 192w, https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_1p8my9.webp 384w, https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_ZTzY2J.webp 450w, https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_1dnsEC.webp 640w, https://martinsiron.com/_astro/post_2020-1.Dou-mYBR_1JXgbD.webp 750w&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;figcaption&gt;
&lt;p&gt;No big visual difference in pre- vs post-pandemic traffic collision patterns.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Just because a street has more absolute collision does not mean it has increased probability of collisions. To capture the probability of collisions, I’m going to make an assumption: that streets with more vehicular traffic should have more chances of vehicle-pedestrian interaction, so if I normalize the collision by the traffic flow, I should arrive at a value that is more representative of the probability of collision.&lt;/p&gt;
&lt;p&gt;Luckily, LADOT has &lt;a href=&quot;https://data.lacity.org/Transportation/LADOT-Traffic-Counts-Summary/94wu-3ps3&quot;&gt;data on such traffic volume&lt;/a&gt;. Unfortunately, this data appears to start in 2011 and stop in 2016. It does not survey the same street year over year and seems sporadic in the streets surveyed over time. It has not been updated since 2016 giving a mixed snapshot of the traffic throughout Los Angeles.&lt;/p&gt;
&lt;p&gt;The first plot will assume that the traffic from 2011-2016 more or less is constant throughout the collision data from 2010-2020:&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 800px) 800px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;800&quot; height=&quot;800&quot; src=&quot;https://martinsiron.com/_astro/probability.CAxXx6wZ_21KMii.webp&quot; srcset=&quot;https://martinsiron.com/_astro/probability.CAxXx6wZ_Z105r2M.webp 192w, https://martinsiron.com/_astro/probability.CAxXx6wZ_ZXfCaR.webp 384w, https://martinsiron.com/_astro/probability.CAxXx6wZ_Z1a0w4o.webp 640w, https://martinsiron.com/_astro/probability.CAxXx6wZ_ZCpIxn.webp 750w, https://martinsiron.com/_astro/probability.CAxXx6wZ_21KMii.webp 800w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;&lt;strong&gt;Overall collision probability map&lt;/strong&gt;&lt;em&gt;: Is Silver Lake one of the most dangerous places to bike in the last decade?&lt;/em&gt; &lt;em&gt;(arbitrary units, higher means higher probability)&lt;/em&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;To make a plot like this I had to engineer a trick: the data from the traffic flow does not overlay perfectly from the data from collisions, naturally. In order to be able to divide both data I needed to figure out an interpolation scheme for each. For traffic flow data I did a ‘nearest’ interpolation grid approach. I did this for two reasons, first I thought of the traffic flow data as a ‘graph’ in that the flow from one point to its nearest neighbor must be related: cars must travel between these points to an extent. The other reason for this interpolation, is that unlike the collision data, the traffic data was rather dense (in my opinion). For the collision data I opted for a Kernel Density Estimation (KDE) approach. Here, I made the assumption that an area near a collision point must be less safe, and thus a collision within a certain radius of another collision, is more likely to occur.&lt;/p&gt;
&lt;p&gt;In the second plot, realizing that we have a snapshot of a traffic count done late 2016 (600+ intersections), and we also have collisions for just 2016, we will repeat the plot with just the snapshot for the 2016 year:&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 800px) 800px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;800&quot; height=&quot;800&quot; src=&quot;https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_1zatxV.webp&quot; srcset=&quot;https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_850bN.webp 192w, https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_ZvolBg.webp 384w, https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_ZdthXF.webp 640w, https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_17p2xh.webp 750w, https://martinsiron.com/_astro/probability_2016-1.CBGqEpGz_1zatxV.webp 800w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;&lt;strong&gt;Just the 2016 data&lt;/strong&gt;&lt;em&gt;: dangerous centers appear in Calabasas, Koreatown, South LA, Venice, Boyle Heights&lt;/em&gt;, North Hollywood. &lt;em&gt;(arbitrary units, higher means higher probability)&lt;/em&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We will do the same thing with 2015, 2014, 2013, 2012, and 2011, but animated to see how the most dangerous areas changed over time:&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source media=&quot;(prefers-reduced-motion: reduce)&quot; srcset=&quot;https://martinsiron.com/stills/2022/11/collision_probability_yoy-2.webp&quot;&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 800px) 800px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;800&quot; height=&quot;800&quot; src=&quot;https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_sO1Aw.webp&quot; srcset=&quot;https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_1jp4rj.webp 192w, https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_ZUqWWT.webp 384w, https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_ZeItAa.webp 640w, https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_Z1oiYS.webp 750w, https://martinsiron.com/_astro/collision_probability_yoy-2.DSigZWch_sO1Aw.webp 800w&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;We can see year over year variation in probability of collisions, however some areas are highlighted throughout most of the year: Koreatown, Silverlake, South LA, East LA.&lt;/p&gt;</content:encoded><category>Data visualization</category><category>Statistics</category></item><item><title>Using Flask and Plotly to build a Web App of n-Cov2019 Cases</title><link>https://martinsiron.com/2020/02/09/using-flask-and-plotly-to-build-a-web-app-of-n-cov2019-cases/</link><guid isPermaLink="true">https://martinsiron.com/2020/02/09/using-flask-and-plotly-to-build-a-web-app-of-n-cov2019-cases/</guid><pubDate>Sun, 09 Feb 2020 02:38:41 GMT</pubDate><content:encoded>&lt;p&gt;&gt;&gt;&gt; &lt;a href=&quot;https://ncov2019.martinsiron.com/&quot;&gt;Please check out the web app here.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&gt;&gt;&gt; &lt;a href=&quot;https://martinsiron.com/2020/02/03/using-named-entity-recognition-and-natural-language-processing-to-build-a-map-of-accumulated-infections-of-n-cov2019/&quot;&gt;And read the blog post on the science behind the model here.&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 960px) 960px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;960&quot; height=&quot;527&quot; src=&quot;https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_Z2vW9H.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_Z21L5Qt.webp 192w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_1KlAAx.webp 384w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_Z26pgbn.webp 640w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_yQjHj.webp 750w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_4ImgU.webp 828w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_Z2vW9H.webp 960w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_2jQTQm.webp 1080w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_2nn6NG.webp 1280w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_ZDv48T.webp 1668w, https://martinsiron.com/_astro/Screen-Shot-2020-02-08-at-6.25.17-PM.CmDu0ScH_1bcn2d.webp 1920w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;Screenshot of web app as of 02.08.2020&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;</content:encoded><category>COVID-19</category><category>Data visualization</category></item><item><title>Using Named Entity Recognition and Natural Language Processing to build a map of accumulated infections of n-Cov2019</title><link>https://martinsiron.com/2020/02/03/using-named-entity-recognition-and-natural-language-processing-to-build-a-map-of-accumulated-infections-of-n-cov2019/</link><guid isPermaLink="true">https://martinsiron.com/2020/02/03/using-named-entity-recognition-and-natural-language-processing-to-build-a-map-of-accumulated-infections-of-n-cov2019/</guid><pubDate>Mon, 03 Feb 2020 04:23:03 GMT</pubDate><content:encoded>&lt;p&gt;I begin by scraping the following website for all its information and translating the text using Google Translate API: &lt;a href=&quot;https://ncov.dxy.cn/ncovh5/view/pneumonia_timeline?whichFrom=dxy&quot;&gt;https://ncov.dxy.cn/ncovh5/view/pneumonia_timeline?whichFrom=dxy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The data consists of a header, a description, a timestamp of some sort, and the source where the information came from. Using the HTML library in Python I extracted these various sections of the page and placed them into a Pandas Dataframe.&lt;/p&gt;
&lt;p&gt;After some cleaning, I used “Named Entity Recognition” to extract locations from both the descriptions and the titles. Since location is such a common use for NER, I decided to use an already existing model: DeepPavlov. I loaded this model and extracted all the locations and put them in their own Pandas columns in the data frame.&lt;/p&gt;
&lt;p&gt;Next, I need to extract the latitude and longitude from the name of these locations. Using GeoPy, I extracted and averaged all the locations in both the header and description. For now, I opted to use only the location information in the header as from a quick glance, this tends to be the main region or entity where the cases happened, rather than the city levels or entities that might have tested the case in the descriptions.&lt;/p&gt;
&lt;p&gt;Now, I was left with my ultimate bottleneck, text in the description like this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“From 00:00 to 24:00 on January 31, 2020, Shanxi Province reported 8 new confirmed cases of pneumonia due to new coronavirus infection. As of 14:00 on January 31, 47 cases of pneumonia confirmed by new coronavirus infection have been reported in 11 cities in Shanxi Province (including 2 severe cases, 1 critical case, 1 discharged case, and no deaths). At present, 1333 close contacts have been tracked. 41 people were released from medical observation on the same day, and a total of 1101 people were receiving medical observation.”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;From this I’ve already extracted this information:&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Time&lt;/u&gt;: January 31, 2020&lt;br&gt;
&lt;u&gt;Location&lt;/u&gt;: Shanxi Province&lt;br&gt;
&lt;strong&gt;However, I still need to extract the following information&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;New cases:&lt;/u&gt; 8 new confirmed cases of pneumonia (8)&lt;br&gt;
&lt;u&gt;Accumulated cases:&lt;/u&gt; 47 cases of pneumonia confirmed (47)&lt;br&gt;
&lt;u&gt;New deaths:&lt;/u&gt; no deaths (0)&lt;/p&gt;
&lt;p&gt;In order to approach this, I needed to train a custom NER model. I used TagTog’s tagging and AI tool to do this work:&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 974px) 974px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;974&quot; height=&quot;212&quot; src=&quot;https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_Z2riLVR.webp&quot; srcset=&quot;https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_1ezB0O.webp 192w, https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_Z1TqNNQ.webp 384w, https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_erS3S.webp 640w, https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_2qSF4a.webp 750w, https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_2hwhci.webp 828w, https://martinsiron.com/_astro/report-tagtog.gVoUrCfh_Z2riLVR.webp 974w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;TagTog: Annotation Tool&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This makes it easy to train by selecting the various information in a document. I created 8 entities and 4 relationships:&lt;/p&gt;


















































&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;strong&gt;Entity&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Relations&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;new_case_I&lt;/td&gt;&lt;td&gt;New case added in location&lt;/td&gt;&lt;td&gt;New cases and its number&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;new_case_N&lt;/td&gt;&lt;td&gt;Number of new cases&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;acc_case_I&lt;/td&gt;&lt;td&gt;Accumulated case in region&lt;/td&gt;&lt;td&gt;Accumulated cases and its number&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;acc_case_N&lt;/td&gt;&lt;td&gt;Number of accumulated cases&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;new_death_I&lt;/td&gt;&lt;td&gt;New death recorded in region&lt;/td&gt;&lt;td&gt;New deaths and its number&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;new_death_N&lt;/td&gt;&lt;td&gt;Number of new deaths&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;acc_death_I&lt;/td&gt;&lt;td&gt;Accumulated death in region&lt;/td&gt;&lt;td&gt;Accumulated deaths and its number&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;acc_death_N&lt;/td&gt;&lt;td&gt;Number of accumulated deaths&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;I manually tagged 20% of the data to build the model. From this, I parsed the rest of the data through the model to extract the remaining information. From the initial document example, the model extracted the following information:&lt;/p&gt;























































&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Text&lt;/th&gt;&lt;th&gt;Entity&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;Probability&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;‘no’&lt;/td&gt;&lt;td&gt;“accumulated_death-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.874&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;‘8’&lt;/td&gt;&lt;td&gt;“new_case-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.838&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;‘no deaths’&lt;/td&gt;&lt;td&gt;“accumulated_death-I”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.698&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;‘1’&lt;/td&gt;&lt;td&gt;“new_death-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.621&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;‘1’&lt;/td&gt;&lt;td&gt;“new_death-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.550&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;’47’&lt;/td&gt;&lt;td&gt;“accumulated_case-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.813&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;’41’&lt;/td&gt;&lt;td&gt;“accumulated_case-N”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.714&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;‘8 new confirmed cases’&lt;/td&gt;&lt;td&gt;“new_case-I”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.842&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;’47 cases of pneumonia confirmed’&lt;/td&gt;&lt;td&gt;“new_case-I”&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.640&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;We can see that the model with 20% of the data did fairly well. &lt;strong&gt;Numerically, we were able to pick up the correct new case number (8) and the correct accumulated case number (47).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;With the rest of the data parsed, I used Plotly to build a final heatmap (data from morning of 01/28). We can see from this that the model has clearly picked up the epicenter and the surrounding virus activity nearby.&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 700px) 700px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;700&quot; height=&quot;500&quot; src=&quot;https://martinsiron.com/_astro/final_heatmap.TD7dLhTU_Z2uAo3h.webp&quot; srcset=&quot;https://martinsiron.com/_astro/final_heatmap.TD7dLhTU_Zcezwc.webp 192w, https://martinsiron.com/_astro/final_heatmap.TD7dLhTU_2l2UpY.webp 384w, https://martinsiron.com/_astro/final_heatmap.TD7dLhTU_Z2phGFX.webp 640w, https://martinsiron.com/_astro/final_heatmap.TD7dLhTU_Z2uAo3h.webp 700w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;Heatmap of nCov2019 Accumulated Infections as of 01.28.2020&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I plotted the accumulated cases over time:&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 432px) 432px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;432&quot; height=&quot;288&quot; src=&quot;https://martinsiron.com/_astro/acc_cases_overtime.DWOpsDKl_ZQjNFd.webp&quot; srcset=&quot;https://martinsiron.com/_astro/acc_cases_overtime.DWOpsDKl_Z1eTsU0.webp 192w, https://martinsiron.com/_astro/acc_cases_overtime.DWOpsDKl_NvANi.webp 384w, https://martinsiron.com/_astro/acc_cases_overtime.DWOpsDKl_ZQjNFd.webp 432w&quot;&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;Accumulated cases over time for nCov2019 Infections&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Finally, I made a GIF heatmap of the virus activity over time (note the scale bar changes over time):&lt;/p&gt;
&lt;figure&gt;
&lt;p&gt;&lt;picture&gt;&lt;source media=&quot;(prefers-reduced-motion: reduce)&quot; srcset=&quot;https://martinsiron.com/stills/2020/02/nCov2019-Heatmap-Compressed.webp&quot;&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 700px) 700px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;700&quot; height=&quot;500&quot; src=&quot;https://martinsiron.com/_astro/nCov2019-Heatmap-Compressed.wFgaGv15_1zYk1F.webp&quot; srcset=&quot;https://martinsiron.com/_astro/nCov2019-Heatmap-Compressed.wFgaGv15_Z1CsxOR.webp 192w, https://martinsiron.com/_astro/nCov2019-Heatmap-Compressed.wFgaGv15_2hSUQv.webp 384w, https://martinsiron.com/_astro/nCov2019-Heatmap-Compressed.wFgaGv15_5dYsy.webp 640w, https://martinsiron.com/_astro/nCov2019-Heatmap-Compressed.wFgaGv15_1zYk1F.webp 700w&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;figcaption&gt;
&lt;p&gt;Animated heatmap over time. Scalebar changes over time.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Future:&lt;/strong&gt;&lt;br&gt;
In the imminent future, I plan on releasing a Flask app on my website with the data, &lt;strong&gt;stay tuned!&lt;/strong&gt; Additionally, I will update it with the most recent data released from 01.28.2020.&lt;/p&gt;</content:encoded><category>COVID-19</category><category>Data visualization</category><category>Machine learning</category></item><item><title>Predicting a US Primary Election</title><link>https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/</link><guid isPermaLink="true">https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/</guid><pubDate>Sat, 30 Apr 2016 20:15:26 GMT</pubDate><content:encoded>&lt;p&gt;This primary season has been rather interesting to say the least. There is a former TV reality star running a &lt;em&gt;show&lt;/em&gt;, spewing words that would be normally an automatic disqualifier if mentioned by previous candidates in previous election cycles. There exists a particularly angry voter base that scapegoats their fears and economic insecurities – often with understandable sentiments – at a ruling class they perceive as the establishment. You have people fixated on the character and honesty (or appearance of honesty) of candidates rather than their policies. And, as with the ’08 election cycle, you have a sense of hope in some candidates, as well as a sense of unsettledness about the possible nominees from the two major parties. The character of this unsettledness could perhaps be best described by these recent polls:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;1 in 4 affiliated Republicans say they could not vote for the GOP nominee if said nominee was Trump&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftn1&quot; id=&quot;_ftnref1&quot;&gt;&lt;strong&gt;[1]&lt;/strong&gt;&lt;/a&gt;. 33% of Sanders supporters, according to a McClatchy-Marist poll would not vote for Hillary if she was the nominee&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftn2&quot; id=&quot;_ftnref2&quot;&gt;&lt;strong&gt;[2]&lt;/strong&gt;&lt;/a&gt;, and 25% of voters would abstain from voting for one of the major party candidates if the nominees were Trump or Clinton&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftn3&quot; id=&quot;_ftnref3&quot;&gt;&lt;strong&gt;[3]&lt;/strong&gt;&lt;/a&gt;.&lt;/em&gt; It sure is an election of unique perspective, and uneasiness.&lt;/p&gt;
&lt;p&gt;For me personally, this election was the first time I realized how much math is actually involved during an election year. However, for me, it’s not the polling which is of actual interest but rather some of the commentaries made by political pundits following each contest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bernie does better in primarily white, non-diverse states&lt;/li&gt;
&lt;li&gt;Hillary does better among older and richer voters&lt;/li&gt;
&lt;li&gt;Bernie does better among independents, and in open/same day registration contests&lt;/li&gt;
&lt;li&gt;Bernie does better in caucuses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What if based on the last 38 contests that happened in U.S. states (excluding territories, democrats abroad, etc) we could provide a model to predict not just whether Bernie or Hillary wins one of the next 14 contests, but perhaps also the margin by which each candidate will win. &lt;em&gt;(This will be focused on the Democratic primary).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is exactly what I propose in this post.&lt;/p&gt;
&lt;p&gt;The first weight factor I will propose is one that is based entirely on the logistics of the contest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Is it a primary or caucus?&lt;/li&gt;
&lt;li&gt;Is there same day registration?&lt;/li&gt;
&lt;li&gt;Is it an open or closed contest?&lt;/li&gt;
&lt;li&gt;What region is the contest held in?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For each of these factors I assign certain value of “pro-Bernie” points, or logistical information which I believe would provide Bernie a contest where he would perform better:&lt;/p&gt;

























&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;strong&gt;Factor&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Comment and Value&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Primary or Caucus?&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Because Bernie does much better in caucuses, I will arbitrarily assign a caucus an additive value of 4.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Same day registration or registration with a deadline?&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Same day registration drastically helped Bernie. I assigned this an arbitrary, additive value of 3.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Open or closed contest?&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;It was noticed that this had no effect on how well Bernie did in previous contests.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Region (South, West, N.E., Midwest)&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;South – (-1)&lt;br&gt;&lt;br&gt;NE – (2)&lt;br&gt;&lt;br&gt;Midwest – (3)&lt;br&gt;&lt;br&gt;West – (5)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p class=&quot;label&quot;&gt;&lt;strong&gt;Here are the 39 contests summarized by election factor, to understand why I picked these values:&lt;/strong&gt;&lt;/p&gt;






































































&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;strong&gt;Region&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Count&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Average of Bernie vote&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;South&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;13&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;31.38462&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;West&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;74.7&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;14&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;57.65&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;N.E&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;9&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;52.66667&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Primary Type&lt;/strong&gt;&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;&lt;strong&gt;Count&lt;/strong&gt;&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;&lt;strong&gt;Average of Bernie vote&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Caucus&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;13&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;64.87692&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;26&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;41.14615&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Open&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;23&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;48.26522&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Closed&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;16&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;50.19375&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Same day&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;14&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;61.42857&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;25&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;42.128&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;There is a clear correlation between the region the contest is held in, as well as whether it’s a caucus or primary, and whether there is same day registration or not. However, whether or not the primary was open or closed did not appear to have a significant effect (perhaps it’s more of a bundled factor with whether or not the registration was on the same day and the primary was open vs. the opposite).&lt;/p&gt;
&lt;p&gt;Here is how I divided each state by region in the US:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1122px) 1122px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1122&quot; height=&quot;678&quot; src=&quot;https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_Z2g3IMd.webp&quot; srcset=&quot;https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_ZPHtmU.webp 192w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_ZgJcSM.webp 384w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_ZSg9Hj.webp 640w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_Z1GQsoW.webp 750w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_Ljm35.webp 828w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_Zlsoho.webp 1080w, https://martinsiron.com/_astro/mapInSeconds-map.4RBzcWVp_Z2g3IMd.webp 1122w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Each of these components would then be added into an “Election” Factor (EF), which when plotted against actual percentage of votes Bernie gathered in the state would yield the following curve:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Graph-EF-vs-Vote-1.XzgpJ8su_1cPYkf.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Graph-EF-vs-Vote-1.XzgpJ8su_e1xGi.webp 192w, https://martinsiron.com/_astro/Graph-EF-vs-Vote-1.XzgpJ8su_z5VmA.webp 384w, https://martinsiron.com/_astro/Graph-EF-vs-Vote-1.XzgpJ8su_1cPYkf.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;This gave a positive correlation with rather decent R&lt;sup&gt;2&lt;/sup&gt; value.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Now let’s get into the demographics of the state&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;The first “trend” that I often hear by political pundits is that Bernie does better in rural states. So I tested this hypothesis directly by comparing a graph of population density by state vs. the percentage of votes Bernie received in that state:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Pop-Density-vs-Vote-2.CnjwL67b_Z1EFRCN.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Pop-Density-vs-Vote-2.CnjwL67b_Z1E66TH.webp 192w, https://martinsiron.com/_astro/Pop-Density-vs-Vote-2.CnjwL67b_Z1Kq7RD.webp 384w, https://martinsiron.com/_astro/Pop-Density-vs-Vote-2.CnjwL67b_Z1EFRCN.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This was a rather weak trend, with a rather low R&lt;sup&gt;2&lt;/sup&gt; value that I decided to dismiss this factor into my final calculations. I guess the pundits aren’t always right?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Next demographic of interest is race, which surprisingly shows a rather strong correlation with the percentage of votes Bernie received. Often during the primary race I heard that “Bernie won that state because it’s a mostly white rural state.” Well we already threw out the rural hypothesis, but maybe the white one has some truth to it. So I decided to plot the percentage of white population of a state vs. the percentage of vote Bernie received:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Pop-White-vs-Vote-3.BtTsxhDl_dgD8Q.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Pop-White-vs-Vote-3.BtTsxhDl_2l7C7k.webp 192w, https://martinsiron.com/_astro/Pop-White-vs-Vote-3.BtTsxhDl_1NqLsv.webp 384w, https://martinsiron.com/_astro/Pop-White-vs-Vote-3.BtTsxhDl_dgD8Q.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This demonstrated a slightly weak, but none the less non-ignorable trend between the lack of racial diversity in a state and the amount of votes Bernie received.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now let’s do the same with the black population per state:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Pop-Black-vs-Vote-4.BMFBa8VW_OjtX4.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Pop-Black-vs-Vote-4.BMFBa8VW_Z281ERo.webp 192w, https://martinsiron.com/_astro/Pop-Black-vs-Vote-4.BMFBa8VW_2ptChI.webp 384w, https://martinsiron.com/_astro/Pop-Black-vs-Vote-4.BMFBa8VW_OjtX4.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Now that’s a rather strong correlation…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let’s do the same with the Asian population:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Pop-Asian-vs-Vote-5.ComVwY-n_Z1OSKI3.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Pop-Asian-vs-Vote-5.ComVwY-n_hWdfq.webp 192w, https://martinsiron.com/_astro/Pop-Asian-vs-Vote-5.ComVwY-n_ZeICoo.webp 384w, https://martinsiron.com/_astro/Pop-Asian-vs-Vote-5.ComVwY-n_Z1OSKI3.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Again, not a huge correlation, although it’s worth noting that Bernie is not uniquely strong in diversity-lacking states, he did very well in Hawaii, a state that’s only 26% white&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;What about the Hispanic vote?&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/Pop-Hisp-vs-Vote-6.Cl2dQWs7_Z1911Wu.webp&quot; srcset=&quot;https://martinsiron.com/_astro/Pop-Hisp-vs-Vote-6.Cl2dQWs7_Z27PsAr.webp 192w, https://martinsiron.com/_astro/Pop-Hisp-vs-Vote-6.Cl2dQWs7_Z1LL4U9.webp 384w, https://martinsiron.com/_astro/Pop-Hisp-vs-Vote-6.Cl2dQWs7_Z1911Wu.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;With such a low correlation, it is safe to say that the Hispanic population in a state does not show a noticeable effect on the percentage of vote Bernie wins in that state. I’m going to rule this out of my model.&lt;/p&gt;
&lt;p&gt;Now I will put all of the racial demographic variables together into a “Race” Factor:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 287px) 287px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;287&quot; height=&quot;73&quot; src=&quot;https://martinsiron.com/_astro/RF-Eqn-7.DwpUjT4T_Zr9eOg.webp&quot; srcset=&quot;https://martinsiron.com/_astro/RF-Eqn-7.DwpUjT4T_Z14WxpL.webp 192w, https://martinsiron.com/_astro/RF-Eqn-7.DwpUjT4T_Zr9eOg.webp 287w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Where m&lt;sub&gt;i&lt;/sub&gt;, b&lt;sub&gt;i&lt;/sub&gt;, R&lt;sup&gt;2&lt;/sup&gt; is the slope, intercept and R&lt;sup&gt;2&lt;/sup&gt; of the specific population segment i (white, black, asian). P&lt;sub&gt;i&lt;/sub&gt; is the actual population percentage of the segment i of interest. a&lt;sub&gt;i&lt;/sub&gt; is an arbitrary coefficient of influence I designated based on how much influence each population segment had on the overall trend (1 for white, ½ for asian and 2 for black).&lt;/p&gt;
&lt;p&gt;I then scaled the values so that they would be the same order of magnitude as the election factor (1-10). The highest value of the E.F. was 12, so I wanted the highest value of the RF to also be 12.&lt;/p&gt;
&lt;p&gt;This yields an RF value vs. Bernie vote curve of:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/RF-vs-Vote-8.K0wChz-z_2jpcnI.webp&quot; srcset=&quot;https://martinsiron.com/_astro/RF-vs-Vote-8.K0wChz-z_Z1Rsioi.webp 192w, https://martinsiron.com/_astro/RF-vs-Vote-8.K0wChz-z_9PRTB.webp 384w, https://martinsiron.com/_astro/RF-vs-Vote-8.K0wChz-z_2jpcnI.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p&gt;This gives a rather positive and strong correlation with R&lt;sup&gt;2&lt;/sup&gt; of 0.75.&lt;/p&gt;
&lt;p class=&quot;label&quot;&gt;&lt;strong&gt;Now let’s combine both factors into a final score per state (FS):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 251px) 251px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;251&quot; height=&quot;71&quot; src=&quot;https://martinsiron.com/_astro/FS-Eqn-9.-sLGv2el_2gid0G.webp&quot; srcset=&quot;https://martinsiron.com/_astro/FS-Eqn-9.-sLGv2el_MAiwk.webp 192w, https://martinsiron.com/_astro/FS-Eqn-9.-sLGv2el_2gid0G.webp 251w&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this S&lt;sub&gt;i&lt;/sub&gt; is one of the two factors of interest (EF, RF). I decided to remove the data point for Vermont as it was an outlier in my data (confirmed by a simple Q-test). The most likely explanation for Vermont is that as Bernie’s home state it gave him a much higher advantage unaccounted for in the E.F.&lt;/p&gt;
&lt;p&gt;This gave me a final FS vs. percentage of vote for Bernie curve of:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 482px) 482px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;482&quot; height=&quot;290&quot; src=&quot;https://martinsiron.com/_astro/FS-vs-Vote-10.DzZJBkH9_1qo8DN.webp&quot; srcset=&quot;https://martinsiron.com/_astro/FS-vs-Vote-10.DzZJBkH9_xsKz0.webp 192w, https://martinsiron.com/_astro/FS-vs-Vote-10.DzZJBkH9_1CjblD.webp 384w, https://martinsiron.com/_astro/FS-vs-Vote-10.DzZJBkH9_1qo8DN.webp 482w&quot;&gt;&lt;/p&gt;
&lt;p class=&quot;label&quot;&gt;&lt;strong&gt;&lt;em&gt;This shows a very strong correlation between our engineered FS factor and the vote that Bernie received.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;label&quot;&gt;&lt;strong&gt;Now, we can test the remainder of the states:&lt;/strong&gt;&lt;/p&gt;













































































































































































&lt;table tabindex=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;strong&gt;States&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Total Delegates&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Registration&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/th&gt;&lt;th&gt;&lt;strong&gt;Region&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;EF&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;% White&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Black&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Asian&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;RF2&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;FS&lt;/strong&gt;&lt;/th&gt;&lt;th class=&quot;num&quot;&gt;&lt;strong&gt;Bernie&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;California&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;475&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;West&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;5&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;79.07&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;7.45&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;13.47&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;9.0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;42.8&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;53.2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;DC&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;20&lt;/td&gt;&lt;td&gt;Same day&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;N.E&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;5&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;37&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;47&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;4&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0.0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;14.9&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;34.9&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Indiana&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;83&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;84.3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;9.1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;1.6&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;8.2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;34.5&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;47.7&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Kentucky&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;55&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;84&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;8&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;8.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;36.0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;48.7&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Montana&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;21&lt;/td&gt;&lt;td&gt;Same day&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;6&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;90&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;12.2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;55.9&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;61.8&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;N Dakota&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;18&lt;/td&gt;&lt;td&gt;Same day&lt;/td&gt;&lt;td&gt;Caucus&lt;/td&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;10&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;88&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;11.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;66.1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;68.6&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;NJ&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;126&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;N.E&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;58&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;13&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;9&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;6.6&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;26.4&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;42.4&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;NM&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;34&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;South&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;-1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;40&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;11.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;33.3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;47.0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Oregon&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;61&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;West&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;5&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;76&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;6&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;11.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;51.2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;58.7&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SD&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;20&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;Midwest&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;85&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;11.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;45.2&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;54.8&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;West Virginia&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;29&lt;/td&gt;&lt;td&gt;Deadline&lt;/td&gt;&lt;td&gt;Primary&lt;/td&gt;&lt;td&gt;South&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;-1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;92&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;3&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;0&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;11.1&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;31.7&lt;/td&gt;&lt;td class=&quot;num&quot;&gt;45.9&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The ones highlighted in green are the ones I predict he will have a definite victory. The yellow could go either way and the red I predict he will perform poorly in. This is entirely based on election logistics and demographics of the state.&lt;/p&gt;
&lt;p&gt;I guess we will find out May 3&lt;sup&gt;rd&lt;/sup&gt; when Indiana is up. Right now, according to polls, Bernie is behind by 6.6% points&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftn4&quot; id=&quot;_ftnref4&quot;&gt;[4]&lt;/a&gt;. My model predicts he will lose by 4.6%. This agrees pretty well with the polls. Check back this chart May 3&lt;sup&gt;rd&lt;/sup&gt; to see how my model holds up!&lt;/p&gt;
&lt;p&gt;Resources:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftnref1&quot; id=&quot;_ftn1&quot;&gt;[1]&lt;/a&gt;http://www.rasmussenreports.com/public_content/politics/elections/election_2016/no_trump_no_show_for_33_of_gop_voters&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftnref2&quot; id=&quot;_ftn2&quot;&gt;[2]&lt;/a&gt; http://www.wsj.com/video/poll-33-of-sanders-supporters-wouldnt-vote-for-clinton/69C05055-85FE-4320-8D02-3EAC972CACD0.html&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftnref3&quot; id=&quot;_ftn3&quot;&gt;[3]&lt;/a&gt;http://www.rasmussenreports.com/public_content/politics/elections/election_2016/24_opt_out_of_a_clinton_trump_race&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://martinsiron.com/2016/04/30/predicting-a-us-primary-election/#_ftnref4&quot; id=&quot;_ftn4&quot;&gt;[4]&lt;/a&gt; http://www.realclearpolitics.com/epolls/2016/president/in/indiana_democratic_presidential_primary-5807.html&lt;/p&gt;</content:encoded><category>Just for fun</category><category>Politics</category><category>Statistics</category></item></channel></rss>