-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsim-stable.R
58 lines (52 loc) · 2.23 KB
/
sim-stable.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
library("foreach")
library("doParallel")
library("parallel")
source("init.R")
source("sim.R")
## set number of Monte Carlo replicates
M <- 1000
## set number of threads to use for parallel processing and the random seed
## nb: these two values ensure that the results are replicable
cores <- 2
seed <- 0
cl <- makeCluster(getOption("cl.cores", cores))
clusterEvalQ(cl, source("init.R"))
registerDoParallel(cl)
sim.stable <- function() {
out <- NULL
for (n in c(30,60)) {
for (tmax in c(30,50)) {
clusterSetRNGStream(cl, seed)
out <- rbind(out,
sim(n, tmax, M,
## regress response on proximal treatment, centered by a
## probability that is either (i) constant over time or
## (ii) time-varying
y.formula = list(fixed = y ~ state + I(a - pfixed),
vary = y ~ state + I(a - pvary)),
y.names = c(fixed = "Constant in $t$ (i)",
vary = "Depends on $S_t$ (ii)"),
y.label = list(fixed = "I(a - pfixed)",
vary = "I(a - pvary)"),
## weight regression using the true treatment probability
## in the denominator
y.args = list(fixed = list(wn = "pfixed", wd = "prob"),
vary = list(wn = "pvary", wd = "prob")),
## model numerator probability with (i) intercept only and
## (ii) state, which is time-varying
a.formula = list(pfixed = a ~ 1,
pvary = a ~ state),
a.names = c(pfixed = "Constant in $t$ (i)",
pvary = "Depends on $S_t$ (ii)"),
## use default generative model, but with medium level of
## moderation by state and an unmoderated delayed effect
beta0 = c(-0.2, 0, 0, 0.5, 0),
beta1 = c(-0.1, 0, 0, 0)
))
}
}
out
}
stable <- sim.stable()
save(stable, file = "sim-stable.RData")
stopCluster(cl)