1 source("RemembR/R/RemembeR.R")
6 df <- data.table(read_feather("example_1.feather"))
8 x.naive <- df[,.(N, m, Bxy, Bxy.est.naive, Bxy.ci.lower.naive, Bxy.ci.upper.naive)]
9 x.naive <- x.naive[,':='(true.in.ci = as.integer((Bxy >= Bxy.ci.lower.naive) & (Bxy <= Bxy.ci.upper.naive)),
10 zero.in.ci = (0 >= Bxy.ci.lower.naive) & (0 <= Bxy.ci.upper.naive),
11 bias = Bxy - Bxy.est.naive,
12 sign.correct = as.integer(sign(Bxy) == sign(Bxy.est.naive)))]
14 x.naive.plot <- x.naive[,.(p.true.in.ci = mean(true.in.ci),
15 mean.bias = mean(bias),
16 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
17 mean.estimate=mean(Bxy.est.naive),
18 var.estimate=var(Bxy.est.naive),
25 x.amelia.full <- df[,.(N, m, Bxy, Bxy.est.true, Bxy.ci.lower.amelia.full, Bxy.ci.upper.amelia.full, Bxy.est.amelia.full)]
27 x.amelia.full <- x.amelia.full[,':='(true.in.ci = (Bxy.est.true >= Bxy.ci.lower.amelia.full) & (Bxy.est.true <= Bxy.ci.upper.amelia.full),
28 zero.in.ci = (0 >= Bxy.ci.lower.amelia.full) & (0 <= Bxy.ci.upper.amelia.full),
29 bias = Bxy.est.true - Bxy.est.amelia.full,
30 sign.correct = sign(Bxy.est.true) == sign(Bxy.est.amelia.full))]
32 x.amelia.full.plot <- x.amelia.full[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
33 mean.bias = mean(bias),
34 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
36 method='Multiple imputation'
42 g.amelia.full <- df[,.(N, m, Bgy.est.true, Bgy.est.amelia.full, Bgy.ci.lower.amelia.full, Bgy.ci.upper.amelia.full)]
43 g.amelia.full <- g.amelia.full[,':='(true.in.ci = (Bgy.est.true >= Bgy.ci.lower.amelia.full) & (Bgy.est.true <= Bgy.ci.upper.amelia.full),
44 zero.in.ci = (0 >= Bgy.ci.lower.amelia.full) & (0 <= Bgy.ci.upper.amelia.full),
45 bias = Bgy.est.amelia.full - Bgy.est.true,
46 sign.correct = sign(Bgy.est.true) == sign(Bgy.est.amelia.full))]
48 g.amelia.full.plot <- g.amelia.full[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
49 mean.bias = mean(bias),
50 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
52 method='Multiple imputation'
56 x.amelia.nok <- df[,.(N, m, Bxy.est.true, Bxy.est.amelia.nok, Bxy.ci.lower.amelia.nok, Bxy.ci.upper.amelia.nok)]
57 x.amelia.nok <- x.amelia.nok[,':='(true.in.ci = (Bxy.est.true >= Bxy.ci.lower.amelia.nok) & (Bxy.est.true <= Bxy.ci.upper.amelia.nok),
58 zero.in.ci = (0 >= Bxy.ci.lower.amelia.nok) & (0 <= Bxy.ci.upper.amelia.nok),
59 bias = Bxy.est.amelia.nok - Bxy.est.true,
60 sign.correct = sign(Bxy.est.true) == sign(Bxy.est.amelia.nok))]
62 x.amelia.nok.plot <- x.amelia.nok[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
63 mean.bias = mean(bias),
64 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
66 method='Multiple imputation (Classifier features unobserved)'
70 g.amelia.nok <- df[,.(N, m, Bgy.est.true, Bgy.est.amelia.nok, Bgy.ci.lower.amelia.nok, Bgy.ci.upper.amelia.nok)]
71 g.amelia.nok <- g.amelia.nok[,':='(true.in.ci = (Bgy.est.true >= Bgy.ci.lower.amelia.nok) & (Bgy.est.true <= Bgy.ci.upper.amelia.nok),
72 zero.in.ci = (0 >= Bgy.ci.lower.amelia.nok) & (0 <= Bgy.ci.upper.amelia.nok),
73 bias = Bgy.est.amelia.nok - Bgy.est.true,
74 sign.correct = sign(Bgy.est.true) == sign(Bgy.est.amelia.nok))]
76 g.amelia.nok.plot <- g.amelia.nok[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
77 mean.bias = mean(bias),
78 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
80 method='Multiple imputation (Classifier features unobserved)'
85 x.mecor <- df[,.(N,m,Bxy.est.true, Bxy.est.mecor,Bxy.lower.mecor, Bxy.upper.mecor)]
87 x.mecor <- x.mecor[,':='(true.in.ci = (Bxy.est.true >= Bxy.lower.mecor) & (Bxy.est.true <= Bxy.upper.mecor),
88 zero.in.ci = (0 >= Bxy.lower.mecor) & (0 <= Bxy.upper.mecor),
89 bias = Bxy.est.mecor - Bxy.est.true,
90 sign.correct = sign(Bxy.est.true) == sign(Bxy.est.mecor))]
92 x.mecor.plot <- x.mecor[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
93 mean.bias = mean(bias),
94 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
96 method='Regression Calibration'
100 g.mecor <- df[,.(N,m,Bgy.est.true, Bgy.est.mecor,Bgy.lower.mecor, Bgy.upper.mecor)]
102 g.mecor <- g.mecor[,':='(true.in.ci = (Bgy.est.true >= Bgy.lower.mecor) & (Bgy.est.true <= Bgy.upper.mecor),
103 zero.in.ci = (0 >= Bgy.lower.mecor) & (0 <= Bgy.upper.mecor),
104 bias = Bgy.est.mecor - Bgy.est.true,
105 sign.correct = sign(Bgy.est.true) == sign(Bgy.est.mecor))]
107 g.mecor.plot <- g.mecor[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
108 mean.bias = mean(bias),
109 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
111 method='Regression Calibration'
115 ## x.mecor <- df[,.(N,m,Bgy.est.true, Bgy.est.mecor,Bgy.ci.lower.mecor, Bgy.ci.upper.mecor)]
117 ## x.mecor <- x.mecor[,':='(true.in.ci = (Bgy.est.true >= Bgy.ci.lower.mecor) & (Bgy.est.true <= Bgy.ci.upper.mecor),
118 ## zero.in.ci = (0 >= Bgy.ci.lower.mecor) & (0 <= Bgy.ci.upper.mecor),
119 ## bias = Bgy.est.mecor - Bgy.est.true,
120 ## sign.correct = sign(Bgy.est.true) == sign(Bgy.est.mecor))]
122 ## x.mecor.plot <- x.mecor[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
123 ## mean.bias = mean(bias),
124 ## p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
126 ## method='Regression Calibration'
131 x.gmm <- df[,.(N,m,Bxy.est.true, Bxy.est.gmm,Bxy.ci.lower.gmm, Bxy.ci.upper.gmm)]
132 x.gmm <- x.gmm[,':='(true.in.ci = (Bxy.est.true >= Bxy.ci.lower.gmm) & (Bxy.est.true <= Bxy.ci.upper.gmm),
133 zero.in.ci = (0 >= Bxy.ci.lower.gmm) & (0 <= Bxy.ci.upper.gmm),
134 bias = Bxy.est.gmm - Bxy.est.true,
135 sign.correct = sign(Bxy.est.true) == sign(Bxy.est.gmm))]
137 x.gmm.plot <- x.gmm[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
138 mean.bias = mean(bias),
139 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
145 g.gmm <- df[,.(N,m,Bgy.est.true, Bgy.est.gmm,Bgy.ci.lower.gmm, Bgy.ci.upper.gmm)]
146 g.gmm <- g.gmm[,':='(true.in.ci = (Bgy.est.true >= Bgy.ci.lower.gmm) & (Bgy.est.true <= Bgy.ci.upper.gmm),
147 zero.in.ci = (0 >= Bgy.ci.lower.gmm) & (0 <= Bgy.ci.upper.gmm),
148 bias = Bgy.est.gmm - Bgy.est.true,
149 sign.correct = sign(Bgy.est.true) == sign(Bgy.est.gmm))]
151 g.gmm.plot <- g.gmm[,.(p.true.in.ci = mean(as.integer(true.in.ci)),
152 mean.bias = mean(bias),
153 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
159 plot.df <- rbindlist(list(x.naive.plot,g.naive.plot,x.amelia.full.plot,g.amelia.full.plot,x.amelia.nok.plot,g.amelia.nok.plot, x.mecor.plot, g.mecor.plot, x.gmm.plot, g.gmm.plot))
161 remember(plot.df,'example.1.plot.df')
164 ggplot(plot.df,aes(y=N,x=m,color=p.sign.correct)) + geom_point() + facet_grid(variable ~ method) + scale_color_viridis_c(option='D') + theme_minimal() + xlab("Number of gold standard labels") + ylab("Total sample size")
166 ggplot(plot.df,aes(y=N,x=m,color=abs(mean.bias))) + geom_point() + facet_grid(variable ~ method) + scale_color_viridis_c(option='D') + theme_minimal() + xlab("Number of gold standard labels") + ylab("Total sample size")
168 ests <- df[,.(Bxy.est.true = mean(Bxy.est.true),
169 Bxy.est.naive = mean(Bxy.est.naive),
170 Bxy.est.feasible = mean(Bxy.est.feasible),
171 Bxy.est.amelia.full = mean(Bxy.est.amelia.full),
172 Bxy.est.amelia.nok = mean(Bxy.est.amelia.nok),
173 Bxy.est.mecor = mean(Bxy.est.mecor),
174 Bxy.est.gmm = mean(Bxy.est.gmm)),