Last updated: 2023-05-17

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 93f43d6. 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:    data/.DS_Store

Untracked files:
    Untracked:  analysis/ibss_null_model.Rmd
    Untracked:  analysis/poisson_susie.Rmd
    Untracked:  data/dsc3/

Unstaged changes:
    Modified:   analysis/compare_power_fdr.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:   analysis/susie_poor_performance_example.Rmd
    Deleted:    analysis/vi_poisson.Rmd
    Modified:   code/VI_exponential.R
    Modified:   code/vi_poisson.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/check_coxph_fit.Rmd) and HTML (docs/check_coxph_fit.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 93f43d6 yunqiyang0215 2023-05-17 wflow_publish("analysis/check_coxph_fit.Rmd")
html 08361ee yunqiyang0215 2023-05-17 Build site.
Rmd 9655002 yunqiyang0215 2023-05-17 wflow_publish("analysis/check_coxph_fit.Rmd")
html 0373c01 yunqiyang0215 2023-02-13 Build site.
Rmd a865849 yunqiyang0215 2023-02-13 wflow_publish("analysis/check_coxph_fit.Rmd")
html 62ab36f yunqiyang0215 2023-02-13 Build site.
Rmd e3e2352 yunqiyang0215 2023-02-13 wflow_publish("analysis/check_coxph_fit.Rmd")

Description:

check if standardizing will change the coefficient of variables in coxph model. Let’s still use the exponential model from https://yunqiyang0215.github.io/survival-susie/sim_survival.html

The exponential model models the mean of exponential as: \[ \begin{split} E(T_i) &= \mu_i\\ \log\mu_i &= \beta_0 + X\beta \end{split} \] The hazard in exponential model is \(\lambda_i = 1/\mu_i=\frac{1}{\exp\{\beta_0+X\beta\}}=\lambda_0\exp\{X\alpha\}\). Therefore, \(\alpha\) is the output from coxph model and \(\alpha=-\beta\).

Conclusion:

  1. Operations only on x:
  1. Mean center won’t change the coefficient in coxph model.

  2. The coefficient will be multiplied by \(s\) if the variable is divided by \(s\).

  1. Standardize y: the beta estimate is the same as the original data without standardize y.
library(mvtnorm)
library(survival)
# Here we use parametric model to simulate data with survival time,
# assuming survival time is exponentially distributed. 
# We first simulate the mean of exponential from linear combinations
# of variables, and then simulate survival time. 
# T\sim 1/u*exp(-t/u), and the true model is:
# log(T) = \mu + e = b0 + Xb + e
# @param b: vector of length (p+1) for true effect size, include intercept.
# @param X: variable matrix of size n by p. 
# @param status: censoring status. 1 = censored, 2 = event observed. 
sim_dat <- function(b, X){
  n = nrow(X)
  p = ncol(X)
  mu <- exp(cbind(rep(1,n), X) %*% b)
  surT <- rexp(n, rate = 1/mu)
  dat <- data.frame(cbind(surT, X))
  x.name <- unlist(lapply(1:p, function(i) paste0("x", i)))
  names(dat) = c("surT", x.name)
  dat$status <- rep(2, n)
  return(dat)
}
set.seed(1)
n = 200
b = c(1,0.1)
X = as.matrix(rnorm(n, mean = 3, sd = 2))
dat = sim_dat(b, X)

x.c = scale(X, center = TRUE, scale = FALSE)
x.sd = scale(X, center = TRUE, scale = TRUE)
hist(dat$surT, breaks = 20)

Version Author Date
62ab36f yunqiyang0215 2023-02-13

Effect of mean center/standardize X

## Create  survival object. status == 2 is death
dat$y <- with(dat, Surv(surT, status == 2))
# Fit cox ph. Cox ph model with select multiple significant predictors..
cox1 <- coxph(y ~ x1, data =  dat)
cox2 <- coxph(dat$y ~ x.sd)
cox3 <- coxph(dat$y ~ x.c)
coef(cox1)
         x1 
-0.09671461 
coef(cox2)
      x.sd 
-0.1797146 
coef(cox3)
        x.c 
-0.09671461 
summary(cox1)
Call:
coxph(formula = y ~ x1, data = dat)

  n= 200, number of events= 200 

       coef exp(coef) se(coef)      z Pr(>|z|)  
x1 -0.09671   0.90782  0.04239 -2.282   0.0225 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

   exp(coef) exp(-coef) lower .95 upper .95
x1    0.9078      1.102    0.8354    0.9865

Concordance= 0.566  (se = 0.02 )
Likelihood ratio test= 5.27  on 1 df,   p=0.02
Wald test            = 5.21  on 1 df,   p=0.02
Score (logrank) test = 5.21  on 1 df,   p=0.02
summary(cox2)
Call:
coxph(formula = dat$y ~ x.sd)

  n= 200, number of events= 200 

         coef exp(coef) se(coef)      z Pr(>|z|)  
x.sd -0.17971   0.83551  0.07877 -2.282   0.0225 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     exp(coef) exp(-coef) lower .95 upper .95
x.sd    0.8355      1.197     0.716     0.975

Concordance= 0.566  (se = 0.02 )
Likelihood ratio test= 5.27  on 1 df,   p=0.02
Wald test            = 5.21  on 1 df,   p=0.02
Score (logrank) test = 5.21  on 1 df,   p=0.02
summary(cox3)
Call:
coxph(formula = dat$y ~ x.c)

  n= 200, number of events= 200 

        coef exp(coef) se(coef)      z Pr(>|z|)  
x.c -0.09671   0.90782  0.04239 -2.282   0.0225 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

    exp(coef) exp(-coef) lower .95 upper .95
x.c    0.9078      1.102    0.8354    0.9865

Concordance= 0.566  (se = 0.02 )
Likelihood ratio test= 5.27  on 1 df,   p=0.02
Wald test            = 5.21  on 1 df,   p=0.02
Score (logrank) test = 5.21  on 1 df,   p=0.02

Effect of standardize y.

## Create  survival object. status == 2 is death
surT = scale(dat$surT, center = TRUE, scale = TRUE)
status = rep(2, length(surT))
y <- Surv(surT, status)

# Fit cox ph.
cox4 <- coxph(y ~ dat$x1)
summary(cox4)
Call:
coxph(formula = y ~ dat$x1)

  n= 200, number of events= 200 

           coef exp(coef) se(coef)      z Pr(>|z|)  
dat$x1 -0.09671   0.90782  0.04239 -2.282   0.0225 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

       exp(coef) exp(-coef) lower .95 upper .95
dat$x1    0.9078      1.102    0.8354    0.9865

Concordance= 0.566  (se = 0.02 )
Likelihood ratio test= 5.27  on 1 df,   p=0.02
Wald test            = 5.21  on 1 df,   p=0.02
Score (logrank) test = 5.21  on 1 df,   p=0.02

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 mvtnorm_1.1-3   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