Last updated: 2023-09-12

Checks: 7 0

Knit directory: survival-susie/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20230201) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 86371fe. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store

Unstaged changes:
    Modified:   analysis/run_ser_simple_dat.Rmd
    Modified:   analysis/ser_survival.Rmd
    Modified:   data/dsc3/susie.lbf.rds

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/time_comparison.Rmd) and HTML (docs/time_comparison.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 86371fe yunqiyang0215 2023-09-12 Build site.
Rmd 61b64c3 yunqiyang0215 2023-09-12 wflow_publish("analysis/time_comparison.Rmd")

dat = readRDS("./data/sim_dat_censoring.rds")
library(BVSNLP)
Bayesian Variable Selection using Non-Local priors for survival and logistic regression data.
Loading Version 1.1.8
library(survival)
# Modified Karl's code for intercept part
devtools::load_all("/Users/nicholeyang/Desktop/logisticsusie")
ℹ Loading logisticsusie
# Susie helper functions
# Function to calculate approximate BF based on Wakefield approximation
# @param z: zscore of the regression coefficient
# @param s: standard deviation of the estimated coefficient
compute_abf <- function(z, s, prior_variance){
  abf <- sqrt(s^2/(s^2+prior_variance))*exp(z^2/2*(prior_variance/(s^2+prior_variance)))
  return(abf)
}


compute_approx_post_var <- function(z, s, prior_variance){
  post_var <- 1/(1/s^2 + 1/prior_variance)
  return(post_var)
}

# @param post_var: posterior variance
# @param s: standard deviation of the estimated coefficient
# @param bhat: estimated beta effect
compute_approx_post_mean <- function(post_var, s, bhat){
  mu <- post_var/(s^2)*bhat
  return(mu)
}

surv_uni_fun <- function(x, y, o, prior_variance, estimate_intercept = 0, ...){
  fit <- coxph(y~ x + offset(o))
  bhat <- summary(fit)$coefficients[1, 1] # bhat = -alphahat
  sd <- summary(fit)$coefficients[1, 3]
  zscore <- bhat/sd
  bf <- compute_abf(zscore, sd, prior_variance)
  var <- compute_approx_post_var(zscore, sd, prior_variance)
  mu <- compute_approx_post_mean(var, sd, bhat)
  lbf <- log(bf)
  return(list(mu = mu, var=var, lbf=lbf, intercept=0))
}

fit_coxph <- ser_from_univariate(surv_uni_fun)
# IBSS of susie
set.seed(1)
p = 50
dat[[1]]$y <- with(dat[[1]], Surv(surT, status))
X = as.matrix(dat[[1]][, c(2:(p+1))])
y = dat[[1]]$y

t1 = proc.time()
fit1 <- ibss_from_ser(X, y, L = 2, prior_variance = 1., prior_weights = rep(1/p, p), tol = 1e-3, maxit = 10, estimate_intercept = TRUE, ser_function = fit_coxph)
Warning in ibss_from_ser(X, y, L = 2, prior_variance = 1, prior_weights = rep(1/
p, : Maximum number of iterations reached
4.349 sec elapsed
t2 = proc.time()

time.susie = t2 - t1
p = 50
X = as.data.frame(dat[[1]][, c(2:(p+1))])

t1 = proc.time()
fit = bvs(X, resp = y, prep = FALSE, family = "survival", mod_prior = "beta", niter = 10)
t2 = proc.time()

time.bvsnlp1 = t2 - t1


t1 = proc.time()
fit = bvs(X, resp = y, prep = FALSE, family = "survival", mod_prior = "beta", niter = 100)
t2 = proc.time()

time.bvsnlp2 = t2 - t1
time.bvsnlp1
   user  system elapsed 
  0.190   0.012   3.463 
time.bvsnlp2
   user  system elapsed 
  0.195   0.012   6.483 
time.susie
   user  system elapsed 
  4.105   0.104   4.363 

sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin20.6.0 (64-bit)
Running under: macOS Monterey 12.0.1

Matrix products: default
BLAS:   /usr/local/Cellar/openblas/0.3.18/lib/libopenblasp-r0.3.18.dylib
LAPACK: /usr/local/Cellar/r/4.1.1_1/lib/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] logisticsusie_0.0.0.9004 testthat_3.1.0           survival_3.2-11         
[4] BVSNLP_1.1.9             workflowr_1.6.2         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3       lattice_0.20-44    prettyunits_1.1.1  ps_1.6.0          
 [5] rprojroot_2.0.2    digest_0.6.28      foreach_1.5.2      utf8_1.2.2        
 [9] R6_2.5.1           evaluate_0.14      pillar_1.6.4       tictoc_1.1        
[13] rlang_1.1.1        rstudioapi_0.13    whisker_0.4        callr_3.7.3       
[17] jquerylib_0.1.4    Matrix_1.5-3       rmarkdown_2.11     desc_1.4.0        
[21] devtools_2.4.2     splines_4.1.1      stringr_1.4.0      compiler_4.1.1    
[25] httpuv_1.6.3       xfun_0.27          pkgconfig_2.0.3    pkgbuild_1.2.0    
[29] htmltools_0.5.5    tidyselect_1.1.1   tibble_3.1.5       codetools_0.2-18  
[33] matrixStats_0.63.0 fansi_0.5.0        dplyr_1.0.7        crayon_1.4.1      
[37] withr_2.5.0        later_1.3.0        grid_4.1.1         jsonlite_1.7.2    
[41] lifecycle_1.0.3    git2r_0.28.0       magrittr_2.0.1     cli_3.6.1         
[45] stringi_1.7.5      cachem_1.0.6       fs_1.5.0           promises_1.2.0.1  
[49] remotes_2.4.2      doParallel_1.0.17  bslib_0.4.1        generics_0.1.2    
[53] ellipsis_0.3.2     vctrs_0.6.3        iterators_1.0.14   tools_4.1.1       
[57] glue_1.4.2         purrr_0.3.4        processx_3.8.1     pkgload_1.2.3     
[61] parallel_4.1.1     fastmap_1.1.0      yaml_2.2.1         sessioninfo_1.1.1 
[65] memoise_2.0.1      knitr_1.36         sass_0.4.4         usethis_2.1.3