<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/capturing-the-brexit-vote-in-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://freigeist.devmag.net/r/1006-capturing-the-brexit-vote-in-data.html"> fReigeist » R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In my <a rel="nofollow" href="http://www.trfetzer.com/who-voted-for-brexit/" target="_blank">recent research</a> I have worked on understanding the key correlates of Brexit. This paper is joint work with my co-authors <a rel="nofollow" href="http://www.sobecker.de/" target="_blank">Sascha Becker</a> and <a rel="nofollow" href="http://www2.warwick.ac.uk/fac/soc/economics/staff/dnovy/" target="_blank">Dennis Novy</a> and has now been <a rel="nofollow" href="https://academic.oup.com/economicpolicy/article/32/92/601/4459491/Who-voted-for-Brexit-A-comprehensive-district" target="_blank">published in Economic Policy</a>. After having gone through the peer-review process, I am very happy to <a rel="nofollow" href="https://www.dropbox.com/s/3fxh0a2n2lca26b/Becker_Fetzer_Novy_2017_EP.zip?dl=1" target="_blank">share the data and the underlying code</a>.</p>
<div>
<h3>On the construction of a rich local authority level dataset</h3>
<p>After the EU Referendum, I started working on assembling a dataset to study the question to what extent low turnout among potential remain voters may help to understand the result of the referendum. In particular, back then I looked at the extent to which rainfall may have discouraged people to turn up to vote in the first place. After all, a lot of polls, the financial markets and betting markets seemed to indicate that Remain would win.</p>
<p>It was not inconceivable to imagine that turnout may have been particularly low among a set of voters living in the London commuter belt, who were turned off from voting on a working day after an arduous journey into London that was marred by train cancelations due to the bad weather.</p>
<p>The result then was that there appears to have been a weak effect on turnout, but this effect was not biased in either direction with regard to voter preferences: Remain would have lost also on a sunny day (we confirm this finding in the new paper with a different rainfall data set).</p>
<p>In any case, this was the starting point to a significant data collection effort. In particular we have combined data from all the 380 local authorities in England, Scotland and Wales as well as some data of ward level voting across five cities. The resulting set of covariates is quite sizable and they can be roughly grouped into the following four categories:</p>
<ol>
<li>characteristics of the <strong>underlying economic structure</strong> of an area, like the unemployment rate, wages or sectoral employment shares and changes therein,</li>
<li><strong>demographic and human capital characteristics</strong> like age structure, education or life satisfaction,</li>
<li><strong>exposure to the EU</strong> measured by indicators like the level of EU transfers, trade and the growth rate of immigration from other EU countries,</li>
<li><strong>public service provision and fiscal consolidation</strong> that covers the share of public employment, as well as the reduction in public spending per capita among others and NHS performance metrics.</li>
</ol>
<p>To analyse which of these covariates are strong correlates of the Leave vote share in an area, we used a simple machine-learning method that chooses the best subset of covariates that best predicts the referendum Leave share. The idea is to build a robust predictive model that could achieve significant out of sample prediction accurracy.</p>
<p>More formally, best subset selection solves the following optimization problem to obtain an optimal vector <strong>beta</strong> that can robustly predict the vote leave share <strong>y_c</strong></p>
<p><span><a rel="nofollow" href="https://i0.wp.com/freigeist.devmag.net/wp-content/equations.png" target="_blank"><img alt="equations" src="https://i0.wp.com/freigeist.devmag.net/wp-content/equations.png?w=450" class="wp-image-1007" data-recalc-dims="1"></a></span></p>
<p>While the formulation may be a bit technical, it boils down to estimating all possible ways to combine regressors. That means, all possible ways of estimating a model that includes 1, 2, 3, …, p covariates are being estimated. This amounts to estimating <span>(2^p)</span> models, which becomes infeasible to estimate very fast. Lasso and other methods such as forward- and backward stepwise selection are solving approximations to the combinatorical problem that BSS solves. The method is usually taught at the beginning of machine learning courses as it provides a great way to illustrate the bias-variance tradeoff.</p>
<p>The result can be summarized in a simple bar chart and is somewhat striking:</p>
<div>
<div>
<p> <a rel="nofollow" href="https://i0.wp.com/freigeist.devmag.net/wp-content/r2regressors.png" target="_blank"><img alt="r2regressors" src="https://i0.wp.com/freigeist.devmag.net/wp-content/r2regressors.png?w=450" class="wp-image-1008" data-recalc-dims="1"></a></p>
<p>R2 of best models with different groups of regressors</p>
</div>
</div>
<p>What this suggests is that “Fundamental factors” such economic structure, demographics and human capital are strongest correlates of Leave vote in the UK; the direct level effects of migration and trade exposure captured in the group of regressors called “EU Exposure” seem second order.</p>
<p>Also what is striking that even very simple empirical models with just 10 – 20 variables are doing a good job in capturing the variation in the vote leave share across the whole of the UK.  The best model that includes variables measuring vote shares of different parties (especially UKIP) from the 2014 European Parliamentary election captures 95% of the overall variation.</p>
<p>The observation that variables capturing direct exposure to the European Union, in particular, Immigration seems at odds with voter narratives around the EU referendum, which were doinated by the immigration topic. In fact, the 2015 British Election study suggests that voters  considered immigration to be the single most important issue of the time.</p>
<div class="wp-caption"><a rel="nofollow" href="https://i0.wp.com/freigeist.devmag.net/wp-content/brexit-wordcloud.png" target="_blank"><img src="https://i0.wp.com/freigeist.devmag.net/wp-content/brexit-wordcloud.png?w=450" alt="Word clound constructed out of responses to question " class="wp-image-1011" data-recalc-dims="1"></a>
<p class="wp-caption-text">Unigram word cloud constructed out of responses to question “what is single most important issue facing country at the time” from the 2015 BES study</p>
</div>
<p>In the above the word cloud the keyword immigration is just quite striking. Looking at the bigram word cloud drawn from the British Election study, the themes of the individual responses become even more apparent.</p>
<div class="wp-caption"><a rel="nofollow" href="https://i0.wp.com/freigeist.devmag.net/wp-content/brexit-wordcloud-bigram.png" target="_blank"><img src="https://i0.wp.com/freigeist.devmag.net/wp-content/brexit-wordcloud-bigram.png?w=450" alt="Bigram word cloud constructed out of responses to question " class="wp-image-1012" data-recalc-dims="1"></a>
<p class="wp-caption-text">Bigram word cloud constructed out of responses to question “what is single most important issue facing country at the time” from the 2015 BES study</p>
</div>
<p>There things like “many people”, “small island”, “uncontrolled immigration” appear in addition to the simple immigration keyword. But also other themes, such as “national debt”, “health service” and concerns about the “welfare system” seem to feature quite large. Overall this suggests that immigration may have been a salient feature in the public debate, but it seems at odds with the fact that the variable groups pertaining to EU immigration seem to capture very little of the variation in the intensity of the leave vote across the UK.</p>
<p> </p>
<p>In another paper with Sascha we <a rel="nofollow" href="http://ukandeu.ac.uk/immigration-and-brexit/" target="_blank">confirm this observation </a> in a panel setup. We show  that a local area’s exposure to Eastern European immigration has, at best, only a small impact on anti-EU preferences in the UK as measured by UKIP voting in European Parliamentary Elections.</p>
<p>While our code for the Economic policy paper is implemented in Stata, it is very easy to replicate this work in Stata. Below is an example of how you would implement BSS in R through the <strong>leaps</strong> package.</p>
<p>The leaps package has a nice visualization of which regressors are included in which of the best models. The below example replicates the results in our Table 1.</p>
<pre><code>library(data.table)
library(haven)
library(leaps)
DTA&lt;-data.table(read_dta(file=&quot;data/brexitevote-ep2017.dta&quot;))

#TABLE 1 IN THE PAPER WOULD BE REPLICATED BY RUNNING
TABLE1&lt;-regsubsets(Pct_Leave~InitialEUAccession+MigrantEUAccessionGrowth+InitialOldEUMember+MigrantOldEUMemberGrowth+InitialElsewhere+MigrantElsewhereGrowth+Total_EconomyEU_dependence+eufundspercapitapayment13+EU75Leaveshare,nbest=1,data=DTA)

plot(TABLE1,scale=&quot;r2&quot;)</code></pre>
<div>
<div>
<p> <a rel="nofollow" href="https://i2.wp.com/freigeist.devmag.net/wp-content/subsets.png" target="_blank"><img alt="subsets" src="https://i2.wp.com/freigeist.devmag.net/wp-content/subsets.png?w=450" class="wp-image-1009" data-recalc-dims="1"></a></p>
<p>Plotting best subset results</p>
</div>
</div>
<p>If you want to replicate the word clouds from the 2015 British Election study, the following lines of code will do. You will need to download the British Election Study dataset here.</p>
<pre><code>
library(data.table)
library(haven)
library(quanteda)

DTA&lt;-data.table(read_dta(file=&quot;data/bes_f2f_original_v3.0.dta&quot;))

C&lt;-corpus(DTA$A1)
docnames(C)&lt;-DTA$finalserialno

C.dfmunigram

C.dfmunigram &lt;- dfm(C, tolower = TRUE, stem = FALSE, removeNumbers=TRUE,removePunct=TRUE, remove = stopwords(&quot;english&quot;), ngrams=1)
C.dfm&lt;-dfm(C, tolower = TRUE, stem = FALSE, removeNumbers=TRUE,removePunct=TRUE, remove = stopwords(&quot;english&quot;), ngrams=2)

plot(C.dfmunigram)

plot(C.dfm)

this
 </code></pre>
</div>
<div>
<div></div>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://freigeist.devmag.net/r/1006-capturing-the-brexit-vote-in-data.html"> fReigeist » R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/n9c7NH3e2NM" height="1"></a></div>