-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpairs_plot_code.R
More file actions
267 lines (219 loc) · 8.71 KB
/
pairs_plot_code.R
File metadata and controls
267 lines (219 loc) · 8.71 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
##----------------------------------------------------------------
## Calculate CCC of all pairwise combinations -
##----------------------------------------------------------------
#pairs <- combn(sort(levels(core_pars$inter)), 2)
pairs <- combn(levels(core_pars$inter), 2)
all_pars_l <- vector("list", ncol(pairs))
for (i in seq_len(ncol(pairs))) {
tmp_dat <- core_pars %>%
filter(inter %in% pairs[,i]) %>%
mutate(inter = factor(inter,
levels = unique(as.character(unlist(pairs[,i]))))) %>%
select(model, model2, dataset, condition, parameter, est, inter) %>%
spread(key = inter, value = est)
colnames(tmp_dat)[(ncol(tmp_dat)-1):ncol(tmp_dat)] <- c("x", "y")
tmp_dat$cond_x <- pairs[1,i]
tmp_dat$cond_y <- pairs[2,i]
all_pars_l[[i]] <- tmp_dat
}
all_pars2 <- bind_rows(all_pars_l)
#all_pars2 <- left_join(all_pars2, trials)
all_pars2 <- all_pars2 %>%
mutate(
cond_x = factor(cond_x, levels =
levels(all_pars$inter)[unique(all_pars2$cond_x) %in%
levels(all_pars$inter)]),
cond_y = factor(cond_y, levels =
levels(all_pars$inter)[unique(all_pars2$cond_y) %in%
levels(all_pars$inter)])
)
all_pars3 <- all_pars2 %>%
# filter(restriction == "rrest", parameter %in% c("Do", "Dn", "g")) %>%
# mutate(parameter = factor(parameter,
# levels = c("Do", "Dn", "g"))) %>%
mutate(cond_x2 = cond_y,
cond_y2 = cond_x)
# all_ccc <- all_pars2 %>%
# group_by(cond_x, cond_y) %>%
# summarise(ccc = CCC(x, y, na.rm = TRUE)$rho.c$est) %>%
# ungroup() %>%
# mutate(id = seq_len(nrow(.)))
#
# ## plot of CCC for "rrest" variant across parameters
# all_ccc %>%
# ggplot(aes(x = cond_x, y = ccc)) +
# ggbeeswarm::geom_beeswarm(aes(color = cond_y),
# cex = 0.6, alpha = 0.9, #color = "darkgrey",
# size = 1.5) +
# stat_summary(fun.data = mean_se)
# ggsave("cccs1.png", width = 28, height = 18, units = "cm",
# dpi = 500)
##----------------------------------------------------------------
## Selected CCC Plots -
##----------------------------------------------------------------
# all_pars_a3 <- all_pars_a3 %>%
# filter(!(model %in% "pm"))
# dput(levels(all_pars_a3$cond_x))
# dput(levels(all_pars_a3$cond_y))
all_pars3 %>%
filter(cond_x == "Comp MLE", cond_y == "Comp Bayes")
p1 <- plot_pair(all_pars3, "Comp MLE", "No PB", FALSE) +
labs(x = "Complete Pooling MLE", y = "No Pooling: P-Bootstrap")
p2 <- plot_pair(all_pars3, "Comp MLE", "Trait PP", FALSE) +
labs(x = "Complete Pooling MLE", y = "Bayesian Latent Trait")
p3 <- plot_pair(all_pars3, "No PB", "Trait PP", FALSE) +
labs(x = "No Pooling: P-Bootstrap", y = "Bayesian Latent Trait")
cowplot::plot_grid(p2, p1, p3, nrow = 1)
ggsave("figures/pairsplot_selected_1.png", width = 36, height = 12,
units = "cm", dpi = 500)
cowplot::plot_grid(
p2 + geom_smooth(),
p1 + geom_smooth(),
p3 + geom_smooth(),
nrow = 1)
ggsave("figures/pairsplot_selected_2.png", width = 36, height = 12,
units = "cm", dpi = 500)
plot_pair(all_pars3, "No asy", "Trait PP", FALSE) +
geom_smooth()
all_pars3 %>%
filter(cond_x == "Comp MLE", cond_y == "Trait PP") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev)) %>%
print(n = 40)
all_pars3 %>%
filter(cond_x == "Comp MLE", cond_y == "No PB") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev))
all_pars3 %>%
filter(cond_x == "No PB", cond_y == "Trait PP") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev)) %>%
print(n = 20)
### pairs plot without pair clustering model
p1 <- all_pars3 %>%
filter(!(model == "pc")) %>%
plot_pair("Comp MLE", "No PB", FALSE) +
labs(x = "Complete Pooling MLE", y = "No Pooling: P-Bootstrap")
p2 <- all_pars3 %>%
filter(!(model == "pc")) %>%
plot_pair("Comp MLE", "Trait PP", FALSE) +
labs(x = "Complete Pooling MLE", y = "Bayesian Latent Trait")
p3 <- all_pars3 %>%
filter(!(model == "pc")) %>%
plot_pair("No PB", "Trait PP", FALSE) +
labs(x = "No Pooling: P-Bootstrap", y = "Bayesian Latent Trait")
cowplot::plot_grid(p2, p1, p3, nrow = 1)
ggsave("figures/pairsplot_selected_1-no-PC.png", width = 36, height = 12,
units = "cm", dpi = 500)
all_pars3 %>%
filter(!(model == "pc")) %>%
filter(cond_x == "Comp MLE", cond_y == "Trait PP") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev))
all_pars3 %>%
filter(!(model == "pc")) %>%
filter(cond_x == "Comp MLE", cond_y == "No PB") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev))
all_pars3 %>%
filter(!(model == "pc")) %>%
filter(cond_x == "No PB", cond_y == "Trait PP") %>%
mutate(adev = abs(x - y)) %>%
arrange(desc(adev)) %>%
print(n = 20)
all_pars3 %>%
filter(!(model == "pc")) %>%
droplevels() %>%
{length(unique(.$parameter))}
all_pars3 %>%
filter(!(model == "pc")) %>%
filter(cond_x == "Comp MLE", cond_y == "Comp Bayes")
##----------------------------------------------------------------
## Pairs Plot All -
##----------------------------------------------------------------
pars_plot <- all_pars3
plot_text <- pars_plot %>%
group_by(cond_x2, cond_y2) %>%
summarise(ccc = format(
CCC(x, y, na.rm = TRUE)$rho.c$est,
digits = 2))
pars_plot %>%
ggplot(aes(x = x, y = y)) +
geom_abline(slope = 1, intercept = 0) +
geom_point(alpha = 0.15) + #aes(size = trials)
facet_grid(cond_x2~ cond_y2, switch = "both", as.table = FALSE) +
# geom_text(data=plot_text,
# aes(x = 0.2, y = 0.9, label=ccc),
# parse = TRUE, inherit.aes=FALSE, size = 5) +
coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
scale_size(range = c(0.5, 2.5)) +
labs(x = "", y = "") +
theme(legend.position = "none")
ggsave("figures/pairsplot_all.png", width = 33, height = 28, units = "cm",
dpi = 500)
pars_plot %>%
filter(cond_x == "Comp Bayes") %>%
filter(x < 0.05, y > 0.5) %>%
print(n = 1e5)
#################
for (i in levels(pars_plot$model)) {
pars_plot <- pars_plot %>%
mutate(Selected = factor(if_else(model == i, toupper(i), "other"),
levels = c(toupper(i), "other"))) %>%
arrange(desc(Selected))
pars_plot %>%
ggplot(aes(x = x, y = y)) +
geom_abline(slope = 1, intercept = 0) +
geom_point(aes(color = Selected), alpha = 0.33) + #aes(size = trials)
facet_grid(cond_x2~ cond_y2, switch = "both", as.table = FALSE) +
# geom_text(data=plot_text,
# aes(x = 0.2, y = 0.9, label=ccc),
# parse = TRUE, inherit.aes=FALSE, size = 5) +
coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
scale_size(range = c(0.5, 2.5)) +
labs(x = "", y = "") +
theme(legend.position = "none") +
scale_colour_manual(values = c("red", "black"))
ggsave(paste0("figures/pairsplot_all_", i, ".png"),
width = 33, height = 28, units = "cm", dpi = 500)
}
for (i in levels(pars_plot$model)) {
pars_plot <- pars_plot %>%
mutate(Selected = factor(if_else(model == i, toupper(i), "other"),
levels = c(toupper(i), "other"))) %>%
arrange(Selected)
pars_plot %>%
ggplot(aes(x = x, y = y)) +
geom_abline(slope = 1, intercept = 0) +
geom_point(aes(color = Selected), alpha = 0.33) + #aes(size = trials)
facet_grid(cond_x2~ cond_y2, switch = "both", as.table = FALSE) +
# geom_text(data=plot_text,
# aes(x = 0.2, y = 0.9, label=ccc),
# parse = TRUE, inherit.aes=FALSE, size = 5) +
coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
scale_size(range = c(0.5, 2.5)) +
labs(x = "", y = "") +
theme(legend.position = "none") +
scale_colour_manual(values = c("red", "black"))
ggsave(paste0("figures/pairsplot_all_", i, "_2.png"),
width = 33, height = 28, units = "cm", dpi = 500)
}
all_pars_a3 <- all_pars_a2 %>%
# filter(restriction == "rrest", parameter %in% c("Do", "Dn", "g")) %>%
# mutate(parameter = factor(parameter,
# levels = c("Do", "Dn", "g"))) %>%
mutate(cond_x2 = cond_y,
cond_y2 = cond_x) %>%
filter(!(str_detect(dataset, "Smith et al 2014")))
all_pars_a3 %>%
ggplot(aes(x = x, y = y)) +
geom_abline(slope = 1, intercept = 0) +
geom_point(alpha = 0.15) + #aes(size = trials)
facet_grid(cond_x2~ cond_y2, switch = "both", as.table = FALSE) +
coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
scale_size(range = c(0.5, 2.5)) +
geom_smooth() +
labs(x = "", y = "") +
theme(legend.position = "none")
ggsave("figures/pairsplot_no-all.png", width = 33, height = 28,
units = "cm", dpi = 500)