tests/RUnit/RUnit_tests_04b_sims10K_h2oGLM.R

# --------------------------------------------------------------------------------------------------------
# Install data.table (most recent version)
# --------------------------------------------------------------------------------------------------------
# devtools::install_github('Rdatatable/data.table')
# --------------------------------------------------------------------------------------------------------
## For installing most recent vs of h2o see: https://s3.amazonaws.com/h2o-release/h2o/master/latest.html
# --------------------------------------------------------------------------------------------------------
# if ("package:h2o" %in% search()) detach("package:h2o", unload=TRUE)
# if ("h2o" %in% rownames(installed.packages())) remove.packages("h2o")
# # Next, download H2O package dependencies:
# pkgs <- c("methods","statmod","stats","graphics","RCurl","jsonlite","tools","utils")
# new.pkgs <- setdiff(pkgs, rownames(installed.packages()))
# if (length(new.pkgs)) install.packages(new.pkgs)
# # Download and install the H2O package for R:
# install.packages("h2o", type="source", repos=(c("https://s3.amazonaws.com/h2o-release/h2o/master/3636/R")))
# --------------------------------------------------------------------------------------------------------
# Install stremr
# --------------------------------------------------------------------------------------------------------
# devtools::install_github('osofr/stremr', build_vignettes = FALSE)

# test.h2oglm.IPW.MSM.10Kdata <- function() {
#   reqh2o <- requireNamespace("h2o", quietly = TRUE)
#   if (reqh2o) {
#     options(width = 100)
#     `%+%` <- function(a, b) paste0(a, b)
#     require("data.table")
#     require("h2o")

#     data(OdatDT_10K)
#     Odat_DT <- OdatDT_10K
#     setkeyv(Odat_DT, cols = c("ID", "t"))

#     # ---------------------------------------------------------------------------
#     # Define some summaries (lags C[t-1], A[t-1], N[t-1])
#     # ---------------------------------------------------------------------------
#     ID <- "ID"; t <- "t"; TRT <- "TI"; I <- "highA1c"; outcome <- "Y.tplus1";
#     lagnodes <- c("C", "TI", "N")
#     newVarnames <- lagnodes %+% ".tminus1"
#     Odat_DT[, (newVarnames) := shift(.SD, n=1L, fill=0L, type="lag"), by=ID, .SDcols=(lagnodes)]
#     # indicator that the person has never been on treatment up to current t
#     Odat_DT[, ("barTIm1eq0") := as.integer(c(0, cumsum(get(TRT))[-.N]) %in% 0), by = eval(ID)]
#     Odat_DT[, ("lastNat1.factor") := as.factor(lastNat1)]

#     # ----------------------------------------------------------------
#     # IMPORT DATA
#     # ----------------------------------------------------------------
#     # options(stremr.verbose = TRUE)
#     set_all_stremr_options(fit.package = "h2o", fit.algorithm = "glm")
#     h2o::h2o.init(nthreads = 1)

#     OData <- importData(Odat_DT, ID = "ID", t = "t", covars = c("highA1c", "lastNat1", "lastNat1.factor"), CENS = "C", TRT = "TI", MONITOR = "N", OUTCOME = outcome)
#     # to see the input data.table:
#     # OData$dat.sVar

#     # ------------------------------------------------------------------
#     # Fit propensity scores for Treatment, Censoring & Monitoring
#     # ------------------------------------------------------------------
#     gform_TRT <- "TI ~ CVD + highA1c + N.tminus1"
#     stratify_TRT <- list(
#       TI=c("t == 0L",                                            # MODEL TI AT t=0
#            "(t > 0L) & (N.tminus1 == 1L) & (barTIm1eq0 == 1L)",  # MODEL TRT INITATION WHEN MONITORED
#            "(t > 0L) & (N.tminus1 == 0L) & (barTIm1eq0 == 1L)",  # MODEL TRT INITATION WHEN NOT MONITORED
#            "(t > 0L) & (barTIm1eq0 == 0L)"                       # MODEL TRT CONTINUATION (BOTH MONITORED AND NOT MONITORED)
#           ))
#     gform_CENS <- c("C ~ highA1c + t")
#     gform_MONITOR <- "N ~ 1"
#     OData <- fitPropensity(OData, gform_CENS = gform_CENS, gform_TRT = gform_TRT,
#                             stratify_TRT = stratify_TRT, gform_MONITOR = gform_MONITOR)
#     wts.St.dlow <- getIPWeights(OData, intervened_TRT = "gTI.dlow")
#     wts.St.dhigh <- getIPWeights(OData, intervened_TRT = "gTI.dhigh")

#     # ------------------------------------------------------------------
#     # Running IPW-adjusted MSM for the hazard
#     # ------------------------------------------------------------------
#     MSM.IPAW <- survMSM(OData,
#                         wts_data = list(dlow = wts.St.dlow, dhigh = wts.St.dhigh),
#                         t_breaks = c(1:8,12,16)-1,
#                         est_name = "IPAW", getSEs = TRUE)
#     # names(MSM.IPAW)
#     # MSM.IPAW$St
#     if (rmarkdown::pandoc_available(version = "1.12.3"))
#         make_report_rmd(OData, MSM = MSM.IPAW,
#                     AddFUPtables = TRUE, openFile = FALSE,
#                     RDtables = get_MSM_RDs(MSM.IPAW, t.periods.RDs = c(12, 15), getSEs = TRUE),
#                     WTtables = get_wtsummary(MSM.IPAW$wts_data, cutoffs = c(0, 0.5, 1, 10, 20, 30, 40, 50, 100, 150), by.rule = TRUE),
#                     file.name = "sim.data.example.fup", title = "Custom Report Title", author = "Insert Author Name")
#   }

# }

Try the stremr package in your browser

Any scripts or data that you put into this service are public.

stremr documentation built on May 30, 2017, 6:35 a.m.