-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResults.R
222 lines (203 loc) · 6.3 KB
/
Results.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
library(tidyverse)
library(broom)
results =
tibble(
n.nuclei = params$n.nuclei,
k = params$E_peers,
w = params$w,
gamma = params$gamma,
phi_y = stats$phi,
phi_k = stats$phi_m,
Q = stats$Q,
r = params$r,
N = stats$N,
y = stats$f.smokers,
n_gold = stats$n.gold,
y_gold = stats$f.smokers_gold,
n_0 = stats$n.0,
y_0 = stats$f.smokers_0,
n_p = stats$n.p,
y_p = stats$f.smokers_p,
n_hp = stats$n.hp,
y_hp = stats$f.smokers_hp,
n_yu = stats$n.y,
y_yu = stats$f.smokers_y,
n_hyu = stats$n.hy,
y_hyu = stats$f.smokers_hy,
) %>%
mutate(
err_gold = y_gold - y,
err_p = y_p - y,
err_hp = y_hp - y,
err_yu = y_yu - y,
err_hyu = y_hyu - y,
err_0 = y_0 - y,
abs_gold = abs(err_gold),
abs_p = abs(err_p),
abs_hp = abs(err_hp),
abs_yu = abs(err_yu),
abs_hyu = abs(err_hyu),
abs_0 = abs(y_0 - y),
delta_p = (abs_gold - abs_p)/y,
delta_yu = (abs_gold - abs_yu)/y,
delta_hp = (abs_0 - abs_hp)/y,
delta_hyu = (abs_0 - abs_hyu)/y
) %>% mutate(
gamma_l = cut_number(gamma,4,
c("Low",
"Mid-Low",
"Mid-High",
"High")),
ub_p = err_p + .01,
ub_yu = err_yu + .01,
ub_hp = err_hp + .01,
ub_hyu = err_hyu + .01,
delta_ubp = (abs_gold - abs(ub_p)) / y,
delta_ubyu = (abs_gold - abs(ub_yu)) / y,
delta_ubhp = (abs_gold - abs(ub_hp)) / y,
delta_ubhyu = (abs_gold - abs(ub_hyu)) / y
)
library(ggdensity)
library(cowplot)
ggdraw() +
draw_plot(
results %>% ggplot(aes(x=phi_y,
y=phi_k)) +
geom_hdr() +
ylab(bquote(varphi[k])) +
xlab(bquote(varphi[y])) +
theme_linedraw(base_size = 30)+
theme(legend.position = "top")
) +
draw_image(magick::image_read("gamma.png"),
scale = .25, x = .4, y = -.1)
ggsave("phis.png")
results %>%
select(k,w,gamma,phi_y,phi_k,r,N,y,Q,abs_gold) %>%
names() %>%
paste('scale(abs_p)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(-statistic) %>%
mutate_if(is.numeric,round,3) %>%
kableExtra::kable("latex", booktabs = T) %>%
kableExtra::kable_styling(latex_options = c("scale_down"))
results %>%
select(k,w,gamma,phi_y,phi_k,Q,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_hp)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept"))%>%
arrange(p.value) %>% select(-statistic) %>%
mutate_if(is.numeric,round,3) %>%
kableExtra::kable("latex", booktabs = T) %>%
kableExtra::kable_styling(latex_options = c("scale_down"))
results %>%
select(k,w,gamma,phi_y,phi_k,Q,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_yu)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept"))%>%
arrange(p.value) %>% select(-statistic) %>%
mutate_if(is.numeric,round,3) %>%
kableExtra::kable("latex", booktabs = T) %>%
kableExtra::kable_styling(latex_options = c("scale_down"))
results %>%
select(k,w,gamma,phi_y,phi_k,Q,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_hyu)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>%
mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(-statistic) %>%
mutate_if(is.numeric,round,3)
###
results %>%
select(w,gamma,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_p)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(term, estimate) %>%
mutate_if(is.numeric,round,3) %>%
left_join(
results %>%
select(w,gamma,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_yu)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(term, estimate) %>%
mutate_if(is.numeric,round,3), by = "term"
) %>%
left_join(
results %>%
select(w,gamma,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_hp)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(term, estimate) %>%
mutate_if(is.numeric,round,3), by = "term"
) %>%
left_join(
results %>%
select(w,gamma,r,N,y,abs_gold) %>%
names() %>%
paste('scale(abs_hyu)~',.)%>%
map_df(~tidy(lm(as.formula(.x),
data= results %>% select(-gamma_l) %>% mutate_all(scale)
))) %>%
filter(!term %>% str_detect("Intercept")) %>%
arrange(p.value) %>% select(term, estimate) %>%
mutate_if(is.numeric,round,3), by = "term"
) %>% add_column(.after = "term", Concept = c(
"Stage 0", "Homophily", "Familism",
"Attrition", "Target Quota", "Pop. Size"
)) %>%
rename(I = estimate.x,
II = estimate.y,
III = estimate.x.x,
IV = estimate.y.y) %>%
kableExtra::kable("latex")
###
results %>% summarise(
cor = cor(gamma,phi_k),
cor2 = cor(gamma,phi_y),
cor3 = cor(phi_k,phi_y)
)
results %>% ggplot() +
geom_density(aes(err_gold), color = "goldenrod", size = 2) +
#geom_density(aes(err_0), size = 2) +
geom_density(aes(err_p), color = "purple", size = 2) +
xlab("Error") +
ylab("") +
facet_wrap(~gamma_l)+
theme_classic(base_size = 20)
###
results %>%
mutate(id = cur_group_rows(), .before = "n.nuclei") %>%
filter(abs(err_gold) > .055) %>% pull(id) -> redo
results$err_gold %>% max()
results %>% select(c(starts_with("err"),gamma_l)) %>%
pivot_longer(cols = starts_with("err"),
names_to = "Sampling") %>%
ggplot() +
geom_boxplot(aes(x = Sampling,
y = value))+
facet_wrap(~gamma_l)
results$err_gold