]> code.communitydata.science - ml_measurement_error_public.git/blob - simulations/plot_irr_dv_example.R
update simulations code
[ml_measurement_error_public.git] / simulations / plot_irr_dv_example.R
1 source("RemembR/R/RemembeR.R")
2 library(arrow)
3 library(data.table)
4 library(ggplot2)
5 library(filelock)
6 library(argparser)
7
8 parser <- arg_parser("Simulate data and fit corrected models.")
9 parser <- add_argument(parser, "--infile", default="", help="name of the file to read.")
10 parser <- add_argument(parser, "--name", default="", help="The name to safe the data to in the remember file.")
11 args <- parse_args(parser)
12 source("summarize_estimator.R")
13
14 build_plot_dataset <- function(df){
15     
16     x.true <-  summarize.estimator(df, 'true','x')
17
18     z.true <-  summarize.estimator(df, 'true','z')
19
20     x.naive <-  summarize.estimator(df, 'naive','x')
21
22     z.naive <-  summarize.estimator(df, 'naive','z')
23
24     x.loa0.feasible <- summarize.estimator(df, 'loa0.feasible','x')
25     
26     z.loa0.feasible <- summarize.estimator(df,'loa0.feasible','z')
27
28     x.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'x')
29
30     z.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'z')
31
32     x.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'x')
33
34     z.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'z')
35
36     x.loco.mle <- summarize.estimator(df, 'loco.mle', 'x')
37
38     z.loco.mle <- summarize.estimator(df, 'loco.mle', 'z')
39
40
41     z.loco.amelia <- summarize.estimator(df, 'amelia.full', 'z')
42     x.loco.amelia <- summarize.estimator(df, 'amelia.full', 'x')
43
44     z.loco.zhang <- summarize.estimator(df, 'zhang', 'z')
45     x.loco.zhang <- summarize.estimator(df, 'zhang', 'x')
46
47     accuracy <- df[,mean(accuracy)]
48     plot.df <- rbindlist(list(x.true,z.true,x.loa0.feasible,z.loa0.feasible,x.naive,z.naive,x.loa0.mle,z.loa0.mle,x.loco.feasible, z.loco.feasible, z.loco.mle, x.loco.mle, x.loco.amelia, z.loco.amelia, z.loco.zhang, x.loco.zhang),use.names=T)
49     plot.df[,accuracy := accuracy]
50     plot.df <- plot.df[,":="(sd.est=sqrt(var.est)/N.sims)]
51     return(plot.df)
52 }
53
54
55 plot.df <- read_feather(args$infile)
56 print(unique(plot.df$N))
57
58 # df <- df[apply(df,1,function(x) !any(is.na(x)))]
59
60 if(!('Bzx' %in% names(plot.df)))
61     plot.df[,Bzx:=NA]
62
63 if(!('accuracy_imbalance_difference' %in% names(plot.df)))
64     plot.df[,accuracy_imbalance_difference:=NA]
65
66 unique(plot.df[,'accuracy_imbalance_difference'])
67
68 #plot.df <- build_plot_dataset(df[accuracy_imbalance_difference==0.1][N==700])
69 plot.df <- build_plot_dataset(plot.df)
70
71 change.remember.file("remember_irr.RDS",clear=TRUE)
72
73 remember(plot.df,args$name)

Community Data Science Collective || Want to submit a patch?