-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexperiment_wrap.R
More file actions
160 lines (140 loc) · 6.33 KB
/
experiment_wrap.R
File metadata and controls
160 lines (140 loc) · 6.33 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# repeat experiments for interactive methods
# para_vary: a list of parameters that are different from the default in input.R file
experiment_interactive = function(para_vary){
source("input.R", local = TRUE)
for (single_para_vary in para_vary) {
assign(single_para_vary$name, single_para_vary$value)
}
wrapper_func = function(i){
print(i)
p_val = vector(length = length(methods_interactive)); names(p_val) = methods_interactive
dat = sample_generator(n = n, m = m,
treatment_type = treatment_type, control_type = control_type,
C_delta = C_delta, e_D = e_D,
redundant = redundant, blind = blind)
if ("CovAdj-Wilcoxon-linear" %in% methods_interactive) {
e = lm(Y ~ (. - A)^2 - 1, data = dat)$residuals
p_val["CovAdj-Wilcoxon-linear"] = wilcox.test(e ~ dat$A, paired = FALSE)$p.value
}
if ("CovAdj-Wilcoxon-robust" %in% methods_interactive) {
e = rlm(Y ~ (. - A)^2 - 1, data = dat)$residuals
p_val["CovAdj-Wilcoxon-robust"] = wilcox.test(e ~ dat$A, paired = FALSE)$p.value
}
if ("CovAdj-Wilcoxon-quadratic" %in% methods_interactive) {
e = rlm(Y ~ (. - A)^2 + I(X.3^2) - 1, data = dat)$residuals
p_val["CovAdj-Wilcoxon-quadratic"] = wilcox.test(e ~ dat$A, paired = FALSE)$p.value
}
if ("linear-CATE-test" %in% methods_interactive) {
p_val["linear-CATE-test"] = linear_CATE_test(dat)
}
if ("i-Wilcoxon-linear" %in% methods_interactive) {
p_val["i-Wilcoxon-linear"] =
i_Wilcoxon(dat, alg_type = "linear", iter_round = iter_round)
}
if ("i-Wilcoxon-robust" %in% methods_interactive) {
p_val["i-Wilcoxon-robust"] =
i_Wilcoxon(dat, alg_type = "robust", iter_round = iter_round)
}
if ("i-Wilcoxon-quadratic" %in% methods_interactive) {
p_val["i-Wilcoxon-quadratic"] =
i_Wilcoxon(dat, alg_type = "quadratic", iter_round = iter_round)
}
cand_set = rep(FALSE, n); cand_set[sample(n, n*split_pct)] = TRUE
if ("i-bid-linear" %in% methods_interactive) {
p_val["i-bid-linear"] =
i_bid(dat, cand_set = cand_set, alg_type = "linear", scale = scale, iter_round = iter_round)
}
if ("i-bid-robust" %in% methods_interactive) {
p_val["i-bid-robust"] =
i_bid(dat, cand_set = cand_set, alg_type = "robust", scale = scale, iter_round = iter_round)
}
if ("i-bid-quadratic" %in% methods_interactive) {
p_val["i-bid-quadratic"] =
i_bid(dat, cand_set = cand_set, alg_type = "quadratic", scale = scale, iter_round = iter_round)
}
if ("i-bid-cross-linear" %in% methods_interactive) {
p_val["i-bid-cross-linear"] =
i_bid_cross(dat, alg_type = "linear", scale = scale, iter_round = iter_round)
}
if ("i-bid-cross-robust" %in% methods_interactive) {
p_val["i-bid-cross-robust"] =
i_bid_cross(dat, alg_type = "robust", scale = scale, iter_round = iter_round)
}
if ("i-bid-cross-quadratic" %in% methods_interactive) {
p_val["i-bid-cross-quadratic"] =
i_bid_cross(dat, alg_type = "quadratic", scale = scale, iter_round = iter_round)
}
if ("end-bid-cross-linear" %in% methods_interactive) {
p_val["end-bid-cross-linear"] =
end_bid_cross(dat, alg_type = "linear", scale = scale)
}
if ("end-bid-cross-robust" %in% methods_interactive) {
p_val["end-bid-cross-robust"] =
end_bid_cross(dat, alg_type = "robust", scale = scale)
}
if ("end-bid-cross-quadratic" %in% methods_interactive) {
p_val["end-bid-cross-quadratic"] =
end_bid_cross(dat, alg_type = "quadratic", scale = scale)
}
if ("i-Wilcoxon-linear-signedA" %in% methods_interactive) {
p_val["i-Wilcoxon-linear-signedA"] =
i_Wilcoxon(dat, alg_type = "linear", sum_type = "signed_A", order_by = "abs_pred",
iter_round = iter_round)
}
if ("i-Wilcoxon-robust-signedA" %in% methods_interactive) {
p_val["i-Wilcoxon-robust-signedA"] =
i_Wilcoxon(dat, alg_type = "robust", sum_type = "signed_A", order_by = "abs_pred",
iter_round = iter_round)
}
if ("i-Wilcoxon-robust-signedA_adapt" %in% methods_interactive) {
p_val["i-Wilcoxon-robust-signedA_adapt"] =
i_Wilcoxon(dat, alg_type = "robust", sum_type = "signed_A", order_by = "adapt_pred",
iter_round = iter_round)
}
if ("i-Wilcoxon-quadratic-signedA" %in% methods_interactive) {
p_val["i-Wilcoxon-quadratic-signedA"] =
i_Wilcoxon(dat, alg_type = "quadratic", sum_type = "signed_A", order_by = "abs_pred",
iter_round = iter_round)
}
if ("i-Wilcoxon-quadratic-signedA_adapt" %in% methods_interactive) {
p_val["i-Wilcoxon-quadratic-signedA_adapt"] =
i_Wilcoxon(dat, alg_type = "quadratic", sum_type = "signed_A", order_by = "adapt_pred",
iter_round = iter_round)
}
if ("i-Wilcoxon-oracle" %in% methods_interactive) {
p_val["i-Wilcoxon-oracle"] =
i_Wilcoxon(dat, C_delta = C_delta, alg_type = "oracle",
sum_type = "signed_A", order_by = "abs_pred")
}
return(p_val)
}
# p_vals = lapply(1:R, wrapper_func)
p_vals = mclapply(1:R, wrapper_func, mc.cores = detectCores())
return(p_vals)
}
# repeat experiments for non-interactive variants of the Wilcoxon signed rank tests
# para_vary: a list of parameters that are different from the default in input.R file
experiment_var_Wilcoxon = function(para_vary){
source("input.R", local = TRUE)
for (single_para_vary in para_vary) {
assign(single_para_vary$name, single_para_vary$value)
}
wrapper_func = function(i){
print(i)
dat = sample_generator(n = n, m = m,
treatment_type = treatment_type, control_type = control_type,
C_delta = C_delta, e_D = e_D,
redundant = redundant, blind = blind)
if (alg_type == "linear") {
R = rlm(Y ~ (. - A)^2 - 1, data = dat)$residuals
} else if(alg_type == "RF"){
R = dat$Y - randomForest(Y ~ . - A, data = dat)$predicted
}
df = cbind(dat, R = R)
p_vals = var_wilcoxon(dat = df, alg_type = alg_type, n_permute = n_permute)
#return(p_vals[methods_var_Wilcoxon])
return(p_vals)
}
p_vals = lapply(1:R, wrapper_func)
return(p_vals)
}