-
Notifications
You must be signed in to change notification settings - Fork 0
/
Figure3.R
151 lines (135 loc) · 6.57 KB
/
Figure3.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
# 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 Meila to PLRT, p = 10, K = 6####
K=6
p=10
# Figure S5a
sig=2.4
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_meila <- df[df$Method %in% c("test_indep_per", "meila_mclust",
"meila_mclust_per"), ]
df_comp_meila$Method <- factor(df_comp_meila$Method,
levels=c("test_indep_per", "meila_mclust",
"meila_mclust_per"))
lty <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_meila$n)))
p1_comp_meila <- ggplot(aes(x = delta, y = power,
ymin = power - se, ymax = power + se,
color = df_comp_meila$Method,
group = interaction(df_comp_meila$n, df_comp_meila$Method)),
linetype=lty,
data=df_comp_meila) +
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_meila$n))) + geom_linerange() +
xlab("Dependence between views") +
ylab("Power at nominal 5% significance level") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT",
"G-test (Chi squared)",
"G-test (Permutation)"),
values = c("#1f78b4", "#b2df8a", "#33a02c")) +
scale_linetype_manual(name = " n ", values=lty) +
ggtitle(expression(sigma==~2.4)) +
theme(plot.title = element_text(hjust = 0.5)) +
theme_gray(base_size = 15.5) + coord_cartesian(ylim = c(0, 1))
p1_comp_meila
# Figure S5b
sig=4.8
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_meila2 <- df[df$Method %in% c("test_indep_per", "meila_mclust",
"meila_mclust_per"), ]
df_comp_meila2$Method <- factor(df_comp_meila2$Method,
levels=c("test_indep_per", "meila_mclust",
"meila_mclust_per"))
lty2 <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_meila2$n)))
p2_comp_meila <- ggplot(aes(x = delta, y = power,
ymin = power - se, ymax = power + se,
color = df_comp_meila2$Method,
group = interaction(df_comp_meila2$n,
df_comp_meila2$Method)),
linetype=lty2,
data=df_comp_meila2) +
geom_hline(yintercept=0.05, linetype="dotted") +
geom_line(aes(linetype=as.factor(df_comp_meila2$n))) + geom_linerange() +
xlab("Dependence between views") + ylab("") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT",
"G-test (Chi squared)",
"G-test (Permutation)"),
values = c("#1f78b4", "#b2df8a", "#33a02c")) +
scale_linetype_manual(name = " n ", values=lty2) +
ggtitle(expression(sigma==~4.8)) +
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_meila
# Figure S5c
sig=9.6
load(file=paste("df-K", K, "-p", p, "-sig",
sig, ".Rdata", sep=""))
df_comp_meila3 <- df[df$Method %in% c("test_indep_per", "meila_mclust",
"meila_mclust_per"), ]
df_comp_meila3$Method <- factor(df_comp_meila3$Method,
levels=c("test_indep_per", "meila_mclust",
"meila_mclust_per"))
lty3 <- setNames(c(5, 4, 3, 2, 1), levels(factor(df_comp_meila3$n)))
p3_comp_meila <- ggplot(aes(x = delta, y = power,
ymin = power - se, ymax = power + se,
color = df_comp_meila3$Method,
group = interaction(df_comp_meila3$n,
df_comp_meila3$Method)),
linetype=lty3,
data=df_comp_meila3) +
geom_hline(yintercept=0.05, linetype="dotted") +
geom_line(aes(linetype=as.factor(df_comp_meila3$n))) + geom_linerange() +
xlab("Dependence between views") +ylab("") +
scale_colour_manual(name = "Methods",
labels=c( "Pseudo LRT",
"G-test (Chi squared)",
"G-test (Permutation)"),
values = c("#1f78b4", "#b2df8a", "#33a02c")) +
scale_linetype_manual(name = " n ", values=lty3) +
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))
p3_comp_meila
# Arrange in a row
pdf("Figure3.pdf", width=12, height=6)
grid_arrange_shared_legend(p1_comp_meila, p2_comp_meila,
p3_comp_meila, nrow=1, ncol=3)
dev.off()