]> code.communitydata.science - ml_measurement_error_public.git/blobdiff - simulations/plot_irr_dv_example.R
update simulation and mle code
[ml_measurement_error_public.git] / simulations / plot_irr_dv_example.R
diff --git a/simulations/plot_irr_dv_example.R b/simulations/plot_irr_dv_example.R
new file mode 100644 (file)
index 0000000..f5e2c41
--- /dev/null
@@ -0,0 +1,63 @@
+source("RemembR/R/RemembeR.R")
+library(arrow)
+library(data.table)
+library(ggplot2)
+library(filelock)
+library(argparser)
+
+parser <- arg_parser("Simulate data and fit corrected models.")
+parser <- add_argument(parser, "--infile", default="", help="name of the file to read.")
+parser <- add_argument(parser, "--name", default="", help="The name to safe the data to in the remember file.")
+args <- parse_args(parser)
+source("summarize_estimator.R")
+
+build_plot_dataset <- function(df){
+    
+    x.true <-  summarize.estimator(df, 'true','x')
+
+    z.true <-  summarize.estimator(df, 'true','z')
+
+    x.loa0.feasible <- summarize.estimator(df, 'loa0.feasible','x')
+    
+    z.loa0.feasible <- summarize.estimator(df,'loa0.feasible','z')
+
+    x.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'x')
+
+    z.loa0.mle <- summarize.estimator(df, 'loa0.mle', 'z')
+
+    x.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'x')
+
+    z.loco.feasible <- summarize.estimator(df, 'loco.feasible', 'z')
+
+    x.loco.mle <- summarize.estimator(df, 'loco.mle', 'x')
+
+    z.loco.mle <- summarize.estimator(df, 'loco.mle', 'z')
+
+
+    accuracy <- df[,mean(accuracy)]
+    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)
+    plot.df[,accuracy := accuracy]
+    plot.df <- plot.df[,":="(sd.est=sqrt(var.est)/N.sims)]
+    return(plot.df)
+}
+
+
+plot.df <- read_feather(args$infile)
+print(unique(plot.df$N))
+
+# df <- df[apply(df,1,function(x) !any(is.na(x)))]
+
+if(!('Bzx' %in% names(plot.df)))
+    plot.df[,Bzx:=NA]
+
+if(!('accuracy_imbalance_difference' %in% names(plot.df)))
+    plot.df[,accuracy_imbalance_difference:=NA]
+
+unique(plot.df[,'accuracy_imbalance_difference'])
+
+#plot.df <- build_plot_dataset(df[accuracy_imbalance_difference==0.1][N==700])
+plot.df <- build_plot_dataset(plot.df)
+
+change.remember.file("remember_irr.RDS",clear=TRUE)
+
+remember(plot.df,args$name)

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