-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpar_fun.R
54 lines (42 loc) · 2.57 KB
/
par_fun.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
#'
#' 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.
#'
#' @param seed An integer random seed (placeholder - seed is set by BatchJobs)
#' @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_CG (described in paper) over 100 resamplings of the data
par_fun <- function(seed,rand=F){
# 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")
load("genesigprecision_data.Rda")
result <- matrix(NA,1000,12)
i <- 1
while(i <= 1000){
pdtmp <- sampfun(pd) # We sample the data as per the scheme selected
pdtmp$trt <- rbinom(nrow(pdtmp), 1, 0.5) # Exogenous treatment assignment
out_clin_no_er <- tryCatch(run_analysis(pdtmp, c("Characteristics.Age", "Characteristics.TumorSize", "g2ind", "g3ind")), error=function(e) e)
out_clin_er <- tryCatch(run_analysis(pdtmp, c("Characteristics.Age", "Characteristics.TumorSize", "Factor.Value.ER.status", "g2ind", "g3ind")), error=function(e) e)
out_gen <- tryCatch(run_analysis(pdtmp, c("Factor.Value.MammaPrint.prediction")), error=function(e) e)
out_cg <- tryCatch(run_analysis(pdtmp, c("Characteristics.Age", "Characteristics.TumorSize", "Factor.Value.ER.status", "g2ind", "g3ind", "Factor.Value.MammaPrint.prediction")), 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
}