-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
2309 lines (2043 loc) · 95.3 KB
/
README.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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Can visualization alleviate dichotomous thinking? Effects of visual representations on the cliff effect"
author: "Jouni Helske, Satu Helske, Matthew Cooper, Anders Ynnerman, Lonni Besançon"
date: "13/4/2020"
output:
github_document:
fig_width: 12
fig_height: 12
toc: true
toc_depth: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, width = 150)
```
# What is this
This repository contains data and scripts for reproducing the analysis of the paper *Can visualization alleviate dichotomous thinking? Effects of visual representations on the cliff effect* by Jouni Helske, Satu Helske, Matthew Cooper, Anders Ynnerman, and Lonni Besançon.
This Rmd file contains full scripts (and extra stuff) to reproduce figures in the paper.
The raw data for both experiments can be found in folders `experiment1/data/` and `experiment2/data/` respectively, which also contains the R data frames used in the analysis (`exp1_data.rds` and `exp2_data.rds`). The web pages for the surveys are in folder `web`, with some screenshots in folder `screenshots`.
## One-sample experiment
### Creating the dataset
First, we load some packages:
```{r load_packages}
suppressPackageStartupMessages({
library(brms)
library(modelr)
library(ggplot2)
library(dplyr)
library(jsonlite)
library(loo)
library(ggthemes)
})
```
Then we transform the raw data to suitable format for analysis:
```{r create_data_exp1, eval = FALSE}
path <- "experiment1/data"
answers <- list.files(path, pattern="answers", full.names = TRUE)
# fetch number of participants
n <- length(answers)
# create a data frame for the results
data_raw <- data.frame(id = rep(1:n, each = 32), viz = NA, replication = NA, value = NA,
expertise = NA, degree = NA, age = NA, experience = NA, tools = NA)
# read in answers, not optimal way will do
for(i in 1:n){
x <- strsplit(fromJSON(answers[i]), ",")
dem <- fromJSON(paste0(path, "/demography", x[[1]][1], ".txt"))
for(j in 1:32) {
data_raw[32*(i-1) + j, c("id", "viz", "replication", "value")] <- x[[j]]
data_raw[32*(i-1) + j, c("expertise", "degree", "age", "experience", "tools")] <-
dem[c("expertise", "level", "age", "experience", "tools")]
}
}
saveRDS(data_raw, file = "experiment1/data/data_raw.rds")
# remove person who didn't answer reasonably on the demography part
# Degree is None and more importantly expertise is 1..?
data <- data_raw[data_raw$degree != "None",]
# true p-values
true_p <- c(0.001, 0.01, 0.04, 0.05, 0.06, 0.1, 0.5, 0.8)
# convert to factors and numeric
data <- data %>% mutate(n = factor(ifelse(as.numeric(id) %% 8 < 4, 50, 200)),
id = factor(id),
viz = relevel(factor(viz, labels = c("CI", "gradient", "p", "violin")), "p"),
replication = as.numeric(replication),
value = as.numeric(value),
p = true_p[replication],
true_p = factor(p), # for monotonic but non-linear effect on confidence
confidence = (value - 1) / 99,
expertise = factor(expertise)) %>% arrange(id, viz)
# Classify expertise
data$expertise <- recode_factor(data$expertise,
"Statistics" = "Stats/ML",
"statistics" = "Stats/ML",
"statistics/machine learning" = "Stats/ML",
"Analytics" = "Stats/ML",
"Statistics/Medicine" = "Stats/ML",
"Data science" = "Stats/ML",
"Biostatistics" = "Stats/ML",
"IT & Business Data Science" = "Stats/ML",
"methods" = "Stats/ML",
"AI" = "Stats/ML",
"Neuroscience and Statistics" = "Stats/ML",
"Computer vision" = "Stats/ML",
"Psychometric" = "Stats/ML",
"HCI, Visualization" = "VIS/HCI",
"HCI/Visualization" = "VIS/HCI",
"interaction design and evaluation" = "VIS/HCI",
"Human-Computer Interaction" = "VIS/HCI",
"HCI" = "VIS/HCI",
"Vis" = "VIS/HCI",
"Visualization" = "VIS/HCI",
"Data Visualization" = "VIS/HCI",
"CS, Visualization, HCI" = "VIS/HCI",
"Infovis" = "VIS/HCI",
"Visualization / Computer Science" = "VIS/HCI",
"Virtual Reality" = "VIS/HCI",
"Visualisation" = "VIS/HCI",
"research in HCI" = "VIS/HCI",
"Computer science" = "VIS/HCI",
"Computer Science" = "VIS/HCI",
"Social science" = "Social science and humanities",
"Political science" = "Social science and humanities",
"sociology" = "Social science and humanities",
"Sociology" = "Social science and humanities",
"Analytical Sociology" = "Social science and humanities",
"Education research" = "Social science and humanities",
"Economics" = "Social science and humanities",
"market research" = "Social science and humanities",
"Politics" = "Social science and humanities",
"Finance" = "Social science and humanities",
"Linguistics" = "Social science and humanities",
"Education Poliy" = "Social science and humanities",
"Political Science" = "Social science and humanities",
"Psychology" = "Social science and humanities",
"psychology" = "Social science and humanities",
"segregation" = "Social science and humanities",
"Philosophy" = "Social science and humanities",
"organizational science" = "Social science and humanities",
"Strategic Management" = "Social science and humanities",
"network analysis" = "Social science and humanities",
"CSS" = "Social science and humanities",
"Management" = "Social science and humanities",
"Animal science" = "Physical and life sciences",
"Biology" = "Physical and life sciences",
"Botany" = "Physical and life sciences",
"ecology" = "Physical and life sciences",
"Zoology" = "Physical and life sciences",
"Physics" = "Physical and life sciences",
"cognitive neuroscience" = "Physical and life sciences",
"Neuroscience" = "Physical and life sciences",
"neuroscience/motor control" = "Physical and life sciences",
"Biomechanics" = "Physical and life sciences",
"Neurocognitive Psychology" = "Physical and life sciences",
"pharma" = "Physical and life sciences",
"Public health" = "Physical and life sciences",
"neurobiology" = "Physical and life sciences",
"medicine" = "Physical and life sciences",
"Molcular Biology" = "Physical and life sciences",
"Wind Energy" = "Physical and life sciences",
"Mathematical Biology" = "Physical and life sciences",
"Pain" = "Physical and life sciences",
"genomics" = "Physical and life sciences",
"Medicine" = "Physical and life sciences",
"Water engineering" = "Physical and life sciences")
data$expertise <- relevel(data$expertise, "Stats/ML")
```
### Descriptive statistics
```{r, cache = TRUE, echo = FALSE}
data <- readRDS("experiment1/data/exp1_data.rds")
```
Let's first look at some descriptive statistic:
```{r, cache = TRUE}
ids <- which(!duplicated(data$id))
barplot(table(data$expertise[ids]))
barplot(table(data$degree[ids]))
hist(as.numeric(data$age[ids]))
```
Let us now focus on the cliff effect as difference between confidence when $p$-value=0.04 versus $p$-value=0.06:
```{r cliff_effect_exp1, cache = TRUE}
data %>% group_by(id, viz) %>%
summarize(difference = confidence[true_p==0.04] - confidence[true_p==0.06]) %>%
group_by(viz) %>%
summarise(
mean = mean(difference),
median = median(difference),
sd = sd(difference),
se = sd(difference) / sqrt(length(difference)),
"2.5%" = quantile(difference, 0.025),
"97.5%" = quantile(difference, 0.975))
data %>% group_by(id, viz) %>%
summarize(difference = confidence[true_p==0.04] - confidence[true_p==0.06]) %>%
ggplot(aes(x = viz, y = difference)) +
geom_violin() +
geom_point(alpha = 0.5, position = position_jitter(0.1)) +
scale_y_continuous("Difference in confidence when p-value is 0.06 vs 0.04") +
scale_x_discrete("Representation") +
theme_classic()
```
The cliff effect seems to be largest when information is presented as traditional CI or $p$-value which behave similarly. Gradient CI and Violin CI plots are pretty close to each other.
Now same but with subgrouping using sample size:
```{r cliff_effect_n_exp1, cache = TRUE}
data %>% group_by(id, viz, n) %>%
summarize(difference = confidence[true_p==0.04] - confidence[true_p==0.06]) %>%
group_by(viz, n) %>%
summarise(
mean = mean(difference),
median = median(difference),
sd = sd(difference),
se = sd(difference) / sqrt(length(difference)),
"2.5%" = quantile(difference, 0.025),
"97.5%" = quantile(difference, 0.975))
```
and expertise:
```{r cliff_effect_expertise_exp1, cache = TRUE}
data %>% group_by(id, viz, expertise) %>%
summarize(difference = confidence[true_p==0.04] - confidence[true_p==0.06]) %>%
group_by(viz, expertise) %>%
summarise(
mean = mean(difference),
median = median(difference),
sd = sd(difference),
se = sd(difference) / sqrt(length(difference)),
"2.5%" = quantile(difference, 0.025),
"97.5%" = quantile(difference, 0.975))
```
In terms of sample size, there doesn't seem to be clear differences in cliff effect especially when considering medians. In terms of expertise, there seems to be some differences especially in terms of variability (most notably the Violin plot for VIS/HCI), but the differences are likely due to few very extreme cases:
```{r cliff_effect_n_exp1_plot, cache = TRUE}
data %>% group_by(id, viz, expertise) %>%
summarize(
difference = confidence[true_p==0.04] - confidence[true_p==0.06]) %>%
ggplot(aes(x=viz, y = difference)) + geom_violin() + theme_classic() +
scale_y_continuous("Difference in confidence when p-value is 0.04 vs 0.06") +
scale_x_discrete("Representation") +
geom_point(aes(colour = expertise), position=position_jitter(0.1))
```
Let's check how the much extreme answers (full or zero confidence) there are in different groups:
```{r extreme_exp1, cache = TRUE}
data %>% group_by(id, viz, n) %>%
mutate(extreme = confidence %in% c(0, 1)) %>%
group_by(viz, n) %>%
summarise(
mean = mean(extreme),
sd = sd(extreme),
se = sd(extreme) / sqrt(length(extreme)))
data %>% group_by(id, viz, expertise) %>%
mutate(extreme = confidence %in% c(0, 1)) %>%
group_by(viz, expertise) %>%
summarise(
mean = mean(extreme),
sd = sd(extreme),
se = sd(extreme) / sqrt(length(extreme)))
```
Stats/ML and VIS/HCI groups tend to give slightly more extreme answers, but differences are quite small.
### Model
For modelling the data and the potential cliff effect we use piece-wise logit-normal model with following pdf:
$$
p(x)=\begin{cases}
\alpha (1 - \gamma), & \text{if $x = 0$},\\
\alpha \gamma, & \text{if $x = 1$},\\
(1 - \alpha) \phi(logit(x), \mu, \sigma), & \text{otherwise}.\\
\end{cases}
$$
Here $\alpha = P(x \in \{0, 1\})$ is the probability of answering one of the extreme values (not at all confident or fully confident), and $\gamma = P(x = 1 \mid x \in \{0, 1\})$, is the conditional probability of full confidence given that the answer is one of the extremes.
For $\mu$,$\alpha$,$\gamma$, and $\sigma$, we define following linear predictors:
$$
\begin{align}
\begin{split}
\mu &\sim viz \cdot I(p < 0.05) \cdot logit(p) +
viz \cdot I(p = 0.05) \\
& + (viz + I(p < 0.05) \cdot logit(p) + I(p = 0.05) \mid id),\\
\alpha &\sim p \cdot viz + (1 \mid id),\\
\gamma &\sim mo(p),\\
\sigma &\sim viz + (1 \mid id),
\end{split}
\end{align}
$$
where $p$ is a categorical variable defining the true $p$-value, logit($p$) is a continuous variable of the logit-transformed $p$-value, $mo(p)$ denotes a monotonic effect of the $p$-value, the dot corresponds to interaction (\ie $I(p = 0.05) \cdot viz$ \rev{implies} both the main and two-way interaction terms) and $(z \mid id)$ denotes participant-level random effect for variable $z$. As priors we used the relatively uninformative defaults of the \texttt{brms} package.
Now in a presence of a cliff effect we should observe a discontinuity in an otherwise linear relationship (in logit-logit scale) between the true $p$-value and participants' confidence.
We also tested submodels of this model (omitting some of the interactions or random effects), and all of these models gave very similar results. However, this encompassing model integrates over the uncertainty regarding the parameter estimates (with coefficient zero corresponding to simpler model where the variable is omitted) and is that sense "more Bayesian" than selecting some of the simpler models (note that we are not particularly interested in predictive performance).
Now we create the necessary functions for our model:
```{r create_model, eval = TRUE, cache = TRUE}
stan_funs <- "
real logit_p_gaussian_lpdf(real y, real mu, real sigma,
real zoi, real coi) {
if (y == 0) {
return bernoulli_lpmf(1 | zoi) + bernoulli_lpmf(0 | coi);
} else if (y == 1) {
return bernoulli_lpmf(1 | zoi) + bernoulli_lpmf(1 | coi);
} else {
return bernoulli_lpmf(0 | zoi) + normal_lpdf(logit(y) | mu, sigma);
}
}
real logit_p_gaussian_rng(real y, real mu, real sigma,
real zoi, real coi) {
// 0 or 1
int zero_one = bernoulli_rng(zoi);
if (zero_one == 1) {
// casting to real
int one = bernoulli_rng(coi);
if (one == 1) {
return 1.0;
} else {
return 0.0;
}
} else {
return inv_logit(normal_rng(mu, sigma));
}
}
"
log_lik_logit_p_gaussian <- function(i, draws) {
# mu <- draws$dpars$mu[, i]
# zoi <- draws$dpars$zoi[, i]
# coi <- draws$dpars$coi[, i]
# sigma <- draws$dpars$sigma
# y <- draws$data$Y[i]
mu <- brms:::get_dpar(draws, "mu", i = i)
zoi <- brms:::get_dpar(draws, "zoi", i = i)
coi <- brms:::get_dpar(draws, "coi", i = i)
sigma <- brms:::get_dpar(draws, "sigma", i = i)
y <- draws$data$Y[i]
if (y == 0) {
dbinom(1, 1, zoi, TRUE) + dbinom(0, 1, coi, TRUE)
} else if (y == 1) {
dbinom(1, 1, zoi, TRUE) + dbinom(1, 1, coi, TRUE)
} else {
dbinom(0, 1, zoi, TRUE) + dnorm(qlogis(y), mu, sigma, TRUE)
}
}
predict_logit_p_gaussian <- function(i, draws, ...) {
mu <- brms:::get_dpar(draws, "mu", i = i)
zoi <- brms:::get_dpar(draws, "zoi", i = i)
coi <- brms:::get_dpar(draws, "coi", i = i)
sigma <- brms:::get_dpar(draws, "sigma", i = i)
zero_one <- rbinom(length(zoi), 1, zoi)
ifelse(zero_one, rbinom(length(coi), 1, coi), plogis(rnorm(length(mu), mu, sigma)))
}
fitted_logit_p_gaussian <- function(draws) {
mu <- draws$dpars$mu
zoi <- draws$dpars$zoi
coi <- draws$dpars$coi
sigma <- draws$dpars$sigma
# no analytical solution for the mean of logistic normal distribution, rely on simulation
for (i in 1:ncol(mu)) {
for(j in 1:nrow(mu)) {
mu[j, i] <- mean(plogis(rnorm(1000, mu[j, i], sigma[j])))
}
}
zoi * coi + (1 - zoi) * mu
}
logit_p_gaussian <- custom_family(
"logit_p_gaussian",
dpars = c("mu", "sigma", "zoi", "coi"),
links = c("identity", "log", "logit", "logit"),
lb = c(NA, 0, 0, 0), ub = c(NA, NA, 1, 1),
type = "real",
log_lik = log_lik_logit_p_gaussian,
predict = predict_logit_p_gaussian,
fitted = fitted_logit_p_gaussian)
```
And create few additional variables:
```{r additional_vars_exp1, cache = TRUE}
data <- data %>%
mutate(
logit_p = qlogis(p),
p_lt0.05 = factor(p < 0.05, levels = c(TRUE, FALSE), labels = c("Yes", "No")),
p_eq0.05 = factor(p == 0.05, levels = c(TRUE, FALSE), labels = c("Yes", "No")),
cat_p = recode_factor(true_p,
"0.06" = ">0.05", "0.1" = ">0.05", "0.5" = ">0.05", "0.8" = ">0.05",
.ordered = TRUE))
```
```{r, eval = FALSE}
fit_exp1 <- brm(bf(
confidence ~
viz * p_lt0.05 * logit_p +
viz * p_eq0.05 +
(viz + p_lt0.05 * logit_p + p_eq0.05 | id),
zoi ~
viz * true_p + (viz | id),
coi ~ mo(cat_p),
sigma ~ viz + (1 | id)),
data = data,
family = logit_p_gaussian,
stanvars = stanvar(scode = stan_funs, block = "functions"),
chains = 4, cores = 4, iter = 2000, init = 0,
save_warmup = FALSE, save_all_pars = TRUE, refresh = 0)
```
### Results
First, let us check the parameter estimates of the model:
```{r fit_exp1_read, cache = TRUE, echo = FALSE}
fit_exp1 <- readRDS("experiment1/results/fit_noexpertise.rds")
```
```{r fit_exp1, cache = TRUE}
fit_exp1
```
Now we look at some figures. First we draw some samples from posterior predictive distribution and see how well our simulated replications match with our data:
```{r pp_check_exp1_a, cache = TRUE}
pp_check(fit_exp1, type = "hist", nsamples = 11)
```
We see that the histograms of the replicated datasets are similar to observed one, perhaps slight exaggeration of the tails. Next, we look the median confidence of replicated datasets grouped with underlying $p$-value:
```{r pp_check_exp1_b, cache = TRUE}
pp_check(fit_exp1, type = "stat_grouped", group = "true_p", stat = "median")
```
Now grouping based on visualization:
```{r pp_check_exp1_c, cache = TRUE}
pp_check(fit_exp1, type = "stat_grouped", group = "viz", stat = "mean")
```
Noting the scale on the x-axis, our histograms look reasonable given our data, although there are some subgroups where our model is slightly over- or underestimating compared to our data, especially in the violin CI group (reasonable changes to our model, such as dropping some interaction terms, did not improve this). Same posterior checks for average participants (with random effects zeroed out) we get very good results:
```{r pp_check_exp1_b_norandom, cache = TRUE}
pp_check(fit_exp1, type = "stat_grouped", group = "true_p", stat = "median", re_formula = NA)
pp_check(fit_exp1, type = "stat_grouped", group = "viz", stat = "mean", re_formula = NA)
```
Now we are ready to analyze the results. First, the posterior curves of the confidence given the underlying $p$-value:
```{r, cache = TRUE}
comb_exp1 <- fit_exp1$data %>%
data_grid(viz, logit_p, p_lt0.05, p_eq0.05, cat_p, true_p) %>%
filter(interaction(logit_p, p_lt0.05, p_eq0.05, cat_p, true_p) %in%
unique(interaction(
fit_exp1$data$logit_p, fit_exp1$data$p_lt0.05,
fit_exp1$data$p_eq0.05, fit_exp1$data$cat_p,
fit_exp1$data$true_p)))
f_mu_exp1 <- posterior_epred(fit_exp1, newdata = comb_exp1, re_formula = NA)
d <- data.frame(value = c(f_mu_exp1),
p = rep(comb_exp1$true_p, each = nrow(f_mu_exp1)),
viz = rep(comb_exp1$viz, each = nrow(f_mu_exp1)),
iter = 1:nrow(f_mu_exp1))
levels(d$viz) <- c("Textual", "Classic CI", "Gradient CI", "Violin CI")
```
```{r posterior_curves_exp1, cache = TRUE}
sumr <- d %>% group_by(viz, p) %>%
summarise(Estimate = mean(value),
Q2.5 = quantile(value, 0.025),
Q97.5 = quantile(value, 0.975)) %>%
mutate(p = as.numeric(levels(p))[p])
cols <- c("Textual" = "#D55E00", "Classic CI" = "#0072B2",
"Gradient CI" = "#009E73", "Violin CI" = "#CC79A7")
x_ticks <- c(0.001, 0.01, 0.04, 0.06, 0.1, 0.5, 0.8)
y_ticks <- c(0.05, seq(0.1, 0.9, by = 0.1), 0.95)
dodge <- 0.19
p1 <- sumr %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14,
margin = margin(t = -0.1, r = 0, b = -0.1, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14,
margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07), ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p2 <- sumr %>% filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
p <- p1 + coord_cartesian(xlim = c(0.001, 0.9), ylim = c(0.045, 0.95)) +
annotation_custom(
ggplotGrob(p2),
xmin = qlogis(0.2), xmax = qlogis(0.9), ymin = qlogis(0.3), ymax = qlogis(0.95))
p
```
```{r, echo = FALSE, eval = FALSE}
ggsave(p, filename = "experiment1/results/exp1_confidence.pdf",
width = 2*8.5, height = 12.5,
unit = "cm", device = "pdf")
```
The confidence level with traditional CI is most constant of all techniques when are within "statistically significant region" i.e. $p<0.05$, but there is a large drop when moving to $p>0.05$, even larger than with textual information with $p$-value, which behaves nearly identically with the Violin CI plot until $p=0.05$, when the confidence in $p$-value representation drops below all other techniques. The Gradient CI plot and Violin CI plot behave similarly, except the confidence level in case of Gradient CI plot is constantly below the Violin CI plot.
The probability curves of extreme answer show that traditional CI produces more easily extreme answers when $p<0.05$ (so the extreme answer is likely of full confidence), whereas $p$-value is more likely to lead extreme answer (zero confidence) when $p>0.05$. Differences between techniques seem nevertheless quite small compared to overall variation in the estimates.
```{r extreme_exp1_plot, cache = TRUE}
f_zoi_exp1_sumr <- fitted(fit_exp1, newdata = comb_exp1,
re_formula = NA, dpar = "zoi")
df_01_exp1 <- data.frame(
p = plogis(comb_exp1$logit_p),
viz = comb_exp1$viz,
f_zoi_exp1_sumr)
levels(df_01_exp1$viz) <-
c("Textual", "Classic CI", "Gradient CI", "Violin CI")
y_ticks <- c(0.0001, 0.01, seq(0.1,0.9,by=0.2))
p <- df_01_exp1 %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_linerange(aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(width=0.19)) +
geom_line(alpha=0.5, position = position_dodge(width=0.19)) +
ylab("Probability of all-or-none answer") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
theme_classic() +
scale_y_continuous(trans = "logit",
breaks = y_ticks, labels = y_ticks, minor_breaks = NULL) +
scale_x_continuous(trans = "logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 10), legend.position = "bottom",
axis.title.x = element_text(size = 12),
axis.text.y = element_text(size = 10), axis.title.y = element_text(size = 12),
legend.text=element_text(size = 10), strip.text.x = element_text(size = 10))
p
```
Finally, we can compute the average drop in perceived confidence when moving from $p = 0.04$ to $p=0.06$:
```{r drop1, cache = TRUE}
d %>% group_by(viz, iter) %>%
summarise(difference = value[p == "0.04"] - value[p == "0.06"]) %>%
summarise(mean = mean(difference), sd = sd(difference),
"2.5%" = quantile(difference, 0.025),
"97.5" = quantile(difference, 0.975))
```
Let's also visualize this:
```{r, cache = TRUE}
p <- d %>% group_by(viz, iter) %>%
summarise(difference = value[p == "0.04"] - value[p == "0.06"]) %>%
ggplot(aes(x = difference, fill = viz, colour = viz)) +
geom_density(bw = 0.01, alpha = 0.6) +
theme_classic() +
scale_fill_manual("Representation", values = cols) +
scale_colour_manual("Representation", values = cols) +
ylab("Posterior density") +
xlab("E[confidence(p=0.04) - confidence(p=0.06)]") +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
legend.text = element_text(size = 14))
p
```
```{r, echo = FALSE, eval = FALSE}
ggsave(p, filename = "experiment1/results/exp1_cliff.pdf",
width = 2*8.5, height = 6.5,
unit = "cm", device = "pdf")
```
Note that the cliff effect between viz styles are not independent, i.e. if there is a large cliff effect with Violin CI then the cliff effect with $p$-value is likely larger as well. This can be seen from the posterior probabilities that cliff effect is larger with viz 1 (row variable) than with viz 2 (column variable):
```{r 'postprob1', cache = TRUE}
postprob <- d %>% group_by(viz, iter) %>%
summarise(difference = value[p == "0.04"] - value[p == "0.06"]) %>%
group_by(iter) %>%
mutate(p_vs_ci = difference[viz == "Textual"] - difference[viz == "Classic CI"],
p_vs_gradient = difference[viz == "Textual"] - difference[viz == "Gradient CI"],
p_vs_violin = difference[viz == "Textual"] - difference[viz == "Violin CI"],
ci_vs_gradient = difference[viz == "Classic CI"] - difference[viz == "Gradient CI"],
ci_vs_violin = difference[viz == "Classic CI"] - difference[viz == "Violin CI"],
gradient_vs_violin = difference[viz == "Gradient CI"] -
difference[viz == "Violin CI"]) %>%
ungroup() %>% summarise(
"P(p > CI)" = mean(p_vs_ci > 0),
"P(p > gradient)" = mean(p_vs_gradient > 0),
"P(p > violin)" = mean(p_vs_violin > 0),
"P(CI > gradient)" = mean(ci_vs_gradient > 0),
"P(CI > violin)" = mean(ci_vs_violin > 0),
"P(gradient > violin)" = mean(gradient_vs_violin > 0),
"P(p > CI)" = mean(p_vs_ci > 0))
round(t(as.data.frame(postprob)), 2)
```
### Results for the model with expertise
Now we consider expanded model with with expertise as predictor:
```{r, eval = FALSE, cache = TRUE}
fit_expertise <- brm(bf(
confidence ~
expertise * viz * p_lt0.05 * logit_p +
expertise * viz * p_eq0.05 +
(viz + p_lt0.05 * logit_p + p_eq0.05 | id),
zoi ~
expertise * viz + viz * true_p + (viz | id),
coi ~ mo(cat_p),
sigma ~ expertise * viz + (1 | id)),
data = data,
family = logit_p_gaussian,
stanvars = stanvar(scode = stan_funs, block = "functions"),
chains = 4, cores = 4, iter = 2000, init = 0,
save_warmup = FALSE, save_all_pars = TRUE, refresh = 0)
```
```{r, eval = TRUE, cache = TRUE, echo = FALSE}
fit_expertise <- readRDS("experiment1/results/fit_expertise.rds")
```
```{r, cache = TRUE}
comb_exp1 <- fit_expertise$data %>%
data_grid(expertise, viz, logit_p, p_lt0.05, p_eq0.05, cat_p, true_p) %>%
filter(interaction(expertise, logit_p, p_lt0.05, p_eq0.05, cat_p, true_p) %in%
unique(interaction(fit_expertise$data$expertise,
fit_expertise$data$logit_p, fit_expertise$data$p_lt0.05,
fit_expertise$data$p_eq0.05, fit_expertise$data$cat_p,
fit_expertise$data$true_p)))
f_mu_exp1 <- posterior_epred(fit_expertise, newdata = comb_exp1, re_formula = NA)
d <- data.frame(value = c(f_mu_exp1),
p = rep(comb_exp1$true_p, each = nrow(f_mu_exp1)),
viz = rep(comb_exp1$viz, each = nrow(f_mu_exp1)),
expertise = rep(comb_exp1$expertise, each = nrow(f_mu_exp1)),
iter = 1:nrow(f_mu_exp1))
levels(d$viz) <- c("Textual", "Classic CI", "Gradient CI", "Violin CI")
```
Here are posterior curves for the four different groups:
```{r 'posterior_curves_exp1_expertise', cache = TRUE}
sumr <- d %>% group_by(viz, p, expertise) %>%
summarise(Estimate = mean(value),
Q2.5 = quantile(value, 0.025),
Q97.5 = quantile(value, 0.975)) %>%
mutate(p = as.numeric(levels(p))[p])
x_ticks <- c(0.001, 0.01, 0.04, 0.06, 0.1, 0.5, 0.8)
y_ticks <- c(0.05, seq(0.1, 0.9, by = 0.1), 0.95)
dodge <- 0.19
p11 <- sumr %>% filter(expertise == "Stats/ML") %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.margin = margin(t = -0.1, b = 0, unit = "cm"),
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14,
margin = margin(t = -0.1, r = 0, b = -0.3, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14,
margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07),
ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p21 <- sumr %>% filter(expertise == "Stats/ML") %>%
filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
yrange <- c(min(sumr$Q2.5)-0.001, max(sumr$Q97.5) +0.001)
p1 <- p11 + coord_cartesian(xlim = c(0.001, 0.9),
ylim = yrange) +
annotation_custom(
ggplotGrob(p21),
xmin = qlogis(0.2), xmax = qlogis(0.9), ymin = qlogis(0.3), ymax = qlogis(0.95))
p12 <- sumr %>% filter(expertise == "VIS/HCI") %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks, minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14, margin = margin(t = -0.1, r = 0, b = -0.3, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14, margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07), ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p22 <- sumr %>% filter(expertise == "VIS/HCI") %>%
filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
p2 <- p12 + coord_cartesian(xlim = c(0.001, 0.9), ylim = yrange) +
annotation_custom(
ggplotGrob(p22),
xmin = qlogis(0.2), xmax = qlogis(0.9), ymin = qlogis(0.3), ymax = qlogis(0.95))
p13 <- sumr %>% filter(expertise == "Social science and humanities") %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks, minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14, margin = margin(t = -0.1, r = 0, b = -0.3, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14, margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07), ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p23 <- sumr %>% filter(expertise == "Social science and humanities") %>%
filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
p3 <- p13 + coord_cartesian(xlim = c(0.001, 0.9), ylim = yrange) +
annotation_custom(
ggplotGrob(p23),
xmin = qlogis(0.2), xmax = qlogis(0.9), ymin = qlogis(0.3), ymax = qlogis(0.95))
p14 <- sumr %>% filter(expertise == "Physical and life sciences") %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks, minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14, margin = margin(t = -0.1, r = 0, b = -0.3, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14, margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07), ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p24 <- sumr %>% filter(expertise == "Physical and life sciences") %>%
filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
p4 <- p14 + coord_cartesian(xlim = c(0.001, 0.9), ylim = yrange) +
annotation_custom(
ggplotGrob(p24),
xmin = qlogis(0.2), xmax = qlogis(0.9), ymin = qlogis(0.3), ymax = qlogis(0.95))
library(patchwork)
p <- (p1 + ggtitle("Stats/ML")) + (p2 + ggtitle("VIS/HCI")) +
(p3 + ggtitle("Social sciences and humanities")) +
(p4 + ggtitle("Physical and life sciences"))
p
```
There are some differences between confidence curves between groups: In Physical and life sciences the visualization affects only little on the confidence curves; gradient CI and violin CI produce very linear curves in VIS/HCI group; and there is very large drop in confidence in case of classic CI in Stats/ML group. However, the ordering in terms of cliff effect is same in all groups.
We can also draw same figure when averaging over the groups:
```{r posterior_curves_exp1_marginal, cache = TRUE}
sumr <- d %>% group_by(viz, p) %>%
summarise(Estimate = mean(value),
Q2.5 = quantile(value, 0.025),
Q97.5 = quantile(value, 0.975)) %>%
mutate(p = as.numeric(levels(p))[p])
p1 <- sumr %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(dodge), size = 0.1) +
geom_linerange(data = sumr %>% filter(p < 0.03 | p > 0.07),
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(dodge), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(dodge), size = 0.7, show.legend = FALSE) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = x_ticks, labels = x_ticks, minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
axis.text.x = element_text(size = 12, angle = 45, hjust = 1, vjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14,
margin = margin(t = -0.1, r = 0, b = -0.3, l = 0, unit = "cm")),
axis.title.y = element_text(size = 14,
margin = margin(t = 0, r = -0.1, b = 0, l = -0.1, unit = "cm")),
legend.text = element_text(size = 14)) +
geom_rect(xmin = qlogis(0.03), xmax = qlogis(0.07), ymin = qlogis(0.31), ymax = qlogis(0.82),
color = "grey70", alpha = 0, linetype = "dashed", size = 0.1) +
guides(colour = guide_legend(override.aes = list(size = 1.5)))
p2 <- sumr %>% filter(p > 0.02 & p < 0.09) %>%
ggplot(aes(x = p, y = Estimate, colour = viz)) +
geom_line(position = position_dodge(0.1), size = 0.1) +
geom_linerange(
aes(ymin = Q2.5, ymax = Q97.5),
position = position_dodge(0.1), size = 0.3,
show.legend = FALSE) +
geom_point(position = position_dodge(0.1), size = 0.7) +
ylab("Confidence") + xlab("p-value") +
scale_color_manual("Representation", values = cols) +
scale_y_continuous(trans="logit", breaks = y_ticks,
minor_breaks = NULL, labels = y_ticks) +
scale_x_continuous(trans="logit",
breaks = c(0.04, 0.05, 0.06),
labels = c(0.04, 0.05, 0.06),
minor_breaks = NULL) +
theme_classic() +
theme(legend.position = "none",
axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.background = element_blank(),
plot.margin=unit(c(-4,-9,0,0), "mm"),