-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path33_multivariate_analysis.Rmd
186 lines (154 loc) · 5.33 KB
/
33_multivariate_analysis.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# multivariate analysis of digital- & geo-politics
plot correlation over time:
```{r}
library(tidyverse)
library(magrittr)
analysis_data %<>%
mutate(year = year(date)) %>%
filter(year != 2024)
analysis_data_doclevel %<>%
mutate(year = year(date)) %>%
filter(year != 2024)
```
define function:
```{r}
plot_cor_trend <- function(var1, var2, groupingvar, plot_title = "", plot_subtitle = "", plotname = "cor_trend"){
# groupgvariabel should be a year
data <- tibble(
var1 = var1,
var2 = var2,
year = groupingvar
)
cor_data <- data %>%
group_by(year) %>%
summarise(cor = cor.test(var1, var2)$estimate,
lower = cor.test(var1, var2)$conf.int[1],
upper = cor.test(var1, var2)$conf.int[2]
)
cor_trend_plot <-
ggplot(cor_data,
aes(x = year, y = cor)) +
geom_hline(yintercept = 0, linetype ="dotted") +
geom_errorbar(aes(ymin = lower, ymax = upper), colour = "grey", width = 0.2) +
geom_point() +
geom_line() +
labs(x = "Year",
y = "Correlation (with 95% CI)",
title = plot_title,
subtitle = plot_subtitle) +
theme_bw()
ggsave(paste0("output/plots/bivariate/", plotname, ".png"),
cor_trend_plot,
width = 24, height = 27, units = "cm")
return(cor_trend_plot)
}
```
doclevel shares:
```{r}
plot_cor_trend(analysis_data_doclevel$share_digital_para,
analysis_data_doclevel$cm_external_share,
analysis_data_doclevel$year,
"Correlation of digital- and geopolitics over time",
"share of paragraphs classified as 'digital' and share of non-EU states mentioned (document level)",
"cor_trend_dig_share_external_doc")
```
paralevel shares:
```{r}
plot_cor_trend(analysis_data$zs_max,
analysis_data$cm_external,
analysis_data$year,
"Correlation of digital- and geopolitics over time",
"share of paragraphs classified as 'digital' and share of non-EU states mentioned (paragraph level)",
"cor_trend_dig_external_para")
```
```{r}
plot_cor_trend(analysis_data$zs_max,
analysis_data$RU,
analysis_data$year,
"Correlation of digital- and geopolitics over time",
"'digitality' score and mentions of Russia (paragraph level)",
"cor_trend_para_zs_RU")
```
```{r}
plot_cor_trend(analysis_data$zs_max,
analysis_data$cm_BRICS,
analysis_data$year,
"Correlation of digital- and geopolitics over time",
"'digitality' score and mentions of Russia (paragraph level)",
"cor_trend_para_zs_BRICS")
```
```{r}
plot_cor_trend(analysis_data$zs_max,
analysis_data$CN,
analysis_data$year,
"Correlation of digital- and geopolitics over time",
"'digitality' score and mentions of China (paragraph level)",
"cor_trend_para_zs_CN")
```
faceted:
```{r}
plot_title <- "Correlation of digital- and geopolitics over time"
plot_subtitle <- "'digitality' classification and mentions of Great Powers (paragraph level)"
plotname <- "cor_trend_para_zs_powers"
analysis_data_long <-
analysis_data %>%
pivot_longer(US:RU,
names_to = "facet",
values_to = "mentions")
cor_data <- analysis_data_long %>%
group_by(year, facet) %>%
summarise(cor = cor.test(zs_digital, mentions)$estimate,
lower = cor.test(zs_digital, mentions)$conf.int[1],
upper = cor.test(zs_digital, mentions)$conf.int[2]
)
cor_trend_plot <-
ggplot(cor_data,
aes(x = year, y = cor)) +
geom_hline(yintercept = 0, linetype ="dotted") +
geom_errorbar(aes(ymin = lower, ymax = upper), colour = "grey", width = 0.2) +
geom_point() +
geom_line() +
facet_wrap(vars(facet), nrow = 3) +
labs(x = "Year",
y = "Correlation (with 95% CI)",
title = plot_title,
subtitle = plot_subtitle) +
theme_bw()
ggsave(paste0("output/plots/bivariate/", plotname, ".png"),
cor_trend_plot,
width = 24, height = 27, units = "cm")
cor_trend_plot
```
```{r}
plot_title <- "Correlation of digital- and geopolitics over time"
plot_subtitle <- "'digitality' classification and mentions of country groups (paragraph level)"
plotname <- "cor_trend_para_zsbin_groups"
analysis_data_long <-
analysis_data %>%
pivot_longer(cm_EU:cm_BRICSplus,
names_to = "facet",
values_to = "mentions")
cor_data <- analysis_data_long %>%
group_by(year, facet) %>%
summarise(cor = cor.test(zs_digital, mentions)$estimate,
lower = cor.test(zs_digital, mentions)$conf.int[1],
upper = cor.test(zs_digital, mentions)$conf.int[2]
)
cor_trend_plot <-
ggplot(cor_data,
aes(x = year, y = cor)) +
geom_hline(yintercept = 0, linetype ="dotted") +
geom_errorbar(aes(ymin = lower, ymax = upper), colour = "grey", width = 0.2) +
geom_point() +
geom_line() +
facet_wrap(vars(facet), nrow = 3) +
labs(x = "Year",
y = "Correlation (with 95% CI)",
title = plot_title,
subtitle = plot_subtitle) +
theme_bw()
ggsave(paste0("output/plots/bivariate/", plotname, ".png"),
cor_trend_plot,
width = 24, height = 27, units = "cm")
cor_trend_plot
```