examples_tests/ex.R

# devtools::install_github("jeremyrcoyle/sl3")
# devtools::install_github("jlstiles/SDE_transport")
library("SDEtransportsim")
library("parallel")
library("doParallel")

func_formsYM$func_listYMmis
func_formsYZ$func_listYZmis

forms = func_formsYM$formswell
forms = lapply(forms, formula)
# forms$Zform = formula("Z~A*W2")
# forms$Mform = formula("M~Z*W2")
truth = func_formsYM$func_listYMmis
truth

n=1e6
W = truth$f_W(n)
p_S = truth$f_S(W)
hist(p_S, breaks = 200)
S = rbinom(n, 1, p_S)
p_A = truth$f_A(S,W)
hist(p_A, breaks = 200)
A = rbinom(n, 1, p_A)
p_Z = truth$f_Z(A,S,W)
hist(p_Z, breaks = 200)
Z = rbinom(n, 1, p_Z)
p_M = truth$f_M(Z, W, S)
hist(p_M, breaks = 200)
M = rbinom(n, 1, p_M)
p_Y = truth$f_Y(M,Z,W)
hist(p_Y, breaks = 200)
Y = rbinom(n, 1, p_Y)
mean(Y)

Wnames = c("W2")
Wnamesalways = c("W2")

data = gendata.SDEtransport(1e3, truth$f_W, truth$f_S, truth$f_A, 
                   truth$f_Z, truth$f_M, truth$f_Y)
head(data)
data$weights = rep(1,nrow(data))
res1 = try(suppressWarnings(SDE_tmle_lasso(data, forms, RCT = 0.5, Wnames = Wnames, Wnamesalways = Wnamesalways, 
                                           transport = TRUE, pooled = TRUE, gstar_S = 0, truth = truth))) 


res2 = SDE_glm4(data, truth = truth, truncate = list(lower =.0001, upper = .9999), 
                           B = NULL, forms, RCT = 0.5) 


result_lasso = rbind(c(res1$CI_SDE, res1$SDE0),c(res1$CI_SIE, res1$SIE0))
result_glm = rbind(c(res2$CI_SDE, res2$SDE_0),c(res2$CI_SIE, res2$SIE_0))

result_lasso
result_glm

debug(get_gstarM_lasso)
debug(SDE_tmle_lasso)
debug(get.mediation.initdata_lasso)
debug(mediation.step1_lasso)
debug(mediation.step2_lasso)
debug(mediation.step1_glm)
jlstiles/SDE_transport documentation built on Feb. 6, 2020, 2:06 p.m.