]> code.communitydata.science - ml_measurement_error_public.git/blobdiff - simulations/02_indep_differential.R
Update stuff.
[ml_measurement_error_public.git] / simulations / 02_indep_differential.R
index c6907d3adbeb46ce0d55e5a6a4d720ca2481eb6f..bcfad65f8dc63659fd306977fe546ac40d16f660 100644 (file)
@@ -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)

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