Giter Club home page Giter Club logo

ezcox's Introduction

ezcox: Easily Process a Batch of Cox Models

CRAN status Hits R-CMD-check 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 1.0.2
#> 
#> Project home : https://github.com/ShixiangWang/ezcox
#> Documentation: https://shixiangwang.github.io/ezcox
#> Cite as      : arXiv:2110.14232
#> =======================================================================
#> 
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_cont…¹ contr…² ref_l…³ n_con…⁴ n_ref    beta    HR lower…⁵ upper…⁶
#>   <chr>    <lgl>     <chr>   <chr>     <int> <int>   <dbl> <dbl>   <dbl>   <dbl>
#> 1 age      FALSE     age     age         228   228  0.0187 1.02    1       1.04 
#> 2 sex      FALSE     sex     sex         228   228 -0.531  0.588   0.424   0.816
#> 3 ph.ecog  FALSE     ph.ecog ph.ecog     227   227  0.476  1.61    1.29    2.01 
#> # … with 2 more variables: p.value <dbl>, global.pval <dbl>, and abbreviated
#> #   variable names ¹​is_control, ²​contrast_level, ³​ref_level, ⁴​n_contrast,
#> #   ⁵​lower_95, ⁶​upper_95

# 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_cont…¹ contr…² ref_l…³ n_con…⁴ n_ref    beta    HR lower…⁵ upper…⁶
#>   <chr>    <lgl>     <chr>   <chr>     <int> <int>   <dbl> <dbl>   <dbl>   <dbl>
#> 1 sex      FALSE     sex     sex         228   228 -0.513  0.599   0.431   0.831
#> 2 sex      TRUE      age     age         228   228  0.017  1.02    0.999   1.04 
#> 3 ph.ecog  FALSE     ph.ecog ph.ecog     227   227  0.443  1.56    1.24    1.96 
#> 4 ph.ecog  TRUE      age     age         228   228  0.0113 1.01    0.993   1.03 
#> # … with 2 more variables: p.value <dbl>, global.pval <dbl>, and abbreviated
#> #   variable names ¹​is_control, ²​contrast_level, ³​ref_level, ⁴​n_contrast,
#> #   ⁵​lower_95, ⁶​upper_95
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.

ezcox's People

Contributors

olivroy avatar shixiangwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ezcox's Issues

并行计算提升

以当前的 ezcox 为核心,构建一个顶层函数,可以设定批次大小。

并行速度不够快

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倍

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 👀 Watch and Star the repository ShixiangWang/ezcox to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

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 👀 Watch and Star the repository ShixiangWang/ezcox to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

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 👀 Watch and Star the repository ShixiangWang/ezcox to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

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 👀 Watch and Star the repository ShixiangWang/ezcox to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

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

没有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这个函数

建议

诗翔:

我用你的这个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

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.

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 👀 Watch and Star the repository ShixiangWang/ezcox to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.