-
Notifications
You must be signed in to change notification settings - Fork 0
/
080-tmle3sim.Rmd
72 lines (54 loc) · 1.27 KB
/
080-tmle3sim.Rmd
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
# Monte Carlo Simulation with `tmle3sim`
_Jeremy Coyle_
## Intro
## Architecture
## Other
## Previous Documentation
```{r example, eval=FALSE}
library(devtools)
library(tmle3)
load_all()
# define simulation / DGD
# TODO: maybe DGD should be separate object
example_dgd <- function(n, mean, sd, ...) {
list(x = rnorm(n, mean, sd))
}
params <- list(
n = 1000,
mean = 0,
sd = 1
)
simulation <- sim_from_fun(example_dgd,
params = params,
vebose = TRUE
)
# define estimation strategy
example_est <- function(simulation, ...) {
data <- simulation$last_sample
result <- list(
xbar = mean(data$x),
sigma = sd(data$x)
)
return(result)
}
example_est2 <- function(simulation, ...) {
data <- simulation$last_sample
result <- list(
xbar = median(data$x),
sigma = IQR(data$x)
)
return(result)
}
mean_est <- est_from_fun(example_est, params = list(name = "mean_estimator"))
median_est <- est_from_fun(example_est2, params = list(name = "median_estimator"))
t3s_Reporter$new()
simulations <- list(simululation)
simulation$estimator <-
simulation$reporter <-
simulation$full_params
# debugonce(simulation$reporter$report)
# debugonce(simulation$reporter$make_final)
simulation$run()
debugonce(simulation$reporter$save)
simulation$reporter$save()
```