3 summarize.estimator <- function(sims.df, suffix='naive', coefname='x'){
7 paste0('B',coefname,'y.est.',suffix),
8 paste0('B',coefname,'y.ci.lower.',suffix),
9 paste0('B',coefname,'y.ci.upper.',suffix)
13 grouping_vars <- c('N','m','B0', 'Bxy', 'Bzy', 'Bzx', 'Px', 'Py','y_explained_variance', 'prediction_accuracy','outcome_formula','proxy_formula','truth_formula','z_bias','y_bias')
15 grouping_vars <- grouping_vars[grouping_vars %in% names(df)]
18 unique(c(reported_vars,
23 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)]]))
24 zero.in.ci <- as.integer(0 >= part[[paste0('B',coefname,'y.ci.lower.',suffix)]]) & (0 <= part[[paste0('B',coefname,'y.ci.upper.',suffix)]])
25 bias <- part[[paste0('B',coefname,'y')]] - part[[paste0('B',coefname,'y.est.',suffix)]]
26 sign.correct <- as.integer(sign(part$Bxy) == sign(part[[paste0('B',coefname,'y.est.',suffix)]]))
28 part <- part[,':='(true.in.ci = true.in.ci,
29 zero.in.ci = zero.in.ci,
31 sign.correct =sign.correct)]
34 part.plot <- part[, .(p.true.in.ci = mean(true.in.ci),
35 mean.bias = mean(bias),
36 mean.est = mean(.SD[[paste0('B',coefname,'y.est.',suffix)]],na.rm=T),
37 var.est = var(.SD[[paste0('B',coefname,'y.est.',suffix)]],na.rm=T),
38 est.upper.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.975,na.rm=T),
39 est.lower.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.025,na.rm=T),
40 mean.ci.upper = mean(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],na.rm=T),
41 mean.ci.lower = mean(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],na.rm=T),
42 median.ci.upper = median(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],na.rm=T),
43 median.ci.lower = median(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],na.rm=T),
44 ci.upper.975 = quantile(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],0.975,na.rm=T),
45 ci.upper.025 = quantile(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],0.025,na.rm=T),
46 ci.lower.975 = quantile(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],0.975,na.rm=T),
47 ci.lower.025 = quantile(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],0.025,na.rm=T),
48 N.ci.is.NA = sum(is.na(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]])),
50 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),