Update on Overleaf.
This commit is contained in:
268
resources/robustness_check_plots.R
Normal file
268
resources/robustness_check_plots.R
Normal file
@@ -0,0 +1,268 @@
|
||||
library(data.table)
|
||||
library(ggplot2)
|
||||
source('resources/functions.R')
|
||||
|
||||
plot.robustness.1 <- function(iv='x'){
|
||||
|
||||
## robustness check 1 test g
|
||||
r <- readRDS('robustness_1.RDS')
|
||||
baseline_df <- readRDS('remembr.RDS')[['plot.df.example.2']]
|
||||
robust_df <- data.table(r$robustness_1)
|
||||
|
||||
## just compare the mle methods in the two examples
|
||||
robust_df <- robust_df[Bzy!=0]
|
||||
robust_df <- robust_df[Bzx!=0]
|
||||
baseline_df[method=='true', method:='True']
|
||||
robust_df[method=='true', method:='True']
|
||||
|
||||
baseline_df <- baseline_df[(method=='mle') | (method=='True') | (method=='naive')]
|
||||
robust_df <- robust_df[(method=='mle') | (method=='True')]
|
||||
|
||||
baseline_df[method=='mle',method:='MLE Reported']
|
||||
robust_df[method=='mle',method:='No Z in Error Model']
|
||||
|
||||
df <- rbind(baseline_df, robust_df, fill=TRUE)
|
||||
df[method=='naive', method:='Naive']
|
||||
df <- df[(N %in% c(1000,5000)) & (m %in% c(200,100))]
|
||||
p <- plot.simulation(df,iv=iv,levels=c('MLE Reported','No Z in Error Model', 'Naive', 'True'))
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.1.checkassumption <- function(iv='x'){
|
||||
|
||||
## robustness check 1 test g
|
||||
r <- readRDS('robustness_1.RDS')
|
||||
baseline_df <- readRDS('remembr.RDS')[['plot.df.example.2']]
|
||||
robust_df <- data.table(r$robustness_1)
|
||||
|
||||
## just compare the mle methods in the two examples
|
||||
robust_df <- robust_df[Bzy==0]
|
||||
robust_df <- robust_df[Bzx!=0]
|
||||
baseline_df[method=='true', method:='True']
|
||||
robust_df[method=='true', method:='True']
|
||||
|
||||
baseline_df <- baseline_df[(method=='mle') | (method=='naive')]
|
||||
robust_df <- robust_df[(method=='mle') | (method=='True')]
|
||||
|
||||
baseline_df[method=='mle',method:='MLE Reported']
|
||||
robust_df[method=='mle',method:='No Z in Error Model']
|
||||
|
||||
df <- rbind(baseline_df, robust_df, fill=TRUE)
|
||||
df[method=='naive', method:='Naive']
|
||||
df <- df[(N %in% c(1000,5000)) & (m %in% c(200,100))]
|
||||
p <- plot.simulation(df,iv=iv,levels=c('MLE Reported','No Z in Error Model', 'Naive', 'True'))
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.1.dv <- function(iv='z'){
|
||||
|
||||
## robustness check 1 test g
|
||||
r <- readRDS('robustness_1_dv.RDS')
|
||||
baseline_df <- readRDS('remembr.RDS')[['plot.df.example.4']]
|
||||
robust_df <- data.table(r$robustness_1_dv)
|
||||
|
||||
## just compare the mle methods in the two examples
|
||||
|
||||
baseline_df[method=='true', method:='True']
|
||||
robust_df[method=='true', method:='True']
|
||||
|
||||
robust_df <- robust_df[Bxy!=0]
|
||||
robust_df <- robust_df[Bzy!=0]
|
||||
# robust_df <- robust_df[Bzx==-0.1]
|
||||
|
||||
baseline_df <- baseline_df[(method=='mle') | (method=='True') | (method=='naive')]
|
||||
robust_df <- robust_df[(method=='mle') | (method=='True')]
|
||||
|
||||
baseline_df[method=='mle',method:='MLE Reported']
|
||||
robust_df[method=='mle',method:='No Z in Error Model']
|
||||
|
||||
df <- rbind(baseline_df, robust_df, fill=TRUE)
|
||||
df <- df[(N %in% c(1000,5000)) & (m %in% c(200,100))]
|
||||
df[method=='naive', method:='Naive']
|
||||
|
||||
p <- plot.simulation(df,iv=iv,levels=c('MLE Reported','No Z in Error Model','Naive', 'True'))
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.2.iv <- function(iv, n.annotations=100, n.classifications=5000){
|
||||
|
||||
r <- readRDS("robustness_2.RDS")
|
||||
robust_df <- data.table(r[['robustness_2']])
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","gmm"="GMM", "mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(prediction_accuracy~., ncol=4,as.table=F)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("AC Accuracy",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
robust2 <- readRDS("robustness_2_dv.RDS")
|
||||
robust_2_df <- data.table(robust2[['robustness_2_dv']])
|
||||
robust_2_min_acc <- min(robust_2_df[,prediction_accuracy])
|
||||
robust_2_max_acc <- max(robust_2_df[,prediction_accuracy])
|
||||
|
||||
plot.robustness.2.dv <- function(iv, n.annotations=100, n.classifications=5000){
|
||||
|
||||
r <- readRDS("robustness_2_dv.RDS")
|
||||
robust_df <- data.table(r[['robustness_2_dv']])
|
||||
|
||||
|
||||
#temporary work around a bug in the makefile
|
||||
## if('Px' %in% names(robust_df))
|
||||
## robust_df <- robust_df[is.na(Px)]
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","gmm"="GMM", "mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(prediction_accuracy~., ncol=4,as.table=F)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("AC Accuracy",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
|
||||
plot.robustness.3.iv <- function(iv, n.annotations=100, n.classifications=5000){
|
||||
r <- readRDS('robustness_3.RDS')
|
||||
robust_df <- data.table(r[['robustness_3']])
|
||||
r2 <- readRDS('robustness_3_proflik.RDS')
|
||||
robust_df_proflik <- data.table(r2[['robustness_3_proflik']])
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","gmm"="GMM", "mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
robust_df <- robust_df[method=='MLE',method:='Fischer likelihood']
|
||||
|
||||
robust_df_proflik <- robust_df_proflik[(m==n.annotations) & (N==n.classifications)]
|
||||
robust_df_proflik <- robust_df_proflik[method=='MLE',method:='Profile likelihood']
|
||||
|
||||
|
||||
|
||||
robust_df_proflik <- robust_df_proflik[,method := new.levels[method]]
|
||||
robust_df_proflik <- robust_df_proflik[method != "Feasible"]
|
||||
|
||||
df <- rbind(robust_df, robust_df_proflik)
|
||||
|
||||
p <- .plot.simulation(df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(Px~., ncol=3,as.table=F)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("P(X)",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.3.dv <- function(iv, n.annotations=100, n.classifications=1000){
|
||||
r <- readRDS('robustness_3_dv.RDS')
|
||||
robust_df <- data.table(r[['robustness_3_dv']])
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(B0~., ncol=3,as.table=F)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("P(Y)",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.4.iv <- function(iv, n.annotations=100, n.classifications=1000){
|
||||
r <- readRDS('robustness_4.RDS')
|
||||
robust_df <- data.table(r[['robustness_4']])
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","gmm"="GMM", "mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
|
||||
robust_df <- robust_df[,y_bias=factor(robust_df$y_bias,levels=sort(unique(robust_df$y_bias),decreasing=TRUE))]
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(y_bias~., ncol=3,as.table=T)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("Coefficient of Y for W",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
|
||||
|
||||
plot.robustness.4.iv <- function(iv, n.annotations=100, n.classifications=1000){
|
||||
r <- readRDS('robustness_4.RDS')
|
||||
robust_df <- data.table(r[['robustness_4']])
|
||||
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","gmm"="GMM", "mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
|
||||
robust_df <- robust_df[,y_bias=factor(robust_df$y_bias,levels=sort(unique(robust_df$y_bias),decreasing=TRUE))]
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
|
||||
p <- p + facet_wrap(y_bias~., ncol=3,as.table=T)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("Coefficient of Y for W",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
|
||||
plot.robustness.4.dv <- function(iv, n.annotations=100, n.classifications=1000){
|
||||
r <- readRDS('robustness_4_dv.RDS')
|
||||
robust_df <- data.table(r[['robustness_4']])
|
||||
|
||||
new.levels <- c("true"="True","naive"="Naïve","amelia.full"="MI", "mecor"="mecor","mle"="MLE", "zhang"="PL","feasible"="Feasible")
|
||||
|
||||
robust_df <- robust_df[(m==n.annotations) & (N==n.classifications)]
|
||||
|
||||
robust_df <- robust_df[,method := new.levels[method]]
|
||||
robust_df <- robust_df[method != "Feasible"]
|
||||
|
||||
robust_df <- robust_df[,z_bias=factor(z_bias, levels=sort(unique(z_bias),descending=TRUE))]
|
||||
|
||||
p <- .plot.simulation(robust_df, iv=iv, levels=c("True","Naïve","MI", "GMM", "MLE", "PL", "Feasible"))
|
||||
p <- p + facet_wrap(z_bias~., ncol=3,as.table=F)
|
||||
p <- p + scale_x_discrete(labels=label_wrap_gen(14)) + ylab("Estimate") + xlab("Method") + coord_flip()
|
||||
|
||||
p <- arrangeGrob(p,
|
||||
top=grid.text("Coefficient of Z on W",x=0.32,just='right'))
|
||||
|
||||
grid.draw(p)
|
||||
}
|
||||
Reference in New Issue
Block a user