X-Git-Url: https://code.communitydata.science/ml_measurement_error_public.git/blobdiff_plain/979dc14b6861ae31f00d56392fd5b8cf69f17333..b52b4f7daaba8a877b041ddb24c8f36b466ddc5b:/simulations/02_indep_differential.R diff --git a/simulations/02_indep_differential.R b/simulations/02_indep_differential.R index c6907d3..bcfad65 100644 --- a/simulations/02_indep_differential.R +++ b/simulations/02_indep_differential.R @@ -104,8 +104,9 @@ simulate_data <- function(N, m, B0, Bxy, Bzx, Bzy, seed, y_explained_variance=0. ## print(mean(df[z==1]$x == df[z==1]$w_pred)) ## print(mean(df$w_pred == df$x)) - odds.x1 <- qlogis(prediction_accuracy) + y_bias*qlogis(pnorm(scale(df[x==1]$y))) - odds.x0 <- qlogis(prediction_accuracy,lower.tail=F) + y_bias*qlogis(pnorm(scale(df[x==0]$y))) + resids <- resid(lm(y~x + z)) + odds.x1 <- qlogis(prediction_accuracy) + y_bias*qlogis(pnorm(resids[x==1])) + odds.x0 <- qlogis(prediction_accuracy,lower.tail=F) + y_bias*qlogis(pnorm(resids[x==0])) ## acc.x0 <- p.correct[df[,x==0]] ## acc.x1 <- p.correct[df[,x==1]] @@ -115,8 +116,7 @@ simulate_data <- function(N, m, B0, Bxy, Bzx, Bzy, seed, y_explained_variance=0. df[,w_pred := as.integer(w > 0.5)] - print(mean(df[z==0]$x == df[z==0]$w_pred)) - print(mean(df[z==1]$x == df[z==1]$w_pred)) + print(mean(df$w_pred == df$x)) print(mean(df[y>=0]$w_pred == df[y>=0]$x)) print(mean(df[y<=0]$w_pred == df[y<=0]$x)) @@ -124,7 +124,7 @@ simulate_data <- function(N, m, B0, Bxy, Bzx, Bzy, seed, y_explained_variance=0. } parser <- arg_parser("Simulate data and fit corrected models") -parser <- add_argument(parser, "--N", default=1000, help="number of observations of w") +parser <- add_argument(parser, "--N", default=5000, help="number of observations of w") parser <- add_argument(parser, "--m", default=500, help="m the number of ground truth observations") parser <- add_argument(parser, "--seed", default=51, help='seed for the rng') parser <- add_argument(parser, "--outfile", help='output file', default='example_2.feather') @@ -136,7 +136,7 @@ parser <- add_argument(parser, "--Bzy", help='Effect of z on y', default=-0.3) parser <- add_argument(parser, "--Bxy", help='Effect of z on y', default=0.3) parser <- add_argument(parser, "--outcome_formula", help='formula for the outcome variable', default="y~x+z") parser <- add_argument(parser, "--proxy_formula", help='formula for the proxy variable', default="w_pred~y*z*x") -parser <- add_argument(parser, "--y_bias", help='coefficient of y on the probability a classification is correct', default=-0.75) +parser <- add_argument(parser, "--y_bias", help='coefficient of y on the probability a classification is correct', default=-1) parser <- add_argument(parser, "--truth_formula", help='formula for the true variable', default="x~z") args <- parse_args(parser)