-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUN_voting_topics.Rmd
82 lines (59 loc) · 1.92 KB
/
UN_voting_topics.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: "UN_voting_topics"
output: html_document
date: "2022-12-14"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
# Transform topic data into tidy data
topics <- UN_voting %>%
gather(topic, has_topic, me:ec) %>%
filter(has_topic == 1) %>%
mutate(topic = recode(topic,
me = "Palestinian conflict",
nu = "Nuclear weapons and nuclear material",
di = "Arms control and disarmament",
hr = "Human rights",
co = "Colonialism",
ec = "Economic development"))
```
```{r}
# Clean Countrynames
unique(topics$Countryname)
topics$Countryname[topics$Countryname == "C\xf4te d\x92Ivoire"] <- "Cote dIvoire"
topics$Countryname[topics$Countryname == "S\xe3o Tom\xe9 & Pr\xedncipe"] <- "Sao Tome and Principe"
```
```{r}
# Plot "agreebleness" of topics
by_year_topic <- topics %>%
group_by(year, topic) %>%
summarize(total = n(),
percent_yes = mean(vote == 1)) %>%
ungroup()
ggplot(by_year_topic, aes(year, percent_yes)) +
geom_line() +
facet_wrap(~ topic)
```
```{r}
# Summarize the percentage "yes" per country-year-topic
by_country_year_topic <- topics %>%
group_by(Countryname, year, topic) %>%
summarize(total = n(),
percent_yes = mean(vote == 1)) %>%
ungroup()
```
```{r}
# Tidy modeling by country and topic
country_topic_coefficients <- by_country_year_topic %>%
nest(-Countryname, -topic) %>%
mutate(model = map(data, ~ lm(percent_yes ~ year, data = .)),
tidied = map(model, tidy)) %>%
unnest(tidied)
# Filter for slope and significant observations
country_topic_filtered <- country_topic_coefficients %>%
filter(term == "year") %>%
mutate(p.adjusted = p.adjust(p.value)) %>%
filter(p.adjusted < .05)
```