<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/"></div></div><div><a data-url="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/" data-counturl="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/" data-count="horizontal" data-text="The Effective Number of Parties in the Electorate by Year and Region" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://danielmarcelino.github.io/blog/2016/effective-number-of-parties.html"> Daniel's Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Tasks: Compute the Effective Number of Parties by year and region</h2>
<ul>
<li>Using the American National Election Studies, compute the Effective Number of Parties in the electorate across regions and years/waves.</li>
</ul>
<h2>The data</h2>
<p>The data come from The American National Election Studies (ANES).<br>
The <a target="_blank" rel="nofollow" href="http://www.electionstudies.org/">ANES</a> is a survey that covers voting behavior, public opinion, and political participation. Many other countries have their own version of this survey, for instance see <a target="_blank" rel="nofollow" href="http://ellisp.github.io/blog/2016/09/18/nzes1">here</a>.<br>
While the primary mission of these studies is to answer questions about voting behavior, the wealth of variables collected amongst voters means that we can use these data to answer other questions too. If you would like to know about the other variables contained in the ANES questionnaires, you may want to read its <a target="_blank" rel="nofollow" href="http://www.electionstudies.org/studypages/anes_timeseries_cdf/anes_timeseries_cdf_codebook_var.pdf">codebook</a>. You may also be interested in a <a target="_blank" rel="nofollow" href="http://www.asdfree.com/2013/11/analyze-american-national-election.html">post</a> by Anthony Damico on this topic.</p>
<p>There are many ways you can import the version of data I’ve made. For example, you download it. Then read it.</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>library</span><span>(</span><span>RCurl</span><span>)</span><span>
</span><span>library</span><span>(</span><span>SciencesPo</span><span>)</span><span> </span><span>download.file</span><span>(</span><span>&quot;https://github.com/danielmarcelino/Datasets/raw/master/ANES/anes-data.RData&quot;</span><span>,</span><span> </span><span>destfile</span><span> </span><span>=</span><span> </span><span>&quot;anes-data.RData&quot;</span><span>)</span><span>
</span><span>ANES</span><span> </span><span>&lt;-</span><span> </span><span>readRDS</span><span>(</span><span>&quot;anes-data.RData&quot;</span><span>)</span></code></pre>
</figure>
<h2>Data chasing</h2>
<p>I’m particularly interested in 3 variables from the list. Party identification (VCF0301), originally measured as 7-point scale, the census region code (VCF0112), and years of the wave (VCF0004).</p>
<figure>
<pre><code data-lang="r"><span>ANES</span><span>$</span><span>PID3</span><span> </span><span>&lt;-</span><span> </span><span>factor</span><span>(</span><span>ANES</span><span>$</span><span>VCF0301</span><span>)</span><span> </span><span># Convert to three-level Party ID:
</span><span>levels</span><span>(</span><span>ANES</span><span>$</span><span>PID3</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;Dem&quot;</span><span>,</span><span> </span><span>&quot;Dem&quot;</span><span>,</span><span> </span><span>&quot;Dem&quot;</span><span>,</span><span> </span><span>&quot;Ind&quot;</span><span>,</span><span> </span><span>&quot;Rep&quot;</span><span>,</span><span> </span><span>&quot;Rep&quot;</span><span>,</span><span> </span><span>&quot;Rep&quot;</span><span>)</span><span>
</span><span>ANES</span><span>$</span><span>Region</span><span> </span><span>&lt;-</span><span> </span><span>factor</span><span>(</span><span>ANES</span><span>$</span><span>VCF0112</span><span>)</span><span> </span><span># # Convert to factor
</span><span>levels</span><span>(</span><span>ANES</span><span>$</span><span>Region</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;Northeast&quot;</span><span>,</span><span> </span><span>&quot;North Central&quot;</span><span>,</span><span> </span><span>&quot;South&quot;</span><span>,</span><span> </span><span>&quot;West&quot;</span><span>)</span><span>
</span><span>names</span><span>(</span><span>ANES</span><span>)[</span><span>names</span><span>(</span><span>ANES</span><span>)</span><span>==</span><span>&quot;VCF0004&quot;</span><span>]</span><span> </span><span>&lt;-</span><span> </span><span>&quot;Year&quot;</span><span>
</span><span>#</span><span> </span><span>ANES</span><span> </span><span>&lt;-</span><span> </span><span>ANES</span><span>[(</span><span>which</span><span>(</span><span>ANES</span><span>$</span><span>VCF0004</span><span> </span><span>%in%</span><span> </span><span>c</span><span>(</span><span>2000</span><span>,</span><span> </span><span>2002</span><span>,</span><span> </span><span>2004</span><span>,</span><span> </span><span>2008</span><span>,</span><span>2012</span><span>))),]</span></code></pre>
</figure>
<h2>The Effective Number of Parties</h2>
<p>For those who do not know the concept of an “Effective Number of Parties”, you can read a <a target="_blank" rel="nofollow" href="http://danielmarcelino.github.io/blog/2014/A-bit-more-fragmented.html">post back in 2014</a>, or go to <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Effective_number_of_parties">Wikipedia</a> for summarizing details. In short, the effective number of parties is the number of viable or important political parties in a party system that includes parties of unequal size.<br>
This measure is given by the inverse of the Herfindahl-Hirschman Index (HHI) or the inverse participation ratio (IPR) in physics.<br>
The HHI is calculated by taking the voting share of each party in the electorate, squaring them, and summing the result: $HHI = s1^2 + s2^2 + s3^2 + … + sn^2$ (where <em>s</em> is the voting share of each party expressed as a whole number. In mathematical notation, it looks like:</p>
<p></p>
<p>For now, I’ll be using <em>dplyr</em> to estimate the effective number of parties by year and region, but the <strong>SciencesPo</strong> package has a function named <em>politicalDiversity</em> that can calculate several indices used by political science scholars, which I’ll be addressing in future posts.</p>
<figure>
<pre><code data-lang="r"><span>ENPpid3</span><span> </span><span>&lt;-</span><span> </span><span>ANES</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Year</span><span>,</span><span> </span><span>Region</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>invHHI</span><span> </span><span>=</span><span> </span><span>sum</span><span>(</span><span>table</span><span>(</span><span>PID3</span><span>))</span><span>^</span><span>2</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>table</span><span>(</span><span>PID3</span><span>)</span><span>^</span><span>2</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>Region</span><span>))</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">print(ENPpid3)

Source: local data frame [112 x 3]
Groups: Year [28]

    Year        Region   invHHI
   &lt;dbl>        &lt;fctr>    &lt;dbl>
1   1952     Northeast 2.251207
2   1952 North Central 2.231502
3   1952         South 1.538712
4   1952          West 2.119764
5   1956     Northeast 2.352651
6   1956 North Central 2.419891
7   1956         South 1.816944
8   1956          West 2.395399
9   1958     Northeast 2.296220
10  1958 North Central 2.247543
# ... with 102 more rows</code></pre>
</figure>
<h2>The plot</h2>
<p>The index takes into consideration the relative size distribution of the parties (actually, declared partisanship) in an electorate. It approaches 1 when the distribution of preferences in a region is concentrated around only one party. Conversely, the index increases when the number of parties favored in the region increases.</p>
<p>The analysis suggests a highly concentrated political market in-the-electorate in the South states, around 1 and a half party in the 50s, but then regressing towards the national mean (invHHI = 2.349) after the 60s.</p>
<figure>
<pre><code data-lang="r"><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>ENPpid3</span><span>)</span><span>
</span><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>gg</span><span> </span><span>+</span><span> </span><span>geom_line</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Year</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>invHHI</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>Region</span><span>),</span><span> </span><span>size</span><span>=</span><span>1.1</span><span>)</span><span>
</span><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>gg</span><span> </span><span>+</span><span> </span><span>scale_x_continuous</span><span>(</span><span>limits</span><span>=</span><span>c</span><span>(</span><span>1952</span><span>,</span><span> </span><span>2012</span><span>),</span><span> </span><span>breaks</span><span> </span><span>=</span><span> </span><span>round</span><span>(</span><span>seq</span><span>(</span><span>1952</span><span>,</span><span> </span><span>2012</span><span>,</span><span> </span><span>by</span><span> </span><span>=</span><span> </span><span>4</span><span>),</span><span>1</span><span>))</span><span> </span><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>gg</span><span> </span><span>+</span><span> </span><span>scale_y_continuous</span><span>(</span><span>limits</span><span>=</span><span>c</span><span>(</span><span>1</span><span>,</span><span> </span><span>3</span><span>))</span><span>
</span><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>gg</span><span> </span><span>+</span><span> </span><span>theme_pub</span><span>()</span><span>
</span><span>gg</span><span> </span><span>&lt;-</span><span> </span><span>gg</span><span> </span><span>+</span><span> </span><span>labs</span><span>(</span><span>title</span><span> </span><span>=</span><span> </span><span>&quot;Effective Number of Parties-in-the-Electorate&quot;</span><span>,</span><span> </span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Year of the survey&quot;</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Index&quot;</span><span>)</span><span>
</span><span>gg</span></code></pre>
</figure>
<p><img title="center" alt="center" src="https://i0.wp.com/danielmarcelino.github.io/img/11-26-2016-effective-number-of-parties/plot-1-1.png?w=456" data-recalc-dims="1"></p>
<p>It’s true that majority plurality (single ballot) electoral systems tend to have a low number of effective parties compared to majority second ballot systems and to proportional representation systems. With an average count of effective parties in-the-electorate around 2, there is not much room for a third political force to emerge; and this seems to be quite consolidated among regions.</p>
<p><code>#reproducible</code></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/"></div></div><div><a data-url="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/" data-counturl="https://www.r-bloggers.com/the-effective-number-of-parties-in-the-electorate-by-year-and-region/" data-count="vertical" data-text="The Effective Number of Parties in the Electorate by Year and Region" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://danielmarcelino.github.io/blog/2016/effective-number-of-parties.html"> Daniel's Blog</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kaHDtTho3TY"></a></div>