-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_test_output.r
176 lines (147 loc) · 3.88 KB
/
gen_test_output.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
library('meta')
# load all data
all_data <- read.csv('testsets/test_input.csv')
# get all outcomes
ocns = unique(all_data$outcome)
###########################################################
# Generate tests for OR fixed and random with MH/DL/nohak
###########################################################
# the final dataframe for output
df_rsts = data.frame()
# start count time
start_time <- Sys.time()
for (i in 1:length(ocns)) {
ocn = ocns[i]
df <- all_data[all_data$outcome == ocn, c('study', 'Et', 'Nt', 'Ec', 'Nc')]
# get the result of this study
r <- metabin(
Et,
Nt,
Ec,
Nc,
data = df,
studlab = study,
sm = "OR",
method = "MH",
method.tau = "DL",
prediction = FALSE,
hakn = FALSE
)
df_rst = data.frame(
"outcome" = c(paste(ocn)),
"sm" = c('OR'),
"TE.fixed" = c(r$TE.fixed),
"lower.fixed" = c(r$lower.fixed),
"upper.fixed" = c(r$upper.fixed),
"TE.random" = c(r$TE.random),
"lower.random" = c(r$lower.random),
"upper.random" = c(r$upper.random),
"I2" = c(r$I2),
"tau2" = c(r$tau2),
"pval.Q" = c(r$pval.Q)
)
# merge this record
df_rsts = rbind(df_rsts, df_rst)
}
end_time <- Sys.time()
print(paste0('Spent: ', end_time - start_time, ' for OR fixed and random'))
# print(df_rsts)
write.csv(
df_rsts,
file='testsets/test_result_OR.csv',
row.names = FALSE
)
###########################################################
# Generate tests for OR fixed and random with MH/DL/nohak
###########################################################
# the final dataframe for output
df_rsts = data.frame()
# start count time
start_time <- Sys.time()
for (i in 1:length(ocns)) {
ocn = ocns[i]
df <- all_data[all_data$outcome == ocn, c('study', 'Et', 'Nt', 'Ec', 'Nc')]
# get the result of this study
r <- metabin(
Et,
Nt,
Ec,
Nc,
data = df,
studlab = study,
sm = "RR",
method = "MH",
method.tau = "DL",
prediction = FALSE,
hakn = FALSE
)
df_rst = data.frame(
"outcome" = c(paste(ocn)),
"sm" = c('RR'),
"TE.fixed" = c(r$TE.fixed),
"lower.fixed" = c(r$lower.fixed),
"upper.fixed" = c(r$upper.fixed),
"TE.random" = c(r$TE.random),
"lower.random" = c(r$lower.random),
"upper.random" = c(r$upper.random),
"I2" = c(r$I2),
"tau2" = c(r$tau2),
"pval.Q" = c(r$pval.Q)
)
# merge this record
df_rsts = rbind(df_rsts, df_rst)
}
end_time <- Sys.time()
print(paste0('Spent: ', end_time - start_time, ' for RR fixed and random'))
# print(df_rsts)
write.csv(
df_rsts,
file='testsets/test_result_RR.csv',
row.names = FALSE
)
###########################################################
# Generate tests for INCD/PFT fixed and random with Inverse/DL/nohak
###########################################################
# the final dataframe for output
df_rsts = data.frame()
# start count time
start_time <- Sys.time()
for (i in 1:length(ocns)) {
ocn = ocns[i]
df <- all_data[all_data$outcome == ocn, c('study', 'Et', 'Nt', 'Ec', 'Nc')]
# get the result of this study
r <- metaprop(
Et,
Nt,
data = df,
studlab = study,
sm = "PFT",
method = "Inverse",
method.tau = "DL",
prediction = FALSE,
hakn = FALSE
)
df_rst = data.frame(
"outcome" = c(paste(ocn)),
"sm" = c('PFT'),
"TE.fixed" = c(r$TE.fixed),
"lower.fixed" = c(r$lower.fixed),
"upper.fixed" = c(r$upper.fixed),
"TE.random" = c(r$TE.random),
"lower.random" = c(r$lower.random),
"upper.random" = c(r$upper.random),
"I2" = c(r$I2),
"tau2" = c(r$tau2),
"pval.Q" = c(r$pval.Q)
)
# merge this record
df_rsts = rbind(df_rsts, df_rst)
}
end_time <- Sys.time()
print(paste0('Spent: ', end_time - start_time, ' for PFT fixed and random'))
# print(df_rsts)
write.csv(
df_rsts,
file='testsets/test_result_PFT.csv',
row.names = FALSE
)