]> code.communitydata.science - ml_measurement_error_public.git/blob - simulations/plot_irr_dv_example.R
Merge branch 'master' of code:ml_measurement_error_public
[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.loa0.feasible <- summarize.estimator(df, 'loa0.feasible','x')
21     
22     z.loa0.feasible <- summarize.estimator(df,'loa0.feasible','z')
23
24     x.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'x')
25
26     z.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'z')
27
28     x.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'x')
29
30     z.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'z')
31
32     x.loco.mle <- summarize.estimator(df, 'loco.mle', 'x')
33
34     z.loco.mle <- summarize.estimator(df, 'loco.mle', 'z')
35
36
37     accuracy <- df[,mean(accuracy)]
38     plot.df <- rbindlist(list(x.true,z.true,x.loa0.feasible,z.loa0.feasible,x.loa0.mle,z.loa0.mle,x.loco.feasible, z.loco.feasible, z.loco.mle, x.loco.mle),use.names=T)
39     plot.df[,accuracy := accuracy]
40     plot.df <- plot.df[,":="(sd.est=sqrt(var.est)/N.sims)]
41     return(plot.df)
42 }
43
44
45 plot.df <- read_feather(args$infile)
46 print(unique(plot.df$N))
47
48 # df <- df[apply(df,1,function(x) !any(is.na(x)))]
49
50 if(!('Bzx' %in% names(plot.df)))
51     plot.df[,Bzx:=NA]
52
53 if(!('accuracy_imbalance_difference' %in% names(plot.df)))
54     plot.df[,accuracy_imbalance_difference:=NA]
55
56 unique(plot.df[,'accuracy_imbalance_difference'])
57
58 #plot.df <- build_plot_dataset(df[accuracy_imbalance_difference==0.1][N==700])
59 plot.df <- build_plot_dataset(plot.df)
60
61 change.remember.file("remember_irr.RDS",clear=TRUE)
62
63 remember(plot.df,args$name)

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