Created
June 15, 2016 14:36
-
-
Save sachsmc/ae58817b519b6b6e4d0f180bae02f58c to your computer and use it in GitHub Desktop.
A clever (?) but probably dangerous way to do resampling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env.copy <- new.env(parent = parent.env(environment(psdesign$likelihood))) | |
ps.copy <- psdesign | |
objs <- ls(environment(psdesign$likelihood)) | |
for(j in objs){ | |
assign(j, get(j, environment(psdesign$likelihood)), envir = env.copy) | |
} | |
assign("Y.trt", mixup(env.copy$Y.trt, env.copy$trtmat[, "Z"]), envir = env.copy) | |
assign("Y.untrt", mixup(env.copy$Y.untrt, env.copy$untrt.expand[, "Z"]), envir = env.copy) | |
environment(ps.copy$likelihood) <- env.copy | |
perm.est <- ps.copy + eval(ps.copy$estimate.call) | |
psdesign.0 <- psdesign | |
psdesign.0$augdata$Y <- mixup(psdesign.0$augdata$Y, psdesign.0$augdata$Z) | |
if(is.factor(psdesign.0$augdata$S.1)){ | |
if(length(unique(as.numeric(psdesign.0$augdata$S.1))) != length(unique(as.numeric(psdesign$augdata$S.1)))){ | |
bootpar[[i]] <- c(rep(NA, psdesign$nparam), convergence = 11) | |
next | |
} | |
} | |
## re-call integration models | |
psdesign2 <- psdesign.0 | |
for(intj in psdesign$integration.models){ | |
psdesign2 <- psdesign2 + do.call(as.character(intj$model$args[[1]]), intj$model$args[-1]) | |
} | |
## re-call risk model | |
psdesign3 <- psdesign2 + do.call(as.character(psdesign$risk.model$args[[1]]), psdesign$risk.model$args[-1]) | |
# estimate | |
perm.est <- psdesign3 + eval(psdesign$estimate.call) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment