-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpar_fun_eset.R
62 lines (47 loc) · 2.63 KB
/
par_fun_eset.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#'
#' Parallelized Adjusted Estimator Simulation Function
#'
#' This function constructs a simulated dataset from the data saves in genesigprecision_data.Rda
#' and computes the adjusted and unadjusted treatment effect estimates. This process is repeated
#' 1000 times. This function is called by BatchJobs 100 times to complete and aggregate results
#' of 100,000 simulations of the described form. We split data into training and test sets and
#' resample from the test data. We get approximations of precision gain from the resampled test data
#' using covariates that are predictions from the models built on the training data.
#'
#; This function operates on an expression set
#'
#' @param seed An integer random seed
#' @param rand (logical) T indicates that you would like to permute all labels and remove corellation in the dataset. F indicates that you would like to permute records only and retain relationships between covariates
#'
#' @export
#'
#' @return A 1000 x 15 matrix with results for W_{-age}, W_C, W_G, W_C;W_G, W_CG (described in paper) over 100 simulations
par_fun_eset <- function(seed,pd,rand=F){
#set.seed(seed)
# If rand==F, we are doing a normal resampling. If rand==T, we are perumuting labels
if(!rand){
sampfun <- function(pd){ pd[sample(nrow(pd), replace=TRUE),]}
} else {
sampfun <- function(pd){ytmp <- sample(pd$y, replace=TRUE); pd <- pd[sample(nrow(pd), replace=TRUE),]; pd$y <- ytmp; pd}
}
options(warn=-1)
source("functions.R")
result <- matrix(NA,1000,12)
i <- 1
while(i <= 1000){
pdtmp <- sampfun(pd) # We sample the data as per the scheme selected
pdtmp <- pdtmp[sample(1:nrow(pdtmp),nrow(pdtmp)/2,replace=T),] #Take a random 50% subset
pdtmp$trt <- rbinom(nrow(pdtmp), 1, 0.5) # Exogenous treatment assignment
out_clin_no_er <- tryCatch(run_analysis(pdtmp, c("age", "size", "g2ind", "g3ind")), error=function(e) e)
out_clin_er <- tryCatch(run_analysis(pdtmp, c("age", "size", "er", "g2ind", "g3ind")), error=function(e) e)
out_gen <- tryCatch(run_analysis(pdtmp, c("mammaprint")), error=function(e) e)
out_cg <- tryCatch(run_analysis(pdtmp, c("age", "size", "er", "g2ind", "g3ind", "mammaprint")), error=function(e) e)
if(any(unlist(lapply(list(out_clin_no_er, out_clin_er, out_gen, out_cg), inherits, "error")))){
print("I made an error...check why.")
next
}
result[i,] <- c(unlist(out_clin_no_er), unlist(out_clin_er), unlist(out_gen), unlist(out_cg))
i <- i+1
}
result
}