Easily Process a Batch of Cox Models

Overview

ezcox: Easily Process a Batch of Cox Models

CRAN status Hits R-CMD-check Codecov test coverage Lifecycle: stable

The goal of ezcox is to operate a batch of univariate or multivariate Cox models and return tidy result.

Installation

You can install the released version of ezcox from CRAN with:

install.packages("ezcox")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("ShixiangWang/ezcox")

It is possible to install ezcox from Conda conda-forge channel:

conda install r-ezcox --channel conda-forge

Visualization feature of ezcox needs the recent version of forestmodel, please run the following commands:

remotes::install_github("ShixiangWang/forestmodel")

🔰 Example

This is a basic example which shows you how to get result from a batch of cox models.

library(ezcox)
#> Welcome to 'ezcox' package!
#> =======================================================================
#> You are using ezcox version 0.8.1
#> 
#> Github page  : https://github.com/ShixiangWang/ezcox
#> Documentation: https://shixiangwang.github.io/ezcox/articles/ezcox.html
#> 
#> Run citation("ezcox") to see how to cite 'ezcox'.
#> =======================================================================
#> 
library(survival)

# Build unvariable models
ezcox(lung, covariates = c("age", "sex", "ph.ecog"))
#> => Processing variable age
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> => Processing variable sex
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> => Processing variable ph.ecog
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> # A tibble: 3 × 12
#>   Variable is_control contrast_level ref_level n_contrast n_ref    beta    HR
#>   <chr>    <lgl>      <chr>          <chr>          <int> <int>   <dbl> <dbl>
#> 1 age      FALSE      age            age              228   228  0.0187 1.02 
#> 2 sex      FALSE      sex            sex              228   228 -0.531  0.588
#> 3 ph.ecog  FALSE      ph.ecog        ph.ecog          227   227  0.476  1.61 
#> # … with 4 more variables: lower_95 <dbl>, upper_95 <dbl>, p.value <dbl>,
#> #   global.pval <dbl>

# Build multi-variable models
# Control variable 'age'
ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age")
#> => Processing variable sex
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> => Processing variable ph.ecog
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> # A tibble: 4 × 12
#>   Variable is_control contrast_level ref_level n_contrast n_ref    beta    HR
#>   <chr>    <lgl>      <chr>          <chr>          <int> <int>   <dbl> <dbl>
#> 1 sex      FALSE      sex            sex              228   228 -0.513  0.599
#> 2 sex      TRUE       age            age              228   228  0.017  1.02 
#> 3 ph.ecog  FALSE      ph.ecog        ph.ecog          227   227  0.443  1.56 
#> 4 ph.ecog  TRUE       age            age              228   228  0.0113 1.01 
#> # … with 4 more variables: lower_95 <dbl>, upper_95 <dbl>, p.value <dbl>,
#> #   global.pval <dbl>
lung$ph.ecog = factor(lung$ph.ecog)
zz = ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models=TRUE)
#> => Processing variable sex
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
#> => Processing variable ph.ecog
#> ==> Building Surv object...
#> ==> Building Cox model...
#> ==> Done.
mds = get_models(zz)
str(mds, max.level = 1)
#> List of 2
#>  $ Surv ~ sex + age    :List of 19
#>   ..- attr(*, "class")= chr "coxph"
#>   ..- attr(*, "Variable")= chr "sex"
#>  $ Surv ~ ph.ecog + age:List of 22
#>   ..- attr(*, "class")= chr "coxph"
#>   ..- attr(*, "Variable")= chr "ph.ecog"
#>  - attr(*, "class")= chr [1:2] "ezcox_models" "list"
#>  - attr(*, "has_control")= logi TRUE

show_models(mds)

🌟 Vignettes

📃 Citation

If you are using it in academic research, please cite the preprint arXiv:2110.14232 along with URL of this repo.

Comments
  • Fast way to add interaction terms?

    Fast way to add interaction terms?

    Hi, just wondering how the the interaction terms can be handled as "controls" here. Any way to add them rather than manually create new 'interaction variables' in the data? Cheers.

    opened by lijing-lin 12
  • similar tools or approach

    similar tools or approach

    • https://github.com/kevinblighe/RegParallel https://bioconductor.org/packages/release/data/experiment/vignettes/RegParallel/inst/doc/RegParallel.html
    • https://pubmed.ncbi.nlm.nih.gov/25769333/
    opened by ShixiangWang 12
  • 没有show-models这个函数

    没有show-models这个函数

    install.packages("ezcox")#先安装包 packageVersion("ezcox")#0.4.0版本 library(survival) library(ezcox) library("devtools") install.packages("devtools") devtools::install_github("ShixiangWang/ezcox") lung$ph.ecog <- factor(lung$ph.ecog) zz <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE) zz mds <- get_models(zz) str(mds, max.level = 1) install.packages("forestmodel") library("forestmodel") show_models(mds) 问题是没有show-models这个函数

    opened by demi0304 4
  • 并行速度不够快

    并行速度不够快

    library(survival)
    ### write a function
    fastcox_single <- function(num){
      data= cbind(clin,expreset[,num])
      UniNames <- colnames(data)[-c(1:2)]
      do.call(rbind,lapply(UniNames,function(i){
        surv =as.formula(paste('Surv(times, status)~',i))
        cur_cox=coxph(surv, data = data)
        x = summary(cur_cox)
        HR=x$coefficients[i,"exp(coef)"]
        HR.confint.lower = signif(x$conf.int[i,"lower .95"],3)
        HR.confint.upper = signif(x$conf.int[i,"upper .95"],3)
        CI <- paste0("(",HR.confint.lower, "-",HR.confint.upper,")")
        p.value=x$coef[i,"Pr(>|z|)"]
        data.frame(gene=i,HR=HR,CI=CI,p.value=p.value)
      }))
    }
    
    
    clin = share.data[,1:2]
    expreset = share.data[,-c(1:2)]
    length = ncol(expreset)
    groupdf = data.frame(colnuber = seq(1,length),
                         group = rep(1:ceiling(length/100),each=100,length.out=length))
    index = split(groupdf$colnuber,groupdf$group)
    library(future.apply)
    # options(future.globals.maxSize= 891289600)
    plan(multiprocess)
    share.data.os.result=do.call(rbind,future_lapply(index,fastcox_single))
    
    
    #=== Use ezcox
    # devtools::install_github("ShixiangWang/ezcox")
    res = ezcox::ezcox(share.data, covariates = colnames(share.data)[-(1:2)], parallel = TRUE, time = "times")
    
    
    share.data$VIM.INHBE
    tt = ezcox::ezcox(share.data, covariates = "VIM.INHBE", return_models = T, time = "times")
    
    
    
    

    大批量计算时两者时间差4倍

    enhancement 
    opened by ShixiangWang 3
  • 建议

    建议

    诗翔:

    我用你的这个R包,有两个建议,你可以改进一下:

    1. 对covariates的顺序,按照用户给的顺序进行展示,现在是按照字符的大小排序的。
    2. 对HR太大的值,使用科学记数法进行展示

    这个是用的代码

    zz = ezcox(
      scores.combined,
      covariates = c("JSI", "Tindex", "Subclonal_Aca", "Subclonal_Nec", "ITH_Aca", "ITH_Nec"),
      controls = "Age",
      time = "Survival_months",
      status = "Death",
      return_models = TRUE
    )
    
    mds = get_models(zz)
    
    show_models(mds, drop_controls = TRUE)
    
    

    这个是现在的图

    image

    opened by qingjian1991 2
  • Change format setting including text size

    Change format setting including text size

    See

    library(survival)
    library(forestmodel)
    library(ezcox)
    show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", format_options = forest_model_format_options(text_size = 3))
    

    image

    opened by ShixiangWang 0
  • Weekly Digest (22 September, 2019 - 29 September, 2019)

    Weekly Digest (22 September, 2019 - 29 September, 2019)

    Here's the Weekly Digest for ShixiangWang/ezcox:


    ISSUES

    Last week, no issues were created.


    PULL REQUESTS

    Last week, no pull requests were created, updated or merged.


    COMMITS

    Last week there were no commits.


    CONTRIBUTORS

    Last week there were no contributors.


    STARGAZERS

    Last week there were no stargazers.


    RELEASES

    Last week there were no releases.


    That's all for last week, please :eyes: Watch and :star: Star the repository ShixiangWang/ezcox to receive next weekly updates. :smiley:

    You can also view all Weekly Digests by clicking here.

    Your Weekly Digest bot. :calendar:

    opened by weekly-digest[bot] 0
  • Weekly Digest (15 September, 2019 - 22 September, 2019)

    Weekly Digest (15 September, 2019 - 22 September, 2019)

    Here's the Weekly Digest for ShixiangWang/ezcox:


    ISSUES

    Last week, no issues were created.


    PULL REQUESTS

    Last week, no pull requests were created, updated or merged.


    COMMITS

    Last week there were no commits.


    CONTRIBUTORS

    Last week there were no contributors.


    STARGAZERS

    Last week there were no stargazers.


    RELEASES

    Last week there were no releases.


    That's all for last week, please :eyes: Watch and :star: Star the repository ShixiangWang/ezcox to receive next weekly updates. :smiley:

    You can also view all Weekly Digests by clicking here.

    Your Weekly Digest bot. :calendar:

    weekly-digest 
    opened by weekly-digest[bot] 0
  • Weekly Digest (8 September, 2019 - 15 September, 2019)

    Weekly Digest (8 September, 2019 - 15 September, 2019)

    Here's the Weekly Digest for ShixiangWang/ezcox:


    ISSUES

    Last week, no issues were created.


    PULL REQUESTS

    Last week, no pull requests were created, updated or merged.


    COMMITS

    Last week there were no commits.


    CONTRIBUTORS

    Last week there were no contributors.


    STARGAZERS

    Last week there were no stargazers.


    RELEASES

    Last week there were no releases.


    That's all for last week, please :eyes: Watch and :star: Star the repository ShixiangWang/ezcox to receive next weekly updates. :smiley:

    You can also view all Weekly Digests by clicking here.

    Your Weekly Digest bot. :calendar:

    weekly-digest 
    opened by weekly-digest[bot] 0
  • Weekly Digest (1 September, 2019 - 8 September, 2019)

    Weekly Digest (1 September, 2019 - 8 September, 2019)

    Here's the Weekly Digest for ShixiangWang/ezcox:


    ISSUES

    Last week, no issues were created.


    PULL REQUESTS

    Last week, no pull requests were created, updated or merged.


    COMMITS

    Last week there were no commits.


    CONTRIBUTORS

    Last week there were no contributors.


    STARGAZERS

    Last week there were no stargazers.


    RELEASES

    Last week there were no releases.


    That's all for last week, please :eyes: Watch and :star: Star the repository ShixiangWang/ezcox to receive next weekly updates. :smiley:

    You can also view all Weekly Digests by clicking here.

    Your Weekly Digest bot. :calendar:

    weekly-digest 
    opened by weekly-digest[bot] 0
  • Weekly Digest (28 August, 2019 - 4 September, 2019)

    Weekly Digest (28 August, 2019 - 4 September, 2019)

    Here's the Weekly Digest for ShixiangWang/ezcox:


    ISSUES

    Last week, no issues were created.


    PULL REQUESTS

    Last week, no pull requests were created, updated or merged.


    COMMITS

    Last week there were no commits.


    CONTRIBUTORS

    Last week there were no contributors.


    STARGAZERS

    Last week there were no stargazers.


    RELEASES

    Last week there were no releases.


    That's all for last week, please :eyes: Watch and :star: Star the repository ShixiangWang/ezcox to receive next weekly updates. :smiley:

    You can also view all Weekly Digests by clicking here.

    Your Weekly Digest bot. :calendar:

    weekly-digest 
    opened by weekly-digest[bot] 0
Releases(v1.0.1)
Owner
Shixiang Wang
Don't Program by Coincidence.
Shixiang Wang
Node-level Graph Regression with Deep Gaussian Process Models

Node-level Graph Regression with Deep Gaussian Process Models Prerequests our implementation is mainly based on tensorflow 1.x and gpflow 1.x: python

null 1 Jan 16, 2022
This repository contains the data and code for the paper "Diverse Text Generation via Variational Encoder-Decoder Models with Gaussian Process Priors" (SPNLP@ACL2022)

GP-VAE This repository provides datasets and code for preprocessing, training and testing models for the paper: Diverse Text Generation via Variationa

Wanyu Du 18 Dec 29, 2022
Aiming at the common training datsets split, spectrum preprocessing, wavelength select and calibration models algorithm involved in the spectral analysis process

Aiming at the common training datsets split, spectrum preprocessing, wavelength select and calibration models algorithm involved in the spectral analysis process, a complete algorithm library is established, which is named opensa (openspectrum analysis).

Fu Pengyou 50 Jan 7, 2023
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.

Yolov5 running on TorchServe (GPU compatible) ! This is a dockerfile to run TorchServe for Yolo v5 object detection model. (TorchServe (PyTorch librar

null 82 Nov 29, 2022
[ICLR'21] FedBN: Federated Learning on Non-IID Features via Local Batch Normalization

FedBN: Federated Learning on Non-IID Features via Local Batch Normalization This is the PyTorch implemention of our paper FedBN: Federated Learning on

Med-AIR@CUHK 156 Dec 15, 2022
The official repo of the CVPR2021 oral paper: Representative Batch Normalization with Feature Calibration

Representative Batch Normalization (RBN) with Feature Calibration The official implementation of the CVPR2021 oral paper: Representative Batch Normali

Open source projects of ShangHua-Gao 76 Nov 9, 2022
[CVPRW 21] "BNN - BN = ? Training Binary Neural Networks without Batch Normalization", Tianlong Chen, Zhenyu Zhang, Xu Ouyang, Zechun Liu, Zhiqiang Shen, Zhangyang Wang

BNN - BN = ? Training Binary Neural Networks without Batch Normalization Codes for this paper BNN - BN = ? Training Binary Neural Networks without Bat

VITA 40 Dec 30, 2022
Custom TensorFlow2 implementations of forward and backward computation of soft-DTW algorithm in batch mode.

Batch Soft-DTW(Dynamic Time Warping) in TensorFlow2 including forward and backward computation Custom TensorFlow2 implementations of forward and backw

null 19 Aug 30, 2022
Run Effective Large Batch Contrastive Learning on Limited Memory GPU

Gradient Cache Gradient Cache is a simple technique for unlimitedly scaling contrastive learning batch far beyond GPU memory constraint. This means tr

Luyu Gao 198 Dec 29, 2022
Code used to generate the results appearing in "Train longer, generalize better: closing the generalization gap in large batch training of neural networks"

Train longer, generalize better - Big batch training This is a code repository used to generate the results appearing in "Train longer, generalize bet

Elad Hoffer 145 Sep 16, 2022
Code for "On the Effects of Batch and Weight Normalization in Generative Adversarial Networks"

Note: this repo has been discontinued, please check code for newer version of the paper here Weight Normalized GAN Code for the paper "On the Effects

Sitao Xiang 182 Sep 6, 2021
SpecAugmentPyTorch - A Pytorch (support batch and channel) implementation of GoogleBrain's SpecAugment: A Simple Data Augmentation Method for Automatic Speech Recognition

SpecAugment An implementation of SpecAugment for Pytorch How to use Install pytorch, version>=1.9.0 (new feature (torch.Tensor.take_along_dim) is used

IMLHF 3 Oct 11, 2022
Code of 3D Shape Variational Autoencoder Latent Disentanglement via Mini-Batch Feature Swapping for Bodies and Faces

3D Shape Variational Autoencoder Latent Disentanglement via Mini-Batch Feature Swapping for Bodies and Faces Installation After cloning the repo open

null 37 Dec 3, 2022
Contrastive Learning Inverts the Data Generating Process

Official code to reproduce the results and data presented in the paper Contrastive Learning Inverts the Data Generating Process.

null 71 Nov 25, 2022
A bare-bones TensorFlow framework for Bayesian deep learning and Gaussian process approximation

Aboleth A bare-bones TensorFlow framework for Bayesian deep learning and Gaussian process approximation [1] with stochastic gradient variational Bayes

Gradient Institute 127 Dec 12, 2022
Newt - a Gaussian process library in JAX.

Newt __ \/_ (' \`\ _\, \ \\/ /`\/\ \\ \ \\

AaltoML 0 Nov 2, 2021
Code for Transformer Hawkes Process, ICML 2020.

Transformer Hawkes Process Source code for Transformer Hawkes Process (ICML 2020). Run the code Dependencies Python 3.7. Anaconda contains all the req

Simiao Zuo 111 Dec 26, 2022
Multi-Output Gaussian Process Toolkit

Multi-Output Gaussian Process Toolkit Paper - API Documentation - Tutorials & Examples The Multi-Output Gaussian Process Toolkit is a Python toolkit f

GAMES 113 Nov 25, 2022