-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.R
100 lines (84 loc) · 3.3 KB
/
plots.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
library(ggplot2)
library(ggExtra)
library(gridExtra)
library(readxl)
Raw <- read_xlsx("Results.xlsx", sheet = "plots")
Full <- Raw[Raw$Missprop == 0,]
FullRM <- Full
FullMI <- Full
FullRM$Method <- "RM"
FullMI$Method <- "MI"
Full2 <- rbind(FullRM, FullMI)
All <- Raw[Raw$Missprop != 0,]
All <- rbind(Full2, All)
All$Legend <- paste(All$Method, All$Model, sep = " - ")
All$Missprop <- factor(All$Missprop)
# All$Method <- factor(All$Method, levels = c("Complete", "RM", "MI"))
# All$Design <- factor(All$Design, levels = c("ABAB", "RBD"))
# Mode filters
mode = "mcar"
if(mode == "uni")
{
AllF <- All[All$Model %in% c("normal", "uniform", "AR1"),]
AllF$Legend <- factor(AllF$Legend, levels = c(
"RM - normal", "MI - normal",
"RM - uniform", "MI - uniform",
"RM - AR1", "MI - AR1"
))
} else
if(mode == "mcar")
{
AllF <- All[All$Model %in% c("mvn.3", "mvn.6"),]
AllF <- AllF[AllF$Misstype %in% c("mcar", "none"),]
AllF$Legend <- factor(AllF$Legend, levels = c("RM - mvn.3", "MI - mvn.3", "RM - mvn.6", "MI - mvn.6"))
} else
if(mode == "mar")
{
AllF <- All[All$Model %in% c("mvn.3", "mvn.6"),]
AllF <- AllF[AllF$Misstype %in% c("mar+", "mar-", "none"),]
AllF$Legend <- factor(AllF$Legend, levels = c("RM - mvn.3", "MI - mvn.3", "RM - mvn.6", "MI - mvn.6"))
} else
if(mode == "mnar")
{
AllF <- All[All$Model %in% c("mvn.3", "mvn.6"),]
AllF <- AllF[AllF$Misstype %in% c("mnar+", "mnar-", "none"),]
AllF$Legend <- factor(AllF$Legend, levels = c("RM - mvn.3", "MI - mvn.3", "RM - mvn.6", "MI - mvn.6"))
}
All0 <- AllF[AllF$ES == 0,]
All1 <- AllF[AllF$ES == 1,]
All2 <- AllF[AllF$ES == 2,]
Agg0 <- aggregate(All0$Power, by=list(Missprop=All0$Missprop, Legend=All0$Legend), FUN=mean)
Agg1 <- aggregate(All1$Power, by=list(Missprop=All1$Missprop, Legend=All1$Legend), FUN=mean)
Agg2 <- aggregate(All2$Power, by=list(Missprop=All2$Missprop, Legend=All2$Legend), FUN=mean)
theme_set(theme_gray(base_size = 20))
plot1 <- ggplot(data=Agg0, aes(x=Missprop, y=x, group=Legend, colour = Legend)) +
geom_point(aes(shape = Legend), size = 3) +
scale_shape_manual(values=c(15:18,21,22)) +
geom_line(aes(linetype = Legend), size = 1.1) +
xlab("Missing data percentage") +
ylab("Type I error rate (%)") +
ylim(0, 100) +
ggtitle("Effect size = 0") +
theme(plot.title = element_text(hjust=0.5), legend.position="bottom", legend.direction = "vertical") +
removeGrid()
plot2 <- ggplot(data=Agg1, aes(x=Missprop, y=x, group=Legend, colour = Legend)) +
geom_point(aes(shape = Legend), size = 3) +
scale_shape_manual(values=c(15:18,21,22)) +
geom_line(aes(linetype = Legend), size = 1.1) +
xlab("Missing data percentage") +
ylab("Estimated power (%)") +
ylim(0, 100) +
ggtitle("Effect size = 1") +
theme(plot.title = element_text(hjust=0.5), legend.position="bottom", legend.direction = "vertical") +
removeGrid()
plot3 <- ggplot(data=Agg2, aes(x=Missprop, y=x, group=Legend, colour = Legend)) +
geom_point(aes(shape = Legend), size = 3) +
scale_shape_manual(values=c(15:18,21,22)) +
geom_line(aes(linetype = Legend), size = 1.1) +
xlab("Missing data percentage") +
ylab("Estimated power (%)") +
ylim(0, 100) +
ggtitle("Effect size = 2") +
theme(plot.title = element_text(hjust=0.5), legend.position="bottom", legend.direction = "vertical") +
removeGrid()
grid.arrange(plot1, plot2, plot3, ncol=3)