-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.qmd
138 lines (114 loc) · 3.44 KB
/
model.qmd
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
---
title: "Model"
format: html
execute:
echo: false
---
$$y_{i} = \beta_{0} + \beta_{1} modern + \beta_{2}great + \beta_{3}nuclear$$
We are using a linear model with error terms on the dependent variable of whether armed hostility occurs in a given conflict. Our model predicts negative relationships between nuclear possession, great power status, and modernity with chance of severe escalation.
```{r}
#| label: setup
#| message: false
library(tidyverse)
library(dplyr)
library(primer.data)
library(brms)
library(tidybayes)
library(gtsummary)
```
```{r}
#| label: data
DYMID<-read.csv("dyadic_mid_4.02.csv")
DYMID$year <- as.integer(DYMID$year)
DYMID$strtyr <- as.integer(DYMID$strtyr)
DYMID_N <- DYMID %>% mutate(modern=case_when((strtyr<1945)~0,(strtyr>=1945)~1))
DYMID_N <- DYMID_N %>% mutate(nucleara = case_when(
(strtyr<1945) ~ 0,
(
((namea=="USA") & (strtyr >= 1945)) |
((namea=="RUS") & (strtyr >= 1949)) |
((namea=="UKG") & (strtyr >= 1952)) |
((namea=="FRN") & (strtyr >= 1960)) |
((namea=="CHN") & (strtyr >= 1964)) |
((namea=="ISR") & (strtyr >= 1966)) |
((namea=="IND") & (strtyr >= 1974)) |
((namea=="PAK") & (strtyr >= 1998)) |
((namea=="PRK") & (strtyr >= 2006))
) ~ 1,
stateb > 450 ~ 0),
nuclearb = case_when(
(strtyr<1945) ~ 0,
(
((nameb=="USA") & (strtyr >= 1945)) |
((nameb=="RUS") & (strtyr >= 1949)) |
((nameb=="UKG") & (strtyr >= 1952)) |
((nameb=="FRN") & (strtyr >= 1960)) |
((nameb=="CHN") & (strtyr >= 1964)) |
((nameb=="ISR") & (strtyr >= 1966)) |
((nameb=="IND") & (strtyr >= 1974)) |
((nameb=="PAK") & (strtyr >= 1998)) |
((nameb=="PRK") & (strtyr >= 2006))
) ~ 1,
strtyr >= 1945 ~ 0)
) %>%
select(nucleara,nuclearb,strtyr,namea,nameb,everything()) %>%
arrange(desc(nucleara))
DYMID_N <- DYMID_N %>% mutate(greata = case_when(
((namea=="AUH") & (strtyr <= 1918)) |
((namea=="CHN") & (strtyr >= 1896)) |
((namea=="UKG") & (strtyr >= 1952)) |
(namea=="FRN") |
(namea=="GMY") |
(namea=="ITA") |
(namea=="RUS") |
(namea=="UKG") |
(namea=="USA") ~ TRUE,
TRUE ~ FALSE
),
greatb = case_when(
((nameb=="AUH") & (strtyr <= 1918)) |
((nameb=="CHN") & (strtyr >= 1896)) |
((nameb=="UKG") & (strtyr >= 1952)) |
(nameb=="FRN") |
(nameb=="GMY") |
(nameb=="ITA") |
(nameb=="RUS") |
(nameb=="UKG") |
(nameb=="USA") ~ TRUE,
TRUE ~ FALSE
),
)
DYMID_N <- DYMID_N |> drop_na() %>% mutate(nuclear=nucleara+nuclearb) %>%
select(nuclear,everything()) %>%
arrange(desc(nuclear))
DYMID_N <- DYMID_N |> drop_na() %>% mutate(great=greata+greatb) %>%
select(great,everything()) %>%
arrange(desc(great))
DYMID_N <- DYMID_N |> mutate(modern=case_when(
(strtyr<=1945)~FALSE,
(strtyr>1945)~TRUE,
TRUE ~ NA))
DYMID_N <- DYMID_N |>
mutate(escalated=case_when(
(hihost<=3)~FALSE,
(hihost>3)~TRUE,
TRUE ~ NA))
DYMID_N <- (DYMID_N |> drop_na())
DYMID_N <- DYMID_N |> select(great, nuclear,strtyr,modern,outcome,hihost,escalated,settlmnt,fatlev,highact,cumdurat)
DYMID_N <- DYMID_N |> mutate(great=as.factor(great))
DYMID_N <- DYMID_N |> mutate(nuclear=as.factor(nuclear))
set.seed(9)
nuclear_data <- DYMID_N |>
drop_na()
```
```{r}
#| label: model
#| cache: true
fit_nuclear<-brm(formula = escalated ~ modern+great+nuclear, data = nuclear_data, family = bernoulli(), refresh = 0, silent = 2, seed = 19)
```
```{r}
#| label: plot
#| message: false
fit_nuclear |>
tbl_regression()
```