X-Git-Url: https://code.communitydata.science/ml_measurement_error_public.git/blobdiff_plain/46e2d1fe4876a9ed906b723f9e5f74fcc949e339..b52b4f7daaba8a877b041ddb24c8f36b466ddc5b:/simulations/01_two_covariates.R?ds=sidebyside diff --git a/simulations/01_two_covariates.R b/simulations/01_two_covariates.R index 73e8939..3fd6914 100644 --- a/simulations/01_two_covariates.R +++ b/simulations/01_two_covariates.R @@ -71,21 +71,27 @@ parser <- add_argument(parser, "--outfile", help='output file', default='example parser <- add_argument(parser, "--y_explained_variance", help='what proportion of the variance of y can be explained?', default=0.05) # parser <- add_argument(parser, "--zx_explained_variance", help='what proportion of the variance of x can be explained by z?', default=0.3) parser <- add_argument(parser, "--prediction_accuracy", help='how accurate is the predictive model?', default=0.73) -parser <- add_argument(parser, "--Bzx", help='coefficient of z on x?', default=1) -args <- parse_args(parser) +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~x") + +parser <- add_argument(parser, "--truth_formula", help='formula for the true variable', default="x~z") +parser <- add_argument(parser, "--Bzx", help='Effect of z on x', default=0.3) +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) +args <- parse_args(parser) B0 <- 0 -Bxy <- 0.3 -Bzy <- -0.3 +Bxy <- args$Bxy +Bzy <- args$Bzy Bzx <- args$Bzx if (args$m < args$N){ df <- simulate_data(args$N, args$m, B0, Bxy, Bzy, Bzx, seed=args$seed + 500, y_explained_variance = args$y_explained_variance, prediction_accuracy=args$prediction_accuracy) - result <- list('N'=args$N,'m'=args$m,'B0'=B0,'Bxy'=Bxy,'Bzy'=Bzy, 'Bzx'=Bzx, 'seed'=args$seed, 'y_explained_variance' = args$y_explained_variance, 'zx_explained_variance' = args$zx_explained_variance, "prediction_accuracy"=args$prediction_accuracy, "error"="") + result <- list('N'=args$N,'m'=args$m,'B0'=B0,'Bxy'=Bxy, Bzx=Bzx, 'Bzy'=Bzy, 'seed'=args$seed, 'y_explained_variance'=args$y_explained_variance, 'prediction_accuracy'=args$prediction_accuracy, 'accuracy_imbalance_difference'=args$accuracy_imbalance_difference, 'outcome_formula'=args$outcome_formula, 'proxy_formula'=args$proxy_formula,truth_formula=args$truth_formula, error='') - outline <- run_simulation(df, result) + outline <- run_simulation(df, result, outcome_formula=as.formula(args$outcome_formula), proxy_formula=as.formula(args$proxy_formula), truth_formula=as.formula(args$truth_formula)) outfile_lock <- lock(paste0(args$outfile, '_lock'),exclusive=TRUE) if(file.exists(args$outfile)){