-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1_GenerateMAData.R
82 lines (71 loc) · 3.32 KB
/
1_GenerateMAData.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
# Generate Binary Event Meta-Analysis Data
library(future.apply)
plan(multisession, workers = 2)
source("0_DGMs.R") # Data Generating Methods
# Function to Replicate Data ---------------------------------------------------
SaveDataSets <- function(theta, k, tau2, p_ic_init, min_n, max_n, num_reps,
dir) {
pCFixed_data_sets <- replicate(num_reps,
pCfixedGenerateMAData(theta = theta,
k = k,
tau2 = tau2,
p_ic_init = p_ic_init,
min_n = min_n,
max_n = max_n))
pRandomB_data_sets <- replicate(num_reps,
pRandomBGenerateMAData(theta = theta,
k = k,
tau2 = tau2,
p_ic_init = p_ic_init,
min_n = min_n,
max_n = max_n))
# Save as RData files
save(pCFixed_data_sets,
file = paste0(dir, "/pCFixed,Theta=", theta,
",Tau2=", tau2,
",P_ic=", p_ic_init,
",MinN=", min_n,
",MaxN=", max_n, ".RData"))
save(pRandomB_data_sets,
file = paste0(dir, "/pRandomB,Theta=", theta,
",Tau2=", tau2,
",P_ic=", p_ic_init,
",MinN=", min_n,
",MaxN=", max_n, ".RData"))
}
# Generate DGM combinations with expand.grid and set parameter values ----------
theta_sim_vals <- seq(-1.5, 1.5, 0.5)
tau2_sim_vals <- c(0, 0.2, 0.4, 0.8)
p_ic_init_small <- c(0.01, 0.05, 0.1)
p_ic_init_large <- c(0.01, 0.05)
# small sample sizes
dgm_param_combs_small <- expand.grid("theta" = theta_sim_vals,
"tau2" = tau2_sim_vals,
"p_ic_init" = p_ic_init_small)
dgm_param_combs_small$min_n <- 10
dgm_param_combs_small$max_n <- 100
# large sample sizes
dgm_param_combs_large <- expand.grid("theta" = theta_sim_vals,
"tau2" = tau2_sim_vals,
"p_ic_init" = p_ic_init_large)
dgm_param_combs_large$min_n <- 100
dgm_param_combs_large$max_n <- 500
# combine small and large into one data frame
dgm_param_combs <- rbind(dgm_param_combs_large, dgm_param_combs_small)
num_reps <- 2
k <- 10
seed <- 1234
# Parallelize Code -------------------------------------------------------------
rdsdir <- "./RDSDataSets"
if (!dir.exists(rdsdir))
dir.create(rdsdir)
future_mapply("SaveDataSets",
theta = dgm_param_combs$theta,
tau2 = dgm_param_combs$tau2,
p_ic_init = dgm_param_combs$p_ic_init,
min_n = dgm_param_combs$min_n,
max_n = dgm_param_combs$max_n,
MoreArgs = list(k = k,
num_reps = num_reps),
future.seed = seed,
dir = rdsdir)