-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRev-FigureS4-Percent-Censored.R
57 lines (51 loc) · 2.63 KB
/
Rev-FigureS4-Percent-Censored.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
# //////////////////////////////////////////////////////////////////////
# Replicate Figure S2 in Supplementary Materials //////////////////////
# Caption begins "We explored light (~17%), heavy (~49%), and extra ////
# heavy (~82%) censoring in Weibull $X$, induced by generating ... /////
# //////////////////////////////////////////////////////////////////////
# Load packages
library(dplyr) # For data wrangling
library(tidyr) # To transform data
library(ggplot2) # To create plots
library(latex2exp) # To create LaTex labels for plots
library(wesanderson) # For colors
# //////////////////////////////////////////////////////////////////////
# Read in simulation results from GitHub ///////////////////////////////
# //////////////////////////////////////////////////////////////////////
# Read in simulation results
res = read.csv(file = "https://raw.githubusercontent.com/sarahlotspeich/ExtrapolationBeforeImputation/main/Table-Data/data_Table1_rev.csv")
res = read.csv("~/Documents/ExtrapolationBeforeImputation/Table-Data/data_Table1_rev.csv")
# Calculate average % censoring per censoring setting
res |>
group_by(censoring) |>
summarize(min_perc_censored = min(perc_censored),
avg_perc_censored = mean(perc_censored),
max_perc_censored = max(perc_censored))
## Light 17% (7-29%)
## Heavy 49% (33-63%)
## Extra heavy 81% (66-94%)
# //////////////////////////////////////////////////////////////////////
# Create plot //////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////
res |>
mutate(censoring = factor(censoring, levels = c("light", "heavy", "extra_heavy"),
labels = c("Light Censoring",
"Heavy Censoring",
"Extra Heavy Censoring")),
n = factor(x = n,
levels = c(100, 500, 1000, 2000),
labels = paste("n =", c(100, 500, 1000, 2000)))
) |>
ggplot(aes(x = n, y = perc_censored, fill = censoring)) +
geom_boxplot(alpha = 0.7) +
theme_minimal(base_size = 14) +
geom_hline(yintercept = 0.17, linetype = 2) +
geom_hline(yintercept = 0.49, linetype = 2) +
geom_hline(yintercept = 0.815, linetype = 2) +
xlab("Sample Size") +
ylab("Percent Censored Observations") +
scale_fill_manual(values = wes_palette("Zissou1", n = 5, type = "discrete")[c(1,3,5)], name = "") +
theme(legend.position = "top") +
scale_y_continuous(labels = scales::percent, breaks = c(0, 0.168, 0.484, 0.814, 1))
# Save as 10" wide x 6" tall
ggsave("Rev_FigureS2.png", width = 10, height = 6, units = "in")