2 summarize.estimator <- function(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),
10 'y_explained_variance',
13 'accuracy_imbalance_difference'
18 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)]]))
19 zero.in.ci <- as.integer(0 >= part[[paste0('B',coefname,'y.ci.lower.',suffix)]]) & (0 <= part[[paste0('B',coefname,'y.ci.upper.',suffix)]])
20 bias <- part[[paste0('B',coefname,'y')]] - part[[paste0('B',coefname,'y.est.',suffix)]]
21 sign.correct <- as.integer(sign(part$Bxy) == sign(part[[paste0('B',coefname,'y.est.',suffix)]]))
23 part <- part[,':='(true.in.ci = true.in.ci,
24 zero.in.ci = zero.in.ci,
26 sign.correct =sign.correct)]
28 part.plot <- part[, .(p.true.in.ci = mean(true.in.ci),
29 mean.bias = mean(bias),
30 mean.est = mean(.SD[[paste0('B',coefname,'y.est.',suffix)]]),
31 var.est = var(.SD[[paste0('B',coefname,'y.est.',suffix)]]),
32 est.upper.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.975,na.rm=T),
33 est.lower.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.025,na.rm=T),
34 mean.ci.upper = mean(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]]),
35 mean.ci.lower = mean(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]]),
36 ci.upper.975 = quantile(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],0.975,na.rm=T),
37 ci.upper.025 = quantile(.SD[[paste0('B',coefname,'y.ci.upper.',suffix)]],0.025,na.rm=T),
38 ci.lower.975 = quantile(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],0.975,na.rm=T),
39 ci.lower.025 = quantile(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]],0.025,na.rm=T),
40 N.ci.is.NA = sum(is.na(.SD[[paste0('B',coefname,'y.ci.lower.',suffix)]])),
42 p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
46 by=c("N","m",'y_explained_variance','Bzx', 'Bzy', 'accuracy_imbalance_difference')