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
Educational API for 3D Vision using pose to control carton.

Educational API for 3D Vision using pose to control carton.

41 Jul 10, 2022
Unit-Convertor - Unit Convertor Built With Python

Python Unit Converter This project can convert Weigth,length and ... units for y

Mahdis Esmaeelian 1 May 31, 2022
Code and data for the EMNLP 2021 paper "Just Say No: Analyzing the Stance of Neural Dialogue Generation in Offensive Contexts". Coming soon!

ToxiChat Code and data for the EMNLP 2021 paper "Just Say No: Analyzing the Stance of Neural Dialogue Generation in Offensive Contexts". Install depen

Ashutosh Baheti 11 Jan 01, 2023
Gym environments used in the paper: "Developmental Reinforcement Learning of Control Policy of a Quadcopter UAV with Thrust Vectoring Rotors"

gym_multirotor Gym to train reinforcement learning agents on UAV platforms Quadrotor Tiltrotor Requirements This package has been tested on Ubuntu 18.

Aditya M. Deshpande 19 Dec 29, 2022
Multi-Task Learning as a Bargaining Game

Nash-MTL Official implementation of "Multi-Task Learning as a Bargaining Game". Setup environment conda create -n nashmtl python=3.9.7 conda activate

Aviv Navon 87 Dec 26, 2022
Release of SPLASH: Dataset for semantic parse correction with natural language feedback in the context of text-to-SQL parsing

SPLASH: Semantic Parsing with Language Assistance from Humans SPLASH is dataset for the task of semantic parse correction with natural language feedba

Microsoft Research - Language and Information Technologies (MSR LIT) 35 Oct 31, 2022
[CVPR 2022 Oral] Crafting Better Contrastive Views for Siamese Representation Learning

Crafting Better Contrastive Views for Siamese Representation Learning (CVPR 2022 Oral) 2022-03-29: The paper was selected as a CVPR 2022 Oral paper! 2

249 Dec 28, 2022
Train a deep learning net with OpenStreetMap features and satellite imagery.

DeepOSM Classify roads and features in satellite imagery, by training neural networks with OpenStreetMap (OSM) data. DeepOSM can: Download a chunk of

TrailBehind, Inc. 1.3k Nov 24, 2022
PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation

PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation Created by Charles R. Qi, Hao Su, Kaichun Mo, Leonidas J. Guibas from Sta

Charles R. Qi 4k Dec 30, 2022
Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization

This project is now archived. It's been fun working on it, but it's time for me to move on. Thank you for all the support and feedback over the last c

Max Pumperla 2.1k Jan 03, 2023
A Decentralized Omnidirectional Visual-Inertial-UWB State Estimation System for Aerial Swar.

Omni-swarm A Decentralized Omnidirectional Visual-Inertial-UWB State Estimation System for Aerial Swarm Introduction Omni-swarm is a decentralized omn

HKUST Aerial Robotics Group 99 Dec 23, 2022
Udacity's CS101: Intro to Computer Science - Building a Search Engine

Udacity's CS101: Intro to Computer Science - Building a Search Engine All soluti

Phillip 0 Feb 26, 2022
Code for Paper: Self-supervised Learning of Motion Capture

Self-supervised Learning of Motion Capture This is code for the paper: Hsiao-Yu Fish Tung, Hsiao-Wei Tung, Ersin Yumer, Katerina Fragkiadaki, Self-sup

Hsiao-Yu Fish Tung 87 Jul 25, 2022
ConformalLayers: A non-linear sequential neural network with associative layers

ConformalLayers: A non-linear sequential neural network with associative layers ConformalLayers is a conformal embedding of sequential layers of Convo

Prograf-UFF 5 Sep 28, 2022
Tools for manipulating UVs in the Blender viewport.

UV Tool Suite for Blender A set of tools to make editing UVs easier in Blender. These tools can be accessed wither through the Kitfox - UV panel on th

35 Oct 29, 2022
Workshop Materials Delivered on 28/02/2022

intro-to-cnn-p1 Repo for hosting workshop materials delivered on 28/02/2022 Questions you will answer in this workshop Learning Objectives What are co

Beginners Machine Learning 5 Feb 28, 2022
This repository provides some of the code implemented and the data used for the work proposed in "A Cluster-Based Trip Prediction Graph Neural Network Model for Bike Sharing Systems".

cluster-link-prediction This repository provides some of the code implemented and the data used for the work proposed in "A Cluster-Based Trip Predict

Bárbara 0 Dec 28, 2022
Official implementation for ICDAR 2021 paper "Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer"

Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer Description Convert offline handwritten mathematical expressi

Wenqi Zhao 87 Dec 27, 2022
VIsually-Pivoted Audio and(N) Text

VIP-ANT: VIsually-Pivoted Audio and(N) Text Code for the paper Connecting the Dots between Audio and Text without Parallel Data through Visual Knowled

Yän.PnG 16 Nov 04, 2022