Last updated: 2023-04-02
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 3c218db. 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: analysis/.DS_Store
Ignored: analysis/.RData
Ignored: analysis/.Rhistory
Ignored: analysis/figure/
Untracked files:
Untracked: analysis/ibss_null_model.Rmd
Unstaged changes:
Modified: analysis/check_coxph_fit.Rmd
Deleted: analysis/null_model_demo.Rmd
Modified: analysis/null_model_zscore.Rmd
Deleted: analysis/one_predictor_investigation.Rmd
Deleted: analysis/ser_survival.Rmd
Modified: analysis/sim_survival_with_censoring.Rmd
Modified: code/VI_exponential.R
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/vi_exponential.Rmd
) and HTML (docs/vi_exponential.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 |
---|---|---|---|---|
Rmd | 3c218db | yunqiyang0215 | 2023-04-02 | wflow_publish("analysis/vi_exponential.Rmd") |
html | b65d4e4 | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | 7a1d935 | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | d28113a | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | 5fdca53 | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | eb4daeb | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | 6c36c1e | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 198d526 | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | d2f7348 | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | e63707e | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | 0185d47 | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | d401c35 | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | 4be0084 | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 0448d61 | yunqiyang0215 | 2023-03-28 | Build site. |
Rmd | c48008f | yunqiyang0215 | 2023-03-28 | wflow_publish("analysis/vi_exponential.Rmd") |
html | bd953f3 | yunqiyang0215 | 2023-03-27 | Build site. |
Rmd | 1f4f29f | yunqiyang0215 | 2023-03-27 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 42bd7c9 | yunqiyang0215 | 2023-03-27 | Build site. |
Rmd | d440e56 | yunqiyang0215 | 2023-03-27 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 7e681f8 | yunqiyang0215 | 2023-03-27 | Build site. |
Rmd | 00a41d0 | yunqiyang0215 | 2023-03-27 | wflow_publish("analysis/vi_exponential.Rmd") |
html | bcdf196 | yunqiyang0215 | 2023-03-27 | Build site. |
Rmd | daeebdb | yunqiyang0215 | 2023-03-27 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 599ae7f | yunqiyang0215 | 2023-03-25 | Build site. |
Rmd | a3b74ea | yunqiyang0215 | 2023-03-25 | wflow_publish("analysis/vi_exponential.Rmd") |
html | 01efa0e | yunqiyang0215 | 2023-03-24 | Build site. |
Rmd | dbad2be | yunqiyang0215 | 2023-03-24 | wflow_publish("analysis/vi_exponential.Rmd") |
\[ \begin{split} b&\sim N(0, \sigma^2)\\ h(t)&=h_0(t)\exp\{bx\}\\ \end{split} \] And we assume \(h_0(t) =h_0\), constant baseline hazard and independent censoring. \(y_i=\min(t_i,c_i)\), and \(\delta_i\) indicates censoring status. \(\delta_i=1\): the event time is observed and \(\delta_i=0\) indicates censoring.
library(survival)
source("./code/VI_exponential.R")
\[ \begin{split} S(t)&=\exp\{-h(t)*t\}\\ F(t)&=1-S(t)\sim U[0,1]\\ \end{split} \] Using this relationship, we can simulate \(t_i\) by: \[ \begin{split} t_i=\log(1-u_i)/(-h_0\exp\{bx_i\}) \end{split} \] Check if the data simulation makes sense
set.seed(1)
n = 1e4
censoring_lvl = 0
s2 = 1 #prior variance of b
h0 = 2
b = rnorm(1, mean = 0, sd = s2)
print(b)
[1] -0.6264538
seeds = c(1:100)
bhat = rep(NA, 100)
for (seed in seeds){
x = rnorm(n, 1)
y <- log(1 - runif(n)) / (-h0*exp(x*b))
# Status variable delta. delta = 1, outcome observed. delta = 0, censored.
d = rbinom(n, size = 1, prob = 1-censoring_lvl)
y[!d] <- y[!d] * runif(sum(!d))
y.surv <- Surv(y, d)
cox1 <- coxph(y.surv ~ x)
bhat[seed] = coef(cox1)[1]
}
hist(bhat)
abline(v = mean(bhat), col = "red")
abline(v = b, col = "blue")
# change parameter init vals
# the first param is m, the second is v2.
lower = c(-100, 1e-12)
upper = c(100, 100)
res1 <- update_q(x, y, d, h0 = 2, m = 1, v2 = 1, s2 = 1, maxiter = 100, tol = 0.1, lower, upper)
head(res1)
elbo h0 m v2 s2
[1,] -9372.888 1.999090 -0.6362026 4.352175e-05 0.4047972
[2,] -9372.887 1.998548 -0.6359282 4.339616e-05 0.4044481
[3,] -9372.887 1.998275 -0.6357907 4.366658e-05 0.4042734
[4,] -9372.886 1.998138 -0.6357215 4.379216e-05 0.4041856
[5,] -9372.886 1.998069 -0.6356867 4.385257e-05 0.4041414
[6,] -9372.886 1.998035 -0.6356692 4.388225e-05 0.4041192
tail(res1)
elbo h0 m v2 s2
[95,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
[96,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
[97,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
[98,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
[99,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
[100,] -9372.886 1.997999 -0.6356515 4.391179e-05 0.4040968
# change parameter init vals
lower = c(-100, 1e-12)
upper = c(100, 100)
res2 <- update_q(x[1:20], y[1:20], d[1:20], h0 = 10, m = 1, v2 = 1, s2 = 50, maxiter = 50, tol = 0.1, lower, upper)
head(res2)
elbo h0 m v2 s2
[1,] -32.02381 2.745581 -1.1293795 0.01918416 1.29468221
[2,] -22.49032 1.891000 -0.5078175 0.01617105 0.27404968
[3,] -21.13986 1.584217 -0.3338892 0.01435332 0.12583532
[4,] -20.71666 1.431079 -0.2482226 0.01293824 0.07455267
[5,] -20.52976 1.339406 -0.1962598 0.01172968 0.05024758
[6,] -20.42730 1.277795 -0.1607251 0.01066757 0.03650013
tail(res2)
elbo h0 m v2 s2
[45,] -20.10397 1.040724 -0.01368997 0.002072247 0.002259663
[46,] -20.10397 1.040723 -0.01368932 0.002072176 0.002259574
[47,] -20.10397 1.040722 -0.01368879 0.002072118 0.002259502
[48,] -20.10397 1.040722 -0.01368837 0.002072072 0.002259443
[49,] -20.10397 1.040721 -0.01368802 0.002072034 0.002259396
[50,] -20.10397 1.040721 -0.01368774 0.002072004 0.002259358
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] survival_3.2-11 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 highr_0.9 pillar_1.6.4 compiler_4.1.1
[5] bslib_0.4.1 later_1.3.0 jquerylib_0.1.4 git2r_0.28.0
[9] tools_4.1.1 digest_0.6.28 lattice_0.20-44 jsonlite_1.7.2
[13] evaluate_0.14 lifecycle_1.0.1 tibble_3.1.5 pkgconfig_2.0.3
[17] rlang_1.0.6 Matrix_1.5-3 cli_3.1.0 rstudioapi_0.13
[21] yaml_2.2.1 xfun_0.27 fastmap_1.1.0 stringr_1.4.0
[25] knitr_1.36 fs_1.5.0 vctrs_0.3.8 sass_0.4.4
[29] grid_4.1.1 rprojroot_2.0.2 glue_1.4.2 R6_2.5.1
[33] fansi_0.5.0 rmarkdown_2.11 magrittr_2.0.1 whisker_0.4
[37] splines_4.1.1 promises_1.2.0.1 ellipsis_0.3.2 htmltools_0.5.2
[41] httpuv_1.6.3 utf8_1.2.2 stringi_1.7.5 cachem_1.0.6
[45] crayon_1.4.1