-
Notifications
You must be signed in to change notification settings - Fork 0
/
919_replication_code.R
169 lines (141 loc) · 5.05 KB
/
919_replication_code.R
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
##Cody Crunkilton
##919 Replication Paper: Horowitz 2009 Replication
##Data available via the Journal of Conflict Resolution website.
##Spring 2017
setwd("C:/Users/Cody/Dropbox/1school2016_7/919/horowitz 2009")
library(readstata13)
library(rjags)
library(runjags)
#############################################getting the data
d<-read.dta13("JCRNuclearAgeReplication.dta")
#############################################removing the missing data
remove <- d[which(d$Sdy=="NA")]
head(remove)
d_noNA <- d[!is.na(d$Sdy),]
dim(d)
dim(d_noNA)
##############################################small model
log_model1<-"
model {for (i in 1:N) {
y[i]~dbern(p[i])
logit(p[i])<-b0+b1*x1[i]+b2*x2[i]+b3*x3[i]+b4*x4[i]
}
b0~dnorm(0,.000001)
b1 ~ dnorm(0,1.0e-4)
b2 ~ dnorm(0,1.0e-4)
b3 ~ dnorm(0,1.0e-4)
b4 ~ dnorm(0,1.0e-4)
}
"
posterior1_year<- run.jags(log_model1_year, monitor=c("b1","b2","b3","b4","b0"),
data=with(d,
list(y=reciprocation,
x1=sideAnuclear,
x2=sideBnuclear,
x3=sideAnuclearage,
x4=sideBnuclearage,
N=length(reciprocation))),
burnin=1000, sample=1000, thin=1,
n.chains=2)
summary(posterior1)
######################################full model with flat priors
log_modelfull<-"
model {for (i in 1:N) {
y[i]~dbern(p[i])
logit(p[i])<-b0+b1*x1[i]+b2*x2[i]+b3*x3[i]+b4*x4[i]
+b5*x5[i]+b6*x6[i]+b7*x7[i]+b8*x8[i]
+b9*x9[i]+b10*x10[i]+b11*x11[i]+b12*x12[i]
}
b0~dnorm(0,1.0e-4)
b1 ~ dnorm(0,1.0e-4)
b2 ~ dnorm(0,1.0e-4)
b3 ~ dnorm(0,1.0e-4)
b4 ~ dnorm(0,1.0e-4)
b5 ~ dnorm(0,1.0e-4)
b6 ~ dnorm(0,1.0e-4)
b7 ~ dnorm(0,1.0e-4)
b8 ~ dnorm(0,1.0e-4)
b9 ~ dnorm(0,1.0e-4)
b10 ~ dnorm(0,1.0e-4)
b11 ~ dnorm(0,1.0e-4)
b12~ dnorm(0,1.0e-4)
}
"
posterior_full<- run.jags(log_modelfull, monitor=c("b1","b2","b3","b4","b0"),
data=with(d_noNA,
list(y=reciprocation,
x1=sideAnuclear,
x2=sideBnuclear,
x3=sideAnuclearage,
x4=sideBnuclearage,
x5=jointnuke,
x6=sideAbof,
x7=Sdy,
x8=dem1,
x9=dem2,
x10=territory,
x11=regimegovernment,
x12=policy,
N=length(reciprocation))),
burnin=1000, sample=1000, thin=1,
n.chains=2)
summary(posterior_full)
#########################################Full model w/ US, Russia controls
log_modelfull_USR<-"
model {for (i in 1:N) {
y[i]~dbern(p[i])
logit(p[i])<-b0+b1*x1[i]+b2*x2[i]+b3*x3[i]+b4*x4[i]
+b5*x5[i]+b6*x6[i]+b7*x7[i]+b8*x8[i]
+b9*x9[i]+b10*x10[i]+b11*x11[i]+b12*x12[i]
+b13*x13[i]+b14*x14[i]
}
b0~dnorm(0,1.0e-4)
b1 ~ dnorm(0,1.0e-4)
b2 ~ dnorm(0,1.0e-4)
b3 ~ dnorm(0,1.0e-4)
b4 ~ dnorm(0,1.0e-4)
b5 ~ dnorm(0,1.0e-4)
b6 ~ dnorm(0,1.0e-4)
b7 ~ dnorm(0,1.0e-4)
b8 ~ dnorm(0,1.0e-4)
b9 ~ dnorm(0,1.0e-4)
b10 ~ dnorm(0,1.0e-4)
b11 ~ dnorm(0,1.0e-4)
b12~ dnorm(0,1.0e-4)
b13~ dnorm(0,1.0e-4)
b14~ dnorm(0,1.0e-4)
}
"
posterior_full_USR<- run.jags(log_modelfull_USR, monitor=c("b1","b2","b3","b4","b0"),
data=with(d_noNA,
list(y=reciprocation,
x1=sideAnuclear,
x2=sideBnuclear,
x3=sideAnuclearage,
x4=sideBnuclearage,
x5=jointnuke,
x6=sideAbof,
x7=Sdy,
x8=dem1,
x9=dem2,
x10=territory,
x11=regimegovernment,
x12=policy,
x13=US,
x14=Russia,
N=length(reciprocation))),
burnin=1000, sample=1000, thin=1,
n.chains=2)
summary(posterior_full_USR)
###########################################making plots
plot(posterior1, plot.type = "histogram")
plot(posterior_full, plot.type = "histogram")
plot(posterior_full_USR, plot.type = "density")
#############################################tables for latex
library(stargazer)
model1 <- posterior1$hpd
model2 <- posterior_full$hpd
model3 <- posterior_full_USR$hpd
stargazer(model1)
stargazer(model2)
stargazer(model3)