X-Git-Url: https://code.communitydata.science/ml_measurement_error_public.git/blobdiff_plain/5c931a7198452ff3ce0ace5b1f68046bfb33d352..d9d3e47a44ddead1cdf7a649bc0e9849c2219498:/simulations/01_two_covariates.R?ds=sidebyside diff --git a/simulations/01_two_covariates.R b/simulations/01_two_covariates.R index b8f9317..1f317be 100644 --- a/simulations/01_two_covariates.R +++ b/simulations/01_two_covariates.R @@ -30,11 +30,11 @@ source("simulation_base.R") #### how much power do we get from the model in the first place? (sweeping N and m) #### -simulate_data <- function(N, m, B0=0, Bxy=0.2, Bzy=-0.2, Bzx=0.2, y_explained_variance=0.025, prediction_accuracy=0.73, seed=1){ +simulate_data <- function(N, m, B0=0, Bxy=0.2, Bzy=-0.2, Bzx=0.2, y_explained_variance=0.025, prediction_accuracy=0.73, Px=0.5, seed=1){ set.seed(seed) z <- rnorm(N,sd=0.5) # x.var.epsilon <- var(Bzx *z) * ((1-zx_explained_variance)/zx_explained_variance) - xprime <- Bzx * z #+ x.var.epsilon + xprime <- Bzx * z + qlogis(Px) x <- rbinom(N,1,plogis(xprime)) y.var.epsilon <- (var(Bzy * z) + var(Bxy *x) + 2*cov(Bxy*x,Bzy*z)) * ((1-y_explained_variance)/y_explained_variance) @@ -78,18 +78,21 @@ parser <- add_argument(parser, "--truth_formula", help='formula for the true var 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 x on y', default=0.3) +parser <- add_argument(parser, "--Px", help='Base rate of x', default=0.5) +parser <- add_argument(parser, "--confint_method", help='method for approximating confidence intervals', default='quad') args <- parse_args(parser) B0 <- 0 +Px <- args$Px Bxy <- args$Bxy Bzy <- args$Bzy Bzx <- args$Bzx -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) +df <- simulate_data(args$N, args$m, B0, Bxy, Bzy, Bzx, Px, 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, 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='') +result <- list('N'=args$N,'m'=args$m,'B0'=B0,'Bxy'=Bxy, 'Bzx'=Bzx, 'Bzy'=Bzy, 'Px'=Px, '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, confint_method=args$confint_method,error='') -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)) +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),confint_method=args$confint_method) outfile_lock <- lock(paste0(args$outfile, '_lock'),exclusive=TRUE) if(file.exists(args$outfile)){