-
Notifications
You must be signed in to change notification settings - Fork 0
/
FigureS4.R
147 lines (134 loc) · 6.5 KB
/
FigureS4.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
# Note: Run sim-study-sec4-sec5.R, and
# sim-study-sec4-sec5-collate-results.R to
# do the simulation study and format results first
#### Load libraries & functions ####
library(ggplot2)
library(gridExtra)
library(grid)
library(scales)
# Function to arrange plots in a row
grid_arrange_shared_legend <- function(..., nrow = 1, ncol = length(list(...)), position = c("bottom", "right")) {
plots <- list(...)
position <- match.arg(position)
g <- ggplotGrob(plots[[1]] + theme(legend.position = position))$grobs
legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
lheight <- sum(legend$height)
lwidth <- sum(legend$width)
gl <- lapply(plots, function(x) x + theme(legend.position = "none"))
gl <- c(gl, nrow = nrow, ncol = ncol)
combined <- switch(position,
"bottom" = arrangeGrob(do.call(arrangeGrob, gl),
legend,
ncol = 1,
heights = unit.c(unit(1, "npc") - lheight, lheight)),
"right" = arrangeGrob(do.call(arrangeGrob, gl),
legend,
ncol = 2,
widths = unit.c(unit(1, "npc") - lwidth, lwidth)))
grid.draw(combined)
}
#### Generate plots comparing performance of PLRT w/ misspecification, p=100, K=3 ####
p=100
K=3
# Figure S2a
sig=4.8
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_per <- df[df$Method %in% c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"), ]
df_comp_per$Method <- factor(df_comp_per$Method,
levels=c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"))
lty <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_per$n)))
p1_comp_per <- ggplot(aes(x = delta, y = power, ymin = power - se, ymax = power + se,
color = df_comp_per$Method,
group = interaction(df_comp_per$n, df_comp_per$Method)),
linetype=lty, data=df_comp_per) +
geom_hline(yintercept=0.05, linetype="dotted") +
annotate(geom="text", label=as.character(expression(alpha==~"0.05")),parse=T,
x=0.08, y=0, vjust=0.3) +
geom_line(aes(linetype=as.factor(df_comp_per$n))) + geom_linerange() +
xlab("Dependence between views") +
ylab("Power at 5% significance level") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT (K=3, correct K)",
"Pseudo LRT (K=4, K too big)",
"Pseudo LRT (K=2, K too small)"),
values = c("#1b9e77", "#d95f02", "#7570b3")) +
scale_linetype_manual(name = " n ", values=lty) +
ggtitle(expression(sigma==~4.8)) +
theme(plot.title = element_text(hjust = 0.5)) +
theme_gray(base_size = 15.5) + coord_cartesian(ylim = c(0, 1))
p1_comp_per
# Figure S3b
sig=9.6
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_per2 <- df[df$Method %in% c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"), ]
df_comp_per2$Method <- factor(df_comp_per2$Method,
levels=c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"))
lty2 <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_per2$n)))
p2_comp_per <- ggplot(aes(x = delta, y = power, ymin = power - se, ymax = power + se,
color = df_comp_per2$Method,
group = interaction(df_comp_per2$n,
df_comp_per2$Method)),
linetype=lty2,
data=df_comp_per2) +
geom_hline(yintercept=0.05, linetype="dotted") +
geom_line(aes(linetype=as.factor(df_comp_per2$n))) + geom_linerange() +
xlab("Dependence between views") +
ylab("") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT (K=3, correct K)",
"Pseudo LRT (K=4, K too big)",
"Pseudo LRT (K=2, K too small)"),
values = c("#1b9e77", "#d95f02", "#7570b3")) +
scale_linetype_manual(name = " n ", values=lty2) +
ggtitle(expression(sigma==~9.6)) +
theme(plot.title = element_text(hjust = 0.5),
axis.title.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.y=element_blank()) +
theme_gray(base_size = 15.5) + coord_cartesian(ylim = c(0, 1))
p2_comp_per
# Figure S3c
sig=19.2
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_per3 <- df[df$Method %in% c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"), ]
df_comp_per3$Method <- factor(df_comp_per3$Method,
levels=c("test_indep_per", "test_indep_perK4",
"test_indep_perK2"))
lty3 <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_per3$n)))
p3_comp_per <- ggplot(aes(x = delta, y = power, ymin = power - se,
ymax = power + se,
color = df_comp_per3$Method,
group = interaction(df_comp_per3$n,
df_comp_per3$Method)),
linetype=lty3,
data=df_comp_per3) +
geom_hline(yintercept=0.05, linetype="dotted") +
geom_line(aes(linetype=as.factor(df_comp_per3$n))) + geom_linerange() +
xlab("Dependence between views") +
ylab("") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT (K=3, correct K)",
"Pseudo LRT (K=4, K too big)",
"Pseudo LRT (K=2, K too small)"),
values = c("#1b9e77", "#d95f02", "#7570b3")) +
scale_linetype_manual(name = " n ", values=lty3) +
ggtitle(expression(sigma==~19.2)) +
theme(plot.title = element_text(hjust = 0.5),
axis.title.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.y=element_blank()) +
theme_gray(base_size = 15.5) + coord_cartesian(ylim = c(0, 1))
p3_comp_per
# Arrange in a row
pdf("FigureS4.pdf", width=12, height=6)
grid_arrange_shared_legend(p1_comp_per, p2_comp_per,
p3_comp_per, nrow=1, ncol=3)
dev.off()