]> code.communitydata.science - ml_measurement_error_public.git/blob - simulations/summarize_estimator.R
8199c0619496f81607dc22c5d7e5736f2ab106f6
[ml_measurement_error_public.git] / simulations / summarize_estimator.R
1
2 summarize.estimator <- function(df, suffix='naive', coefname='x'){
3
4     part <- df[,c('N',
5                   'm',
6                   'Bxy',
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',
11                   'Bzx',
12                   'Bzy',
13                   'accuracy_imbalance_difference'
14                   ),
15                with=FALSE]
16     
17     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)]]))
18     zero.in.ci <- as.integer(0 >= part[[paste0('B',coefname,'y.ci.lower.',suffix)]]) & (0 <= part[[paste0('B',coefname,'y.ci.upper.',suffix)]])
19     bias <- part$Bxy - part[[paste0('B',coefname,'y.est.',suffix)]]
20     sign.correct <- as.integer(sign(part$Bxy) == sign(part[[paste0('B',coefname,'y.est.',suffix)]]))
21
22     part <- part[,':='(true.in.ci = true.in.ci,
23                        zero.in.ci = zero.in.ci,
24                        bias=bias,
25                        sign.correct =sign.correct)]
26
27     part.plot <- part[, .(p.true.in.ci = mean(true.in.ci),
28                           mean.bias = mean(bias),
29                           mean.est = mean(.SD[[paste0('B',coefname,'y.est.',suffix)]]),
30                           var.est = var(.SD[[paste0('B',coefname,'y.est.',suffix)]]),
31                           est.upper.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.95,na.rm=T),
32                           est.lower.95 = quantile(.SD[[paste0('B',coefname,'y.est.',suffix)]],0.05,na.rm=T),
33                           N.sims = .N,
34                           p.sign.correct = mean(as.integer(sign.correct & (! zero.in.ci))),
35                           variable=coefname,
36                           method=suffix
37                           ),
38                       by=c("N","m",'y_explained_variance','Bzx', 'Bzy', 'accuracy_imbalance_difference')
39                       ]
40     
41     return(part.plot)
42 }

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