Computation Speed of Algorithms
Computation speeds of two algorithms
Let’s check the speeds of two algorithms. On the same data, we run the two algorithms with exact the same setting: 1 chain with 1000 adaptation and 2000 iterations.
data("schizow", package = "remiod")
tic()
test_a = remiod(formula = y6 ~ tx + y0 + y1 + y3, data = schizow, trtvar = 'tx',
algorithm = "jags", method = "MAR", ord_cov_dummy = FALSE,
n.iter = 2000, n.adapt = 1000, n.chains = 1, warn = FALSE,
mess = FALSE)
toc()
57.86 sec elapsed
tic()
test_b = remiod(formula = y6 ~ tx + y0 + y1 + y3, data = schizow, trtvar = 'tx',
algorithm = "tang_seq", method = "MAR", ord_cov_dummy = FALSE,
n.iter = 2000, n.adapt = 1000, n.chains = 1, warn = FALSE,
mess = FALSE)
toc()
563.85 sec elapsed
The results suggest that Algorithm “tang_seq” takes much more time. The partial reason is that “tang_seq” must iterate over all missing patterns besides the basic iteration over observations. Thus, the more the missing patterns are, the longer Algorithm “tang_seq” requires.
Parallel computing
Accompanying with Package doFuture, remiod can implement parallel computation on the chain level. Let’s check the time required for Bayesian sampling with 2 chains.
tic()
test_b = remiod(formula = y6 ~ tx + y0 + y1 + y3, data = schizow, trtvar = 'tx',
algorithm = "tang_seq", method = "MAR", ord_cov_dummy = FALSE,
n.iter = 2000, n.adapt = 1000, n.chains = 2, warn = FALSE, mess = FALSE)
toc()
1026.85 sec elapsed
tic()
registerDoFuture(); plan(multisession(workers = 2))
test_b = remiod(formula = y6 ~ tx + y0 + y1 + y3, data = schizow, trtvar = 'tx',
algorithm = "tang_seq", method = "MAR", ord_cov_dummy = FALSE,
n.iter = 2000, n.adapt = 1000, n.chains = 2, warn = FALSE, mess = FALSE)
plan(sequential)
toc()
543.59 sec elapsed
Without parallel setting, remiod with 2 chains roughly double times comparing with that using parallel chain running.
Please note that all above running is on a computer with Intel Xeon CPU E5-2670 2.60GHz and 100GB RAM memory.
sessionInfo()
## R version 4.1.3 (2022-03-10)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19044)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] doFuture_0.12.2 future_1.28.0 foreach_1.5.2 remiod_1.0.2
## [5] tictoc_1.0.1
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.9 lattice_0.20-45 listenv_0.8.0
## [4] fftwtools_0.9-11 assertthat_0.2.1 digest_0.6.30
## [7] utf8_1.2.2 parallelly_1.32.1 R6_2.5.1
## [10] ordinal_2019.12-10 ellipse_0.4.3 evaluate_0.18
## [13] coda_0.19-4 ggplot2_3.4.0 pillar_1.8.1
## [16] rlang_1.0.6 rstudioapi_0.13 data.table_1.14.4
## [19] jquerylib_0.1.4 rjags_4-13 Matrix_1.5-3
## [22] mcmcse_1.5-0 rmarkdown_2.17 mathjaxr_1.6-0
## [25] splines_4.1.3 stringr_1.4.1 munsell_0.5.0
## [28] compiler_4.1.3 numDeriv_2016.8-1.1 xfun_0.34
## [31] pkgconfig_2.0.3 globals_0.16.1 htmltools_0.5.3
## [34] tidyselect_1.2.0 tibble_3.1.8 progressr_0.10.1
## [37] codetools_0.2-18 fansi_1.0.3 ucminf_1.1-4
## [40] dplyr_1.0.10 brio_1.1.3 MASS_7.3-55
## [43] grid_4.1.3 JointAI_1.0.3 jsonlite_1.8.3
## [46] gtable_0.3.1 lifecycle_1.0.3 DBI_1.1.3
## [49] magrittr_2.0.3 scales_1.2.1 cli_3.4.1
## [52] stringi_1.7.8 cachem_1.0.6 testthat_3.1.5
## [55] bslib_0.4.0 generics_0.1.3 vctrs_0.5.0
## [58] iterators_1.0.14 tools_4.1.3 glue_1.6.2
## [61] parallel_4.1.3 fastmap_1.1.0 survival_3.2-13
## [64] yaml_2.3.6 colorspace_2.0-3 knitr_1.41
## [67] sass_0.4.2