]> code.communitydata.science - ml_measurement_error_public.git/blobdiff - simulations/summarize_estimator.R
changes from klone
[ml_measurement_error_public.git] / simulations / summarize_estimator.R
index 1e1341d2514096e795fcf6e937de9ab521c39abb..8ddeb7c203328aa2a5bf97501355fc1ef65350fc 100644 (file)
@@ -1,5 +1,6 @@
+library(ggdist)
 
-summarize.estimator <- function(df, suffix='naive', coefname='x'){
+summarize.estimator <- function(sims.df, suffix='naive', coefname='x'){
 
     reported_vars <- c(
                        'Bxy',
@@ -13,10 +14,10 @@ summarize.estimator <- function(df, suffix='naive', coefname='x'){
 
     grouping_vars <- grouping_vars[grouping_vars %in% names(df)]
 
-    part <- df[,
-               c(reported_vars,
-                 grouping_vars),
-               with=FALSE]
+    part <- sims.df[,
+                    unique(c(reported_vars,
+                             grouping_vars)),
+                    with=FALSE]
 
 
     true.in.ci <- as.integer((part$Bxy >= part[[paste0('B',coefname,'y.ci.lower.',suffix)]]) & (part$Bxy <= part[[paste0('B',coefname,'y.ci.upper.',suffix)]]))
@@ -29,6 +30,7 @@ summarize.estimator <- function(df, suffix='naive', coefname='x'){
                        bias=bias,
                        sign.correct =sign.correct)]
 
+
     part.plot <- part[, .(p.true.in.ci = mean(true.in.ci),
                           mean.bias = mean(bias),
                           mean.est = mean(.SD[[paste0('B',coefname,'y.est.',suffix)]],na.rm=T),

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