Title: | High-Level Interface for Survival Analysis and Associated Plots |
---|---|
Description: | A high-level interface to perform survival analysis, including Kaplan-Meier analysis and log-rank tests and Cox regression. Aims at providing a clear and elegant syntax, support for use in a pipeline, structured output and plotting. Builds upon the 'survminer' package for Kaplan-Meier plots and provides a customizable implementation for forest plots. Kaplan & Meier (1958) <doi:10.1080/01621459.1958.10501452> Cox (1972) <JSTOR:2985181> Peto & Peto (1972) <JSTOR:2344317>. |
Authors: | Marcel Wiesweg [aut, cre] |
Maintainer: | Marcel Wiesweg <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2024-12-04 07:29:42 UTC |
Source: | CRAN |
Performs Cox regression on right-censored data using a multiple covariates.
analyse_multivariate( data, time_status, covariates, strata = NULL, covariate_name_dict = NULL, covariate_label_dict = NULL, reference_level_dict = NULL, sort_frame_by = vars(HR) ) analyze_multivariate( data, time_status, covariates, strata = NULL, covariate_name_dict = NULL, covariate_label_dict = NULL, reference_level_dict = NULL, sort_frame_by = vars(HR) )
analyse_multivariate( data, time_status, covariates, strata = NULL, covariate_name_dict = NULL, covariate_label_dict = NULL, reference_level_dict = NULL, sort_frame_by = vars(HR) ) analyze_multivariate( data, time_status, covariates, strata = NULL, covariate_name_dict = NULL, covariate_label_dict = NULL, reference_level_dict = NULL, sort_frame_by = vars(HR) )
data |
A data frame containing the time/status information and, if used, the covariate. |
time_status |
A vector of length 2 giving the time and status fields.
It is recommended to use vars() and symbolic column names or code that is tidily-evaluated on |
covariates |
The covariates.
Pass symbolic columns names or code that is tidily-evaluated on |
strata |
Strata (optional). Same format as covariates. For each strata level (if multiple fields, unique combinations of levels) a separate baseline hazard is fit. |
covariate_name_dict |
A dictionary (named list or vector) of old->new covariate names |
covariate_label_dict |
A dictionary (named list or vector) of old->new covariate value level labels |
reference_level_dict |
For categorical variables, the Cox regression uses pseudo variables for each level
relative to a reference category, resulting in n-1 variables for n levels of a categorical covariate.
Hazard ratios will be relative to the reference level, which is defined as having hazard ratio 1.0.
Per default, the reference level is the first factor level.
You can specify a different level by passing a named vector: factor name -> value of reference level.
Note that this is independent of covariate_label_dict, i.e. specify the factor level as it is in |
sort_frame_by |
A vars() list of one or more symbolic column names.
The result contains a data frame of the cox regression results ( |
This method builds upon the survival
package and returns a comprehensive result object
for survival analysis containing the coxph results.
A format
/print
method is provided that prints the essential statistics.
An object of class "SurvivalAnalysisResult" and "SurvivalAnalysisMultivariateResult".
You can use this result as a black box for further functions in this package,
format
or
print
it,
retrieve information as a data frame via multivariate_as_data_frame
or
access individual pieces via pluck_multivariate_analysis
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% print()
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% print()
Performs survival analysis on right-censored data using a single covariate, or no covariate.
analyse_survival( data, time_status, by, by_label_map = NULL, by_order_vector = NULL, cox_reference_level = NULL, p_adjust_method = "none", plot_args = list() ) analyze_survival( data, time_status, by, by_label_map = NULL, by_order_vector = NULL, cox_reference_level = NULL, p_adjust_method = "none", plot_args = list() )
analyse_survival( data, time_status, by, by_label_map = NULL, by_order_vector = NULL, cox_reference_level = NULL, p_adjust_method = "none", plot_args = list() ) analyze_survival( data, time_status, by, by_label_map = NULL, by_order_vector = NULL, cox_reference_level = NULL, p_adjust_method = "none", plot_args = list() )
data |
A data frame containing the time/status information and, if used, the covariate. |
time_status |
A vector of length 2 giving the time and status fields.
It is recommended to use vars() and symbolic column names or code that is tidily-evaluated on |
by |
The term by which survival curves will be separated.
Pass |
by_label_map |
A dictionary (named list or vector) of old->new labels of the factor created using |
by_order_vector |
A vector of the labels of the factor created using |
cox_reference_level |
The result will include a univariate Cox regression. Use this parameter to specify
the level of the factor generated using |
p_adjust_method |
If there are more than two levels in the |
plot_args |
Named list of arguments that will be stored for later use in plotting methods, such as kaplan_meier_plot. There they will take precedence over arguments given to that method. This is useful when plotting multiple results with a set of default arguments, of which some such as title or axis scale differ per-plot. |
This method builds upon the survival
package and returns a comprehensive result object
for survival analysis containing the survfit, survdiff and coxph results.
A format
/print
method is provided that prints the essential statistics.
Kaplan-Meier plots are readily generated using the kaplan_meier_plot
or
kaplan_meier_grid
functions.
An object of class "SurvivalAnalysisResult" and "SurvivalAnalysisUnivariateResult".
You can use this result as a black box for further functions in this package,
format
or
print
it,
retrieve information as a data frame via survival_data_frames
or
access individual pieces via pluck_survival_analysis
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% print
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% print
Extracts useful information from a coxph/summary.coxph into a data frame which is ready for printing or further analysis
cox_as_data_frame( coxphsummary, unmangle_dict = NULL, factor_id_sep = ":", sort_by = NULL )
cox_as_data_frame( coxphsummary, unmangle_dict = NULL, factor_id_sep = ":", sort_by = NULL )
coxphsummary |
The summary.coxph or coxph result object |
unmangle_dict |
An unmangle dict of mangled column name -> readable column name (as created by analyse_multivariate) |
factor_id_sep |
The frame contains one column "factor.id" which is a composite of covariate name and, if categorical, the factor level (one line for each factor level except for the reference level) |
sort_by |
A vars() list of one or more symbolic column names. This frame contains the variables "Lower_CI", "HR", "Upper_CI", "Inv_Lower_CI", "Inv_HR", "Inv_Upper_CI", "p". You can choose to sort by any combination. Use desc() to sort a variable in descending order. |
A tibble.
Creates a forest plot from SurvivalAnalysisResult objects.
Both univariate (analyse_survival
) results, typically with use_one_hot=TRUE,
and multivariate (analyse_multivariate
) results are acceptable.
forest_plot( ..., use_one_hot = FALSE, factor_labeller = identity, endpoint_labeller = identity, orderer = identity_order, categorizer = NULL, relative_widths = c(1, 1, 1), ggtheme = theme_bw(), labels_displayed = c("endpoint", "factor"), label_headers = c(endpoint = "Endpoint", factor = "Subgroup", n = "n"), values_displayed = c("HR", "CI", "p"), value_headers = c(HR = "HR", CI = "CI", p = "p", n = "n", subgroup_n = "n"), HRsprintfFormat = "%.2f", psprintfFormat = "%.3f", p_lessthan_cutoff = 0.001, log_scale = TRUE, HR_x_breaks = seq(0, 10), HR_x_limits = NULL, factor_id_sep = ":", na_rm = TRUE, title = NULL, title_relative_height = 0.1, title_label_args = list(), base_papersize = dinA(4) ) forest_plot.df( .df, factor_labeller = identity, endpoint_labeller = identity, orderer = identity_order, categorizer = NULL, relative_widths = c(1, 1, 1), ggtheme = theme_bw(), labels_displayed = c("endpoint", "factor"), label_headers = c(endpoint = "Endpoint", factor = "Subgroup", n = "n"), values_displayed = c("HR", "CI", "p"), value_headers = c(HR = "HR", CI = "CI", p = "p", n = "n", subgroup_n = "n"), HRsprintfFormat = "%.2f", psprintfFormat = "%.3f", p_lessthan_cutoff = 0.001, log_scale = TRUE, HR_x_breaks = seq(0, 10), HR_x_limits = NULL, factor_id_sep = ":", na_rm = TRUE, title = NULL, title_relative_height = 0.1, title_label_args = list(), base_papersize = dinA(4) )
forest_plot( ..., use_one_hot = FALSE, factor_labeller = identity, endpoint_labeller = identity, orderer = identity_order, categorizer = NULL, relative_widths = c(1, 1, 1), ggtheme = theme_bw(), labels_displayed = c("endpoint", "factor"), label_headers = c(endpoint = "Endpoint", factor = "Subgroup", n = "n"), values_displayed = c("HR", "CI", "p"), value_headers = c(HR = "HR", CI = "CI", p = "p", n = "n", subgroup_n = "n"), HRsprintfFormat = "%.2f", psprintfFormat = "%.3f", p_lessthan_cutoff = 0.001, log_scale = TRUE, HR_x_breaks = seq(0, 10), HR_x_limits = NULL, factor_id_sep = ":", na_rm = TRUE, title = NULL, title_relative_height = 0.1, title_label_args = list(), base_papersize = dinA(4) ) forest_plot.df( .df, factor_labeller = identity, endpoint_labeller = identity, orderer = identity_order, categorizer = NULL, relative_widths = c(1, 1, 1), ggtheme = theme_bw(), labels_displayed = c("endpoint", "factor"), label_headers = c(endpoint = "Endpoint", factor = "Subgroup", n = "n"), values_displayed = c("HR", "CI", "p"), value_headers = c(HR = "HR", CI = "CI", p = "p", n = "n", subgroup_n = "n"), HRsprintfFormat = "%.2f", psprintfFormat = "%.3f", p_lessthan_cutoff = 0.001, log_scale = TRUE, HR_x_breaks = seq(0, 10), HR_x_limits = NULL, factor_id_sep = ":", na_rm = TRUE, title = NULL, title_relative_height = 0.1, title_label_args = list(), base_papersize = dinA(4) )
... |
The SurvivalAnalysisResult objects.
You can also pass one list of such objects, or use explicit splicing (!!! operator).
If not |
use_one_hot |
If not use_one_hot (default), will take univariate or multivariate results and plot hazard ratios
against the reference level (as provided to the |
factor_labeller , endpoint_labeller
|
Either
|
orderer |
A function which returns an integer ordering vector for the input:
Example:
|
categorizer |
A function which returns one logical value if a breaking line should be
inserted _above_ the input: Same semantics as for orderer.
!Please note!: The order of the data is not yet ordered as per your orderer!
If you do calculations depending on order, first order with your own orderer function.
A proper implementation is easy using |
relative_widths |
relation of the width of the plots, labels, plot, values. Default is 1:1:1. |
ggtheme |
ggplot2 theme to use |
labels_displayed |
Combination of "endpoint", "factor", "n", determining what is shown on the left-hand table and in which order. |
label_headers |
Named vector with name=<allowed values of labels_displayed>, value=<your heading>. |
values_displayed |
Combination of "HR", "CI", "p", "subgroup_n", determining what is shown on the right-hand table and in which order. Note: subgroup_n is only applicable if oneHot=TRUE. |
value_headers |
Named vector with name=<allowed values of values_displayed>, value=<your heading>. |
HRsprintfFormat , psprintfFormat
|
sprintf() format strings for hazard ratio and p value |
p_lessthan_cutoff |
The lower limit below which p value will be displayed as "less than". If p_lessthan_cutoff == 0.001, the a p value of 0.002 will be displayed as is, while 0.0005 will become "p < 0.001". |
log_scale |
Plot on log scale, which is quite common and gives symmetric length for the CI bars. Note that HRs of 0 (did not converge) will not be plotted in this case. |
HR_x_breaks |
Breaks of the x scale for plotting HR and CI |
HR_x_limits |
Limits of the x scale for plotting HR and CI. Default (HR_x_lim = NULL) depends on log_scale and existing limits. Pass NA to use the existing minimum and maximum values without interference. Pass a vector of size 2 to specify (min, max) manually |
factor_id_sep |
Allows you to customize the separator of the factor id, the documentation of factor_labeller. |
na_rm |
Only used in the multivariate case (use_one_hot = FALSE). Should null coefficients (NA/0/Inf) be removed? |
title , title_relative_height , title_label_args
|
A title on top of the plot, taking a fraction of title_relative_height of the returned plot.
The title is drawn using |
base_papersize |
numeric vector of length 2, c(width, height), unit inches. forest_plot will store a suggested "papersize" attribute in the return value, computed from base_papersize and the number of entries in the plot (in particular, the height will be adjusted) The attribute is read by save_pdf. It will also store a "forestplot_entries" attribute which you can use for your own calculations. |
.df |
Data frame containing the columns
|
df |
For the variant taking a data frame: A data frame which must contain (at least) the columns: endpoint, factor.id, factor.name, factor.value, HR, Lower_CI, Upper_CI, p, n, subgroup_n |
The plot has a left column containing the labels (covariate name, levels for categorical variables, optionally subgroup size), the actual line plot in the middle column, and a right column to display the hazard ratios and their confidence intervals. A rich set of parameters allows full customizability to create publication-ready plots.
A ggplot2 plot object
forest_plot.df
: Creates a forest plot from the given data frame
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% forest_plot()
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% forest_plot()
Makes use of the stored layout information in a forest_plot
plot to
create grids of plots.
forest_plot_grid( ..., nrow = NULL, ncol = NULL, byrow = TRUE, plot_grid_args = list() )
forest_plot_grid( ..., nrow = NULL, ncol = NULL, byrow = TRUE, plot_grid_args = list() )
... |
Pass individual plots returned by forest_plot, or lists of such plots (bare lists will be spliced). |
nrow , ncol
|
Specify the grid (one is sufficient, uses auto layout if both are null) |
byrow |
If the plots are given in by-row, or by-column (byrow=FALSE) order |
plot_grid_args |
Additional arguments to the |
Return value of plot_grid
Formats a SurvivalAnalysisMultivariateResult for printing
## S3 method for class 'SurvivalAnalysisMultivariateResult' format(x, ..., p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001)
## S3 method for class 'SurvivalAnalysisMultivariateResult' format(x, ..., p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001)
x |
The result generated by |
... |
Further arguments passed from other methods. |
p_precision , hr_precision
|
Precision with which to print floating point values |
p_less_than_cutoff |
Cut-off for small p values. Values smaller than this will be displayed like "<..." |
A formatted string, ready for output with cat()
Formats a SurvivalAnalysisUnivariateResult for printing
## S3 method for class 'SurvivalAnalysisUnivariateResult' format( x, ..., label = NULL, p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
## S3 method for class 'SurvivalAnalysisUnivariateResult' format( x, ..., label = NULL, p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
x |
The result generated by |
... |
Further arguments passed from other methods. |
label |
A label describing the result |
p_precision , hr_precision , time_precision
|
Precision with which to print floating point values |
p_less_than_cutoff |
Cut-off for small p values. Values smaller than this will be displayed like "<..." |
include_end_separator |
Append "\n—\n"? Comes handy if printing multiple results following each other |
timespan_unit |
Unit for time spans: "days", "months" or "years". |
A formatted string, ready for output with cat()
Build a gtable representation from a ggsurvplot object
ggsurvplot_to_gtable( ggsurv_obj, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL )
ggsurvplot_to_gtable( ggsurv_obj, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL )
ggsurv_obj |
The ggsurvplot object |
surv.plot.height , risk.table.height , ncensor.plot.height
|
Layout parameters, see |
A gtable object
Creates a grid layout nrow x ncol for n items.
grid_layout(n, rows = NULL, cols = NULL)
grid_layout(n, rows = NULL, cols = NULL)
n |
Number of items in grid |
rows , cols
|
Pass one of rows or cols, or none, in which case auto layout is used. |
A numeric vector of length 2: rows, cols
grid_layout(24, cols=4) grid_layout(24) grid_layout(24, rows=2)
grid_layout(24, cols=4) grid_layout(24) grid_layout(24, rows=2)
This can be used in a place where a function with a signature like order
is required.
It simply retains the original order.
identity_order(x, ...)
identity_order(x, ...)
x |
a vector |
... |
Effectively ignored |
An integer vector
A grid of kaplan meier plots
kaplan_meier_grid( ..., nrow = NULL, ncol = NULL, layout_matrix = NULL, byrow = TRUE, mapped_plot_args = list(), paperwidth = NULL, paperheight = NULL, size_per_plot = dinAWidth(5), title = NA, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, p_lessthan_cutoff = 0.001 )
kaplan_meier_grid( ..., nrow = NULL, ncol = NULL, layout_matrix = NULL, byrow = TRUE, mapped_plot_args = list(), paperwidth = NULL, paperheight = NULL, size_per_plot = dinAWidth(5), title = NA, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, p_lessthan_cutoff = 0.001 )
... |
One or many SurvivalAnalysisResult objects as returned by
|
nrow , ncol
|
Determines the layout by giving nrow and/or ncol, if missing, uses an auto layout. |
layout_matrix |
Optionally specify a layout matrix, which is passed to |
byrow |
If no layout_matrix is specified and there are multiple rows: How should the plots by layout? The order of the plots can be by-row (default) or by-col (set byrow=FALSE). |
mapped_plot_args |
Optionally, if given n objects to plot, a named list of vectors of size n. The name is an argument names passed to ggsurvplot. The elements of the vector will be mapped 1:1 to each object. This allows to perform batch plotting where only few arguments differ (e.g. titles A, B, C...) between the plots. Please note that only object that need plotting (survival_analysis results) are considered, not those that are already plotted (kaplan_meier_plot results) |
paperwidth , paperheight , size_per_plot
|
You can specify the size per plot, or the full paper width and height.
size_per_plot may be a number (width == height) or two-dimensional, width and height.
The resulting paper size will be stored as a papersize attribute that is e.g.
read by |
title , surv.plot.height , risk.table.height , ncensor.plot.height
|
Passed to |
p_lessthan_cutoff |
The lower limit below which p value will be displayed as "less than". If p_lessthan_cutoff == 0.001, the a p value of 0.002 will be displayed as is, while 0.0005 will become "p < 0.001". |
An object of class arrangelist, which can be printed or saved to pdf with ggsave().
Uses ggsurvplot
from the survminer package to create publication-ready plots.
kaplan_meier_plot(..., mapped_plot_args = list(), p_lessthan_cutoff = 0.001)
kaplan_meier_plot(..., mapped_plot_args = list(), p_lessthan_cutoff = 0.001)
... |
One or many SurvivalAnalysisResult objects as returned by
|
mapped_plot_args |
Optionally, if given n objects to plot, a named list of vectors of size n. The name is an argument names passed to ggsurvplot. The elements of the vector will be mapped 1:1 to each object. This allows to perform batch plotting where only few arguments differ (e.g. titles A, B, C...) between the plots. |
p_lessthan_cutoff |
The lower limit below which p value will be displayed as "less than". If p_lessthan_cutoff == 0.001, the a p value of 0.002 will be displayed as is, while 0.0005 will become "p < 0.001". |
If given one result to plot, one ggsurvplot object; if given more than one result, a list of ggsurvplot objects.
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% kaplan_meier_plot(break.time.by="breakByMonth", xlab=".OS.months", risk.table=TRUE, ggtheme=ggplot2::theme_bw(10))
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% kaplan_meier_plot(break.time.by="breakByMonth", xlab=".OS.months", risk.table=TRUE, ggtheme=ggplot2::theme_bw(10))
Extracts useful information into a data frame which is ready for printing or further analysis
multivariate_as_data_frame(result, factor_id_sep = ":", sort_by = NULL)
multivariate_as_data_frame(result, factor_id_sep = ":", sort_by = NULL)
result |
An object of class "SurvivalAnalysisMultivariateResult"
as returned by |
factor_id_sep |
The frame contains one column "factor.id" which is a composite of covariate name and, if categorical, the factor level (one line for each factor level except for the reference level) |
sort_by |
A vars() list of one or more symbolic column names. This frame contains the variables "Lower_CI", "HR", "Upper_CI", "Inv_Lower_CI", "Inv_HR", "Inv_Upper_CI", "p". You can choose to sort by any combination. Use desc() to sort a variable in descending order. |
A tibble.
Allows access to the analyse_multivariate
result object.
pluck_multivariate_analysis(result, term)
pluck_multivariate_analysis(result, term)
result |
An object of class SurvivalAnalysisMultivariateResult
as returned by |
term |
The item to be retrieved:
|
object as specified by term
, or NULL if not contained in result
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% pluck_multivariate_analysis("p") print
library(magrittr) library(dplyr) survival::colon %>% analyse_multivariate(vars(time, status), vars(rx, sex, age, obstruct, perfor, nodes, differ, extent)) %>% pluck_multivariate_analysis("p") print
Allows access to the analyse_survival
result object.
pluck_survival_analysis(result, term)
pluck_survival_analysis(result, term)
result |
An object of class SurvivalAnalysisUnivariateResult
as returned by |
term |
The item to be retrieved:
|
object as specified by term
, or NULL if not contained in result
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% pluck_survival_analysis("p") %>% print
library(magrittr) library(dplyr) survival::aml %>% analyse_survival(vars(time, status), x) %>% pluck_survival_analysis("p") %>% print
Print the essentials of a SurvivalAnalySurvivalAnalysisMultivariateResult
## S3 method for class 'SurvivalAnalysisMultivariateResult' print(x, ..., p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001)
## S3 method for class 'SurvivalAnalysisMultivariateResult' print(x, ..., p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001)
x |
The result generated by |
... |
Further arguments passed from other methods. |
p_precision |
Precision with which to print floating point values |
hr_precision |
Precision with which to print floating point values |
p_less_than_cutoff |
Cut-off for small p values. Values smaller than this will be displayed like "<..." |
The formatted string, invisibly. #' @export
Print the essentials of a SurvivalAnalysisUnivariateResult
## S3 method for class 'SurvivalAnalysisUnivariateResult' print( x, ..., label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
## S3 method for class 'SurvivalAnalysisUnivariateResult' print( x, ..., label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
x |
The result generated by |
... |
Further arguments passed from other methods. |
label |
A label describing the result |
p_precision |
Precision with which to print floating point values |
hr_precision |
Precision with which to print floating point values |
time_precision |
Precision with which to print floating point values |
include_end_separator |
Append "\n—\n"? Comes handy if printing multiple results following each other |
timespan_unit |
Unit for time spans: "days", "months" or "years". |
The formatted string, invisibly.
Extract results from univariate survival analysis structured as data frames
survival_data_frames( result, format_numbers = TRUE, p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001, time_precision = 1, timespan_unit = c("days", "months", "years") )
survival_data_frames( result, format_numbers = TRUE, p_precision = 3, hr_precision = 2, p_less_than_cutoff = 0.001, time_precision = 1, timespan_unit = c("days", "months", "years") )
result |
The result generated by |
format_numbers |
If true, all numbers will be formatted for printing according to the following options and will be returned as strings |
p_precision , hr_precision , time_precision
|
Precision with which to print floating point values |
p_less_than_cutoff |
Cut-off for small p values. Values smaller than this will be displayed like "<..." |
timespan_unit |
Unit for time spans: "days", "months" or "years". |
A named list list of data frame objects:
cohortMetadata: information about the full cohort
if there are strata (analysis performed "by" a covariate):
strataMetadata: information about each stratum
hazardRatios: hazard ratios for combinations of strata
only if there are more than two strata:
pairwisePValues: Matrix of pairwise (uncorrected) p values
Takes the given result, formats and prints it
survival_essentials( result, label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = TRUE, timespan_unit = "days", print = TRUE )
survival_essentials( result, label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = TRUE, timespan_unit = "days", print = TRUE )
result |
The result generated by |
label |
Optional label to include |
p_precision |
Precision with which to print floating point values |
hr_precision |
Precision with which to print floating point values |
time_precision |
Precision with which to print floating point values |
include_end_separator |
Append "\n—\n"? Comes handy if printing multiple results following each other |
timespan_unit |
Unit for time spans: "days", "months" or "years". |
print |
Print string to console |
The formatted string, invisibly. Ready for output with cat or saving to a file.
Write complete textual information for one or multiple survival analysis results in a text file.
write_survival( ..., file, label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
write_survival( ..., file, label = NULL, p_precision = 3, hr_precision = 2, time_precision = 1, include_end_separator = FALSE, timespan_unit = c("days", "months", "years") )
... |
Results generated by |
file |
A connection, or a character string naming the file to print to.
(see |
label |
A label describing the result, or a vector of the same size as results in ... (will then be mapped 1:1) |
p_precision , hr_precision , time_precision
|
Precision with which to print floating point values |
include_end_separator |
Boolean: Append "\n—\n" as separator? Comes handy if printing multiple results following each other |
timespan_unit |
Unit for time spans: "days", "months" or "years" |
As write_survival takes potentially multiple objects, it cannot
return its input in a cleanly defined way.
You can still elegantly combine write_survival
in a pipe followed by
kaplan_meier_plot
or kaplan_meier_grid
for a single input object if you apply the
tee pipe operator %T>%
in front of write_survival
.
None (invisible NULL).