Title: | Easily Process a Batch of Cox Models |
---|---|
Description: | A tool to operate a batch of univariate or multivariate Cox models and return tidy result. |
Authors: | Shixiang Wang [aut, cre] |
Maintainer: | Shixiang Wang <[email protected]> |
License: | GPL-3 |
Version: | 1.0.4 |
Built: | 2024-08-20 02:29:18 UTC |
Source: | https://github.com/ShixiangWang/ezcox |
Clean ezcox Model File Directory
clean_model_dir(model_dir = file.path(tempdir(), "ezcox"))
clean_model_dir(model_dir = file.path(tempdir(), "ezcox"))
model_dir |
a path for storing model results. |
nothing
clean_model_dir()
clean_model_dir()
Run Cox Analysis in Batch Mode
ezcox( data, covariates, controls = NULL, time = "time", status = "status", global_method = c("likelihood", "wald", "logrank"), keep_models = FALSE, return_models = FALSE, model_dir = file.path(tempdir(), "ezcox"), verbose = TRUE, ... )
ezcox( data, covariates, controls = NULL, time = "time", status = "status", global_method = c("likelihood", "wald", "logrank"), keep_models = FALSE, return_models = FALSE, model_dir = file.path(tempdir(), "ezcox"), verbose = TRUE, ... )
data |
a |
covariates |
column names specifying variables. |
controls |
column names specifying controls.
The names with pattern "*:|()" will be treated as interaction/combination
term, please make sure all column names in |
time |
column name specifying time, default is 'time'. |
status |
column name specifying event status, default is 'status'. |
global_method |
method used to obtain global p value for cox model, should be one of "likelihood", "wald", "logrank". The likelihood-ratio test, Wald test, and score logrank statistics. These three methods are asymptotically equivalent. For large enough N, they will give similar results. For small N, they may differ somewhat. The Likelihood ratio test has better behavior for small sample sizes, so it is generally preferred. |
keep_models |
If |
return_models |
default |
model_dir |
a path for storing model results. |
verbose |
if |
... |
other parameters passing to |
a ezcox
object
Shixiang Wang [email protected]
library(survival) # Build unvariable models t1 <- ezcox(lung, covariates = c("age", "sex", "ph.ecog")) t1 # Build multi-variable models # Control variable 'age' t2 <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age") t2 # Return models t3 <- ezcox(lung, covariates = c("age", "sex", "ph.ecog"), return_models = TRUE ) t3 t4 <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE ) t4
library(survival) # Build unvariable models t1 <- ezcox(lung, covariates = c("age", "sex", "ph.ecog")) t1 # Build multi-variable models # Control variable 'age' t2 <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age") t2 # Return models t3 <- ezcox(lung, covariates = c("age", "sex", "ph.ecog"), return_models = TRUE ) t3 t4 <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE ) t4
Group Cox Analysis and Visualization
ezcox_group( data, grp_var, covariate, controls = NULL, time = "time", status = "status", sort = FALSE, decreasing = TRUE, add_all = FALSE, add_caption = TRUE, verbose = TRUE, headings = list(variable = "Group", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), ... )
ezcox_group( data, grp_var, covariate, controls = NULL, time = "time", status = "status", sort = FALSE, decreasing = TRUE, add_all = FALSE, add_caption = TRUE, verbose = TRUE, headings = list(variable = "Group", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), ... )
data |
a |
grp_var |
a group column. |
covariate |
a covariable for cox analysis. |
controls |
column names specifying controls.
The names with pattern "*:|()" will be treated as interaction/combination
term, please make sure all column names in |
time |
column name specifying time, default is 'time'. |
status |
column name specifying event status, default is 'status'. |
sort |
if |
decreasing |
logical, should the sort order be increasing or decreasing? |
add_all |
if |
add_caption |
if |
verbose |
if |
headings |
a |
... |
other arguments passing to |
a list
.
library(survival) ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog") ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog", controls = "age") p <- ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog", controls = "age", add_all = TRUE )
library(survival) ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog") ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog", controls = "age") p <- ezcox_group(lung, grp_var = "sex", covariate = "ph.ecog", controls = "age", add_all = TRUE )
Parallelly Run Cox Analysis in Batch Mode
ezcox_parallel( data, covariates, controls = NULL, time = "time", status = "status", batch_size = 100, global_method = c("likelihood", "wald", "logrank"), keep_models = FALSE, return_models = FALSE, model_dir = file.path(tempdir(), "ezcox"), parallel = TRUE, verbose = FALSE )
ezcox_parallel( data, covariates, controls = NULL, time = "time", status = "status", batch_size = 100, global_method = c("likelihood", "wald", "logrank"), keep_models = FALSE, return_models = FALSE, model_dir = file.path(tempdir(), "ezcox"), parallel = TRUE, verbose = FALSE )
data |
a |
covariates |
column names specifying variables. |
controls |
column names specifying controls. |
time |
column name specifying time, default is 'time'. |
status |
column name specifying event status, default is 'status'. |
batch_size |
processing size in a batch. |
global_method |
method used to obtain global p value for cox model, should be one of "likelihood", "wald", "logrank". The likelihood-ratio test, Wald test, and score logrank statistics. These three methods are asymptotically equivalent. For large enough N, they will give similar results. For small N, they may differ somewhat. The Likelihood ratio test has better behavior for small sample sizes, so it is generally preferred. |
keep_models |
If |
return_models |
default |
model_dir |
a path for storing model results. |
parallel |
if |
verbose |
if |
a ezcox
object
Shixiang Wang [email protected]
library(survival) t <- ezcox_parallel(lung, covariates = c("sex", "ph.ecog"), controls = "age") t
library(survival) t <- ezcox_parallel(lung, covariates = c("sex", "ph.ecog"), controls = "age") t
Filter ezcox
filter_ezcox(x, levels = "auto", type = c("both", "contrast", "ref"))
filter_ezcox(x, levels = "auto", type = c("both", "contrast", "ref"))
x |
a |
levels |
levels to filter, default is 'auto', it will filter all control variables. |
type |
default is 'both' for filtering both contrast level and reference level. It can also be 'contrast' for filtering only contrast level and 'ref' for filtering only reference level. |
a ezcox
object
Shixiang Wang [email protected]
library(survival) lung$ph.ecog <- factor(lung$ph.ecog) zz <- ezcox(lung, covariates = c("sex", "age"), controls = "ph.ecog") zz filter_ezcox(zz) filter_ezcox(zz, c("0", "2")) filter_ezcox(zz, c("0", "2"), type = "contrast") t <- filter_ezcox(zz, c("0", "2"), type = "ref") t
library(survival) lung$ph.ecog <- factor(lung$ph.ecog) zz <- ezcox(lung, covariates = c("sex", "age"), controls = "ph.ecog") zz filter_ezcox(zz) filter_ezcox(zz, c("0", "2")) filter_ezcox(zz, c("0", "2"), type = "contrast") t <- filter_ezcox(zz, c("0", "2"), type = "ref") t
Create a forest plot for simple data
forester( data, display_cols = c("Variable", "HR", "lower_95", "upper_95"), estimate_precision = 2, null_line_at = 1, font_family = "mono", x_scale_linear = TRUE, xlim = NULL, xbreaks = NULL, point_sizes = 3, point_shape = 16, label_hjust = 0, label_vjust = -1, label_color = "blue", label_size = 3 )
forester( data, display_cols = c("Variable", "HR", "lower_95", "upper_95"), estimate_precision = 2, null_line_at = 1, font_family = "mono", x_scale_linear = TRUE, xlim = NULL, xbreaks = NULL, point_sizes = 3, point_shape = 16, label_hjust = 0, label_vjust = -1, label_color = "blue", label_size = 3 )
data |
Data frame (required). The information to be displayed as the forest plot. |
display_cols |
4 columns stand for axis text and the forest data,
default using |
estimate_precision |
Integer. The number of decimal places on the estimate (default 2). |
null_line_at |
Numeric. Default 0. Change to 1 if using relative measures such as OR, RR. |
font_family |
String. The font to use for the ggplot. Default "mono". |
x_scale_linear |
Logical. Default TRUE, change to FALSE for log scale |
xlim |
Vector. Manually specify limits for the x axis as a vector length 2, i.e. c(low, high) |
xbreaks |
Vector. X axis breaks to label. Specify limits in xlim if using this option. |
point_sizes |
Vector. Length should be equal to 1 or nrow(left_side_data). The sizes of the points in the center plot, where 3.25 is the default. |
point_shape |
Vector. Length should be equal to 1 or nrow(left_side_data). The shapes of the points in the center plot, where 16 (a filled circle) is the default. |
label_hjust , label_vjust , label_color , label_size
|
hjust, vjust color and size for the label text. |
a ggplot
object.
library(survival) t1 <- ezcox(lung, covariates = c( "age", "sex", "ph.karno", "pat.karno" )) p <- forester(t1, xlim = c(0, 1.5)) p p2 <- forester(t1, xlim = c(0.5, 1.5)) p2
library(survival) t1 <- ezcox(lung, covariates = c( "age", "sex", "ph.karno", "pat.karno" )) p <- forester(t1, xlim = c(0, 1.5)) p p2 <- forester(t1, xlim = c(0.5, 1.5)) p2
Models are renamed by the formulas.
get_models(x, variables = NULL)
get_models(x, variables = NULL)
x |
a |
variables |
a character vector representing variables to select. |
a named list
with class ezcox_models
library(survival) zz <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE) mds <- get_models(zz) str(mds, max.level = 1)
library(survival) zz <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE) mds <- get_models(zz) str(mds, max.level = 1)
This is a wrapper of function ezcox, get_models and show_models. It focus on generating forest plot easily and flexibly.
show_forest( data, covariates, controls = NULL, time = "time", status = "status", merge_models = FALSE, model_names = NULL, vars_to_show = NULL, drop_controls = FALSE, add_caption = TRUE, point_size = 3, point_shape = 15, color = "red", banded = TRUE, headings = list(variable = "Variable", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), model_dir = file.path(tempdir(), "ezcox"), verbose = TRUE, ... )
show_forest( data, covariates, controls = NULL, time = "time", status = "status", merge_models = FALSE, model_names = NULL, vars_to_show = NULL, drop_controls = FALSE, add_caption = TRUE, point_size = 3, point_shape = 15, color = "red", banded = TRUE, headings = list(variable = "Variable", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), model_dir = file.path(tempdir(), "ezcox"), verbose = TRUE, ... )
data |
a |
covariates |
a character vector optionally listing the variables to include in the plot (defaults to all variables). |
controls |
column names specifying controls.
The names with pattern "*:|()" will be treated as interaction/combination
term, please make sure all column names in |
time |
column name specifying time, default is 'time'. |
status |
column name specifying event status, default is 'status'. |
merge_models |
if 'TRUE', merge all models and keep the plot tight. |
model_names |
model names to show when |
vars_to_show |
default is |
drop_controls |
works when |
add_caption |
if |
point_size |
size of point. |
point_shape |
shape value of point. |
color |
color for point and segment. |
banded |
if |
headings |
a |
model_dir |
a path for storing model results. |
verbose |
if |
... |
other arguments passing to |
a ggplot
object
library(survival) show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age") show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE) show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE, drop_controls = TRUE ) p <- show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE, vars_to_show = "sex" ) p
library(survival) show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age") show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE) show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE, drop_controls = TRUE ) p <- show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE, vars_to_show = "sex" ) p
Show Cox Models
show_models( models, model_names = NULL, covariates = NULL, merge_models = FALSE, drop_controls = FALSE, headings = list(variable = "Variable", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), ... )
show_models( models, model_names = NULL, covariates = NULL, merge_models = FALSE, drop_controls = FALSE, headings = list(variable = "Variable", n = "N", measure = "Hazard ratio", ci = NULL, p = "p"), ... )
models |
a |
model_names |
model names to show when |
covariates |
a character vector optionally listing the variables to include in the plot (defaults to all variables). |
merge_models |
if 'TRUE', merge all models and keep the plot tight. |
drop_controls |
works when |
headings |
a |
... |
other arguments passing to |
a ggplot
object
library(survival) zz <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE) mds <- get_models(zz) show_models(mds) show_models(mds, model_names = paste0("Model ", 1:2)) show_models(mds, covariates = c("sex", "ph.ecog")) show_models(mds, drop_controls = TRUE) show_models(mds, merge_models = TRUE) p <- show_models(mds, merge_models = TRUE, drop_controls = TRUE) p
library(survival) zz <- ezcox(lung, covariates = c("sex", "ph.ecog"), controls = "age", return_models = TRUE) mds <- get_models(zz) show_models(mds) show_models(mds, model_names = paste0("Model ", 1:2)) show_models(mds, covariates = c("sex", "ph.ecog")) show_models(mds, drop_controls = TRUE) show_models(mds, merge_models = TRUE) p <- show_models(mds, merge_models = TRUE, drop_controls = TRUE) p