Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbrailey committed Mar 31, 2020
1 parent b0f3173 commit ce8dab1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 27 deletions.
20 changes: 15 additions & 5 deletions content/posts/test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ burkina_faso <- rio::import("C:/Users/tbrai/Dropbox/Constitutions Project/Data/E

# What is Electoral Proximity?

Electoral proximity is the measure of fractionalization between a presidential and legislative election. That is, how temporally separated a state's legislative and presidential elections might be. If presidential and legislative elections occur on the same day, they are considered to be proximally maximal. If there is a considerable gap between elections, then there is considered to be less proximity between elections. Gary Cox termed this phrase in Making Votes Count (1997) and builds off of the work of Matthew Shugart, John Carey, Rein Taagepera, and others. Why is electoral proximity important? Cox suggests that it taps into executive-legislative behaviors; others note that greater proximity of presidential and legislative elections tend tends to reduce the number of effective parties in a state. In any case, being able to calculate a state's electoral proximity could open the door to some interesting studies.
Electoral proximity is the measure of fractionalization between a presidential and legislative election. That is, how temporally separated a state's legislative and presidential elections might be. If presidential and legislative elections occur on the same day, they are considered to be proximally maximal. If there is a considerable gap between elections, then there is considered to be less proximity between elections. Gary Cox termed this phrase in Making Votes Count (1997) and builds off of the work of Matthew Shugart, John Carey, Rein Taagepera, and others. Why is electoral proximity important? Cox suggests that it taps into executive-legislative behaviors; others note that greater proximity of presidential and legislative elections tend tends to reduce the number of effective parties in a state. In any case, being able to calculate a state's electoral proximity could open the door to some interesting studies.

# How is Electoral Proximity Calculated?

Per Cox (1997), electoral proximity can be estimated as follows:

$$ PROXIMITY = 2 * \left| \frac{L_{t} - P_{t-1}}{P_{t+1} - P_{t-1}} - \frac{1}{2} \right| $$

and while this is a lovely equation, it is difficult to implement on your own.
and while this is a lovely equation, it might be difficult to implement on one's own.

# What's the Issue?

Expand All @@ -53,18 +53,21 @@ Here is a step-by-step run-through of how I calculated electoral proximity in Bu
burkina_faso <- burkina_faso %>%
#' Group by country and legislative election.
dplyr::group_by(country_name, leg_elect_year) %>%
#' Use "first" and "na.omit" to find the next presidential
#' election in the data. Using these two commands will find
#' the first non-NA value in a column. This new variable is
#' called "next_election".
dplyr::mutate(next_election = dplyr::first(na.omit(pres_elect_year))) %>%
#' Regroup by just country. We don't care about years at this point.
#' Then we fill out the "next_election" variable. Instead of filling
#' down the data, we want to fill up (imagine we are dragging the future
#' election up to the current legislative election).
dplyr::group_by(country_name) %>%
tidyr::fill(next_election, .direction = "up")
```
Expand All @@ -83,6 +86,7 @@ $\textit{next_election}$ = $P_{t+1}$
burkina_faso <- burkina_faso %>%
#' We can now, in one fell swoop, calculate Cox's electoral proximity.
dplyr::mutate(cox_prox = ifelse(leg_elect_dum == 1,
2 * abs(
(
Expand All @@ -92,6 +96,7 @@ burkina_faso <- burkina_faso %>%
cox_prox = ifelse(is.nan(cox_prox), 1, cox_prox)) %>%
#' Fill out the variable.
tidyr::fill(cox_prox)
```

Expand All @@ -100,14 +105,19 @@ burkina_faso <- burkina_faso %>%
Let's plot how electoral proximity changes over time in Burkina Faso.
```{r}
ggplot(burkina_faso, aes(x = year)) +
geom_line(aes(y = cox_prox), size = 2, color = "purple") +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = "dotted") +
geom_line(aes(y = cox_prox), size = 2, color = "purple", na.rm = TRUE) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = "dotted", na.rm=TRUE) +
labs(title = paste0("Electoral Proximity in ", unique(burkina_faso$country_name)),
x = "Year",
y = "Electoral Proximity (Cox, 1997)") +
theme_classic()
```
Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I'm going to plot a few more countries and see if I find any more intresting patterns.

Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I'm going to plot a few more countries and see if I find any more intresting patterns.

In the meantime, feel free to check out the related code for this post [here](https://github.com/tjbrailey/Functions). Please leave any comments and feedback in the "Issues" section of GitHub.

Thanks for reading!



Expand Down
21 changes: 13 additions & 8 deletions content/posts/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>What is Electoral Proximity?</h1>
<h1>How is Electoral Proximity Calculated?</h1>
<p>Per Cox (1997), electoral proximity can be estimated as follows:</p>
<p><span class="math display">\[ PROXIMITY = 2 * \left| \frac{L_{t} - P_{t-1}}{P_{t+1} - P_{t-1}} - \frac{1}{2} \right| \]</span></p>
<p>and while this is a lovely equation, it is difficult to implement on your own.</p>
<p>and while this is a lovely equation, it might be difficult to implement on one’s own.</p>
</div>
<div id="whats-the-issue" class="section level1">
<h1>What’s the Issue?</h1>
Expand Down Expand Up @@ -51,18 +51,21 @@ <h1>The Function</h1>
<pre class="r"><code>burkina_faso &lt;- burkina_faso %&gt;%

#&#39; Group by country and legislative election.

dplyr::group_by(country_name, leg_elect_year) %&gt;%

#&#39; Use &quot;first&quot; and &quot;na.omit&quot; to find the next presidential
#&#39; election in the data. Using these two commands will find
#&#39; the first non-NA value in a column. This new variable is
#&#39; called &quot;next_election&quot;.

dplyr::mutate(next_election = dplyr::first(na.omit(pres_elect_year))) %&gt;%

#&#39; Regroup by just country. We don&#39;t care about years at this point.
#&#39; Then we fill out the &quot;next_election&quot; variable. Instead of filling
#&#39; down the data, we want to fill up (imagine we are dragging the future
#&#39; election up to the current legislative election).

dplyr::group_by(country_name) %&gt;%
tidyr::fill(next_election, .direction = &quot;up&quot;)</code></pre>
<ol start="2" style="list-style-type: decimal">
Expand All @@ -75,6 +78,7 @@ <h1>The Function</h1>
<pre class="r"><code>burkina_faso &lt;- burkina_faso %&gt;%

#&#39; We can now, in one fell swoop, calculate Cox&#39;s electoral proximity.

dplyr::mutate(cox_prox = ifelse(leg_elect_dum == 1,
2 * abs(
(
Expand All @@ -84,20 +88,21 @@ <h1>The Function</h1>
cox_prox = ifelse(is.nan(cox_prox), 1, cox_prox)) %&gt;%

#&#39; Fill out the variable.

tidyr::fill(cox_prox)</code></pre>
</div>
<div id="burkina-fasos-electoral-proximity" class="section level1">
<h1>Burkina Faso’s Electoral Proximity</h1>
<p>Let’s plot how electoral proximity changes over time in Burkina Faso.</p>
<pre class="r"><code>ggplot(burkina_faso, aes(x = year)) +
geom_line(aes(y = cox_prox), size = 2, color = &quot;purple&quot;) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = &quot;dotted&quot;) +
geom_line(aes(y = cox_prox), size = 2, color = &quot;purple&quot;, na.rm = TRUE) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = &quot;dotted&quot;, na.rm=TRUE) +
labs(title = paste0(&quot;Electoral Proximity in &quot;, unique(burkina_faso$country_name)),
x = &quot;Year&quot;,
y = &quot;Electoral Proximity (Cox, 1997)&quot;) +
theme_classic()
## Warning: Removed 18 rows containing missing values (geom_path).
## Warning: Removed 51 rows containing missing values (geom_vline).</code></pre>
<p><img src="/posts/test_files/figure-html/unnamed-chunk-4-1.png" width="672" />
Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I’m going to plot a few more countries and see if I find any more intresting patterns.</p>
theme_classic()</code></pre>
<p><img src="/posts/test_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I’m going to plot a few more countries and see if I find any more intresting patterns.</p>
<p>In the meantime, feel free to check out the related code for this post <a href="https://github.com/tjbrailey/Functions">here</a>. Please leave any comments and feedback in the “Issues” section of GitHub.</p>
<p>Thanks for reading!</p>
</div>
20 changes: 15 additions & 5 deletions public/posts/test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ burkina_faso <- rio::import("C:/Users/tbrai/Dropbox/Constitutions Project/Data/E

# What is Electoral Proximity?

Electoral proximity is the measure of fractionalization between a presidential and legislative election. That is, how temporally separated a state's legislative and presidential elections might be. If presidential and legislative elections occur on the same day, they are considered to be proximally maximal. If there is a considerable gap between elections, then there is considered to be less proximity between elections. Gary Cox termed this phrase in Making Votes Count (1997) and builds off of the work of Matthew Shugart, John Carey, Rein Taagepera, and others. Why is electoral proximity important? Cox suggests that it taps into executive-legislative behaviors; others note that greater proximity of presidential and legislative elections tend tends to reduce the number of effective parties in a state. In any case, being able to calculate a state's electoral proximity could open the door to some interesting studies.
Electoral proximity is the measure of fractionalization between a presidential and legislative election. That is, how temporally separated a state's legislative and presidential elections might be. If presidential and legislative elections occur on the same day, they are considered to be proximally maximal. If there is a considerable gap between elections, then there is considered to be less proximity between elections. Gary Cox termed this phrase in Making Votes Count (1997) and builds off of the work of Matthew Shugart, John Carey, Rein Taagepera, and others. Why is electoral proximity important? Cox suggests that it taps into executive-legislative behaviors; others note that greater proximity of presidential and legislative elections tend tends to reduce the number of effective parties in a state. In any case, being able to calculate a state's electoral proximity could open the door to some interesting studies.

# How is Electoral Proximity Calculated?

Per Cox (1997), electoral proximity can be estimated as follows:

$$ PROXIMITY = 2 * \left| \frac{L_{t} - P_{t-1}}{P_{t+1} - P_{t-1}} - \frac{1}{2} \right| $$

and while this is a lovely equation, it is difficult to implement on your own.
and while this is a lovely equation, it might be difficult to implement on one's own.

# What's the Issue?

Expand All @@ -53,18 +53,21 @@ Here is a step-by-step run-through of how I calculated electoral proximity in Bu
burkina_faso <- burkina_faso %>%
#' Group by country and legislative election.
dplyr::group_by(country_name, leg_elect_year) %>%
#' Use "first" and "na.omit" to find the next presidential
#' election in the data. Using these two commands will find
#' the first non-NA value in a column. This new variable is
#' called "next_election".
dplyr::mutate(next_election = dplyr::first(na.omit(pres_elect_year))) %>%
#' Regroup by just country. We don't care about years at this point.
#' Then we fill out the "next_election" variable. Instead of filling
#' down the data, we want to fill up (imagine we are dragging the future
#' election up to the current legislative election).
dplyr::group_by(country_name) %>%
tidyr::fill(next_election, .direction = "up")
```
Expand All @@ -83,6 +86,7 @@ $\textit{next_election}$ = $P_{t+1}$
burkina_faso <- burkina_faso %>%
#' We can now, in one fell swoop, calculate Cox's electoral proximity.
dplyr::mutate(cox_prox = ifelse(leg_elect_dum == 1,
2 * abs(
(
Expand All @@ -92,6 +96,7 @@ burkina_faso <- burkina_faso %>%
cox_prox = ifelse(is.nan(cox_prox), 1, cox_prox)) %>%
#' Fill out the variable.
tidyr::fill(cox_prox)
```

Expand All @@ -100,14 +105,19 @@ burkina_faso <- burkina_faso %>%
Let's plot how electoral proximity changes over time in Burkina Faso.
```{r}
ggplot(burkina_faso, aes(x = year)) +
geom_line(aes(y = cox_prox), size = 2, color = "purple") +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = "dotted") +
geom_line(aes(y = cox_prox), size = 2, color = "purple", na.rm = TRUE) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = "dotted", na.rm=TRUE) +
labs(title = paste0("Electoral Proximity in ", unique(burkina_faso$country_name)),
x = "Year",
y = "Electoral Proximity (Cox, 1997)") +
theme_classic()
```
Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I'm going to plot a few more countries and see if I find any more intresting patterns.

Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I'm going to plot a few more countries and see if I find any more intresting patterns.

In the meantime, feel free to check out the related code for this post [here](https://github.com/tjbrailey/Functions). Please leave any comments and feedback in the "Issues" section of GitHub.

Thanks for reading!



Expand Down
23 changes: 14 additions & 9 deletions public/posts/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h1 class="title">Calculating Electoral Proximity in R</h1>
</span>
<span class="reading-time">
<i class="fas fa-clock"></i>
4-minute read
5-minute read
</span>
</div>
<div class="categories">
Expand Down Expand Up @@ -194,7 +194,7 @@ <h1>What is Electoral Proximity?</h1>
<h1>How is Electoral Proximity Calculated?</h1>
<p>Per Cox (1997), electoral proximity can be estimated as follows:</p>
<p><span class="math display">\[ PROXIMITY = 2 * \left| \frac{L_{t} - P_{t-1}}{P_{t+1} - P_{t-1}} - \frac{1}{2} \right| \]</span></p>
<p>and while this is a lovely equation, it is difficult to implement on your own.</p>
<p>and while this is a lovely equation, it might be difficult to implement on one’s own.</p>
</div>
<div id="whats-the-issue" class="section level1">
<h1>What’s the Issue?</h1>
Expand Down Expand Up @@ -229,18 +229,21 @@ <h1>The Function</h1>
<pre class="r"><code>burkina_faso &lt;- burkina_faso %&gt;%

#&#39; Group by country and legislative election.

dplyr::group_by(country_name, leg_elect_year) %&gt;%

#&#39; Use &quot;first&quot; and &quot;na.omit&quot; to find the next presidential
#&#39; election in the data. Using these two commands will find
#&#39; the first non-NA value in a column. This new variable is
#&#39; called &quot;next_election&quot;.

dplyr::mutate(next_election = dplyr::first(na.omit(pres_elect_year))) %&gt;%

#&#39; Regroup by just country. We don&#39;t care about years at this point.
#&#39; Then we fill out the &quot;next_election&quot; variable. Instead of filling
#&#39; down the data, we want to fill up (imagine we are dragging the future
#&#39; election up to the current legislative election).

dplyr::group_by(country_name) %&gt;%
tidyr::fill(next_election, .direction = &quot;up&quot;)</code></pre>
<ol start="2" style="list-style-type: decimal">
Expand All @@ -253,6 +256,7 @@ <h1>The Function</h1>
<pre class="r"><code>burkina_faso &lt;- burkina_faso %&gt;%

#&#39; We can now, in one fell swoop, calculate Cox&#39;s electoral proximity.

dplyr::mutate(cox_prox = ifelse(leg_elect_dum == 1,
2 * abs(
(
Expand All @@ -262,22 +266,23 @@ <h1>The Function</h1>
cox_prox = ifelse(is.nan(cox_prox), 1, cox_prox)) %&gt;%

#&#39; Fill out the variable.

tidyr::fill(cox_prox)</code></pre>
</div>
<div id="burkina-fasos-electoral-proximity" class="section level1">
<h1>Burkina Faso’s Electoral Proximity</h1>
<p>Let’s plot how electoral proximity changes over time in Burkina Faso.</p>
<pre class="r"><code>ggplot(burkina_faso, aes(x = year)) +
geom_line(aes(y = cox_prox), size = 2, color = &quot;purple&quot;) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = &quot;dotted&quot;) +
geom_line(aes(y = cox_prox), size = 2, color = &quot;purple&quot;, na.rm = TRUE) +
geom_vline(aes(xintercept = ifelse(leg_elect_dum == 1, year, NA)), linetype = &quot;dotted&quot;, na.rm=TRUE) +
labs(title = paste0(&quot;Electoral Proximity in &quot;, unique(burkina_faso$country_name)),
x = &quot;Year&quot;,
y = &quot;Electoral Proximity (Cox, 1997)&quot;) +
theme_classic()
## Warning: Removed 18 rows containing missing values (geom_path).
## Warning: Removed 51 rows containing missing values (geom_vline).</code></pre>
<p><img src="/posts/test_files/figure-html/unnamed-chunk-4-1.png" width="672" />
Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I’m going to plot a few more countries and see if I find any more intresting patterns.</p>
theme_classic()</code></pre>
<p><img src="/posts/test_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>Interesting! Following independence, BK had concurrent elections which became progressively less concurrent until 2015, when they aligned once again. I’m going to plot a few more countries and see if I find any more intresting patterns.</p>
<p>In the meantime, feel free to check out the related code for this post <a href="https://github.com/tjbrailey/Functions">here</a>. Please leave any comments and feedback in the “Issues” section of GitHub.</p>
<p>Thanks for reading!</p>
</div>

</div>
Expand Down
Binary file removed static/posts/test_files/figure-html/pressure-1.png
Binary file not shown.
Binary file not shown.

0 comments on commit ce8dab1

Please sign in to comment.