Title: | Clinical Graphs and Tables Adhering to Graphical Principles |
---|---|
Description: | To enable fit-for-purpose, reusable clinical and medical research focused visualizations and tables with sensible defaults and based on graphical principles as described in: "Vandemeulebroecke et al. (2018)" <doi:10.1002/pst.1912>, "Vandemeulebroecke et al. (2019)" <doi:10.1002/psp4.12455>, and "Morris et al. (2019)" <doi:10.1136/bmjopen-2019-030215>. |
Authors: | Mark Baillie [aut, cre, cph], Diego Saldana [aut], Charlotta Fruechtenicht [aut], Marc Vandemeulebroecke [aut], Thanos Siadimas [aut], Pawel Kawski [aut], Steven Haesendonckx [aut], James Black [aut], Pelagia Alexandra Papadopoulou [aut], Tim Treis [aut], Rebecca Albrecht [aut], Ardalan Mirshani [ctb], Daniel D. Sjoberg [aut] |
Maintainer: | Mark Baillie <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.1 |
Built: | 2024-12-10 03:59:02 UTC |
Source: | https://github.com/openpharma/visR |
Wrapper around ggplot2::annotation_custom for simplified annotation to ggplot2 plots.
This function accepts a string, dataframe, data.table, tibble or customized
objects of class gtable
and places them on the specified location on
the ggplot
. The layout is fixed: bold column headers and plain body.
Only the font size and type can be chosen.
Both the initial plot as the individual annotation are stored as attribute component
in the final object.
add_annotation( gg = NULL, label = NULL, base_family = "sans", base_size = 11, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf )
add_annotation( gg = NULL, label = NULL, base_family = "sans", base_size = 11, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf )
gg |
Object of class |
label |
|
base_family |
|
base_size |
|
xmin |
x coordinates giving horizontal location of raster in which to fit annotation. |
xmax |
x coordinates giving horizontal location of raster in which to fit annotation. |
ymin |
y coordinates giving vertical location of raster in which to fit annotation. |
ymax |
y coordinates giving vertical location of raster in which to fit annotation. |
Object of class ggplot
with added annotation with an object of class gtable
.
## Estimate survival surv_object <- visR::estimate_KM(data = adtte, strata = "TRTP") ## We want to annotate the survival KM plot with a simple string comment visR::visr(surv_object) %>% visR::add_annotation( label = "My simple comment", base_family = "sans", base_size = 15, xmin = 110, xmax = 180, ymin = 0.80 ) ## Currently, care needs to be taken on the x-y values relative ## to the plot data area. Here we are plotting outside of the data area. visR::visr(surv_object) %>% visR::add_annotation( label = "My simple comment", base_family = "sans", base_size = 15, xmin = 210, xmax = 380, ymin = 1.0 ) ## We may also want to annotate a KM plot with information ## from additional tests or estimates. This example we annotate ## with p-values contained in a tibble ## we calculate p-values for "Equality across strata" lbl <- visR::get_pvalue(surv_object, statlist = c("test", "pvalue"), type = "All" ) ## display p-values lbl ## Now annotate survival KM plot with the p-values visR::visr(surv_object) %>% visR::add_annotation( label = lbl, base_family = "sans", base_size = 9, xmin = 100, xmax = 180, ymin = 0.80 )
## Estimate survival surv_object <- visR::estimate_KM(data = adtte, strata = "TRTP") ## We want to annotate the survival KM plot with a simple string comment visR::visr(surv_object) %>% visR::add_annotation( label = "My simple comment", base_family = "sans", base_size = 15, xmin = 110, xmax = 180, ymin = 0.80 ) ## Currently, care needs to be taken on the x-y values relative ## to the plot data area. Here we are plotting outside of the data area. visR::visr(surv_object) %>% visR::add_annotation( label = "My simple comment", base_family = "sans", base_size = 15, xmin = 210, xmax = 380, ymin = 1.0 ) ## We may also want to annotate a KM plot with information ## from additional tests or estimates. This example we annotate ## with p-values contained in a tibble ## we calculate p-values for "Equality across strata" lbl <- visR::get_pvalue(surv_object, statlist = c("test", "pvalue"), type = "All" ) ## display p-values lbl ## Now annotate survival KM plot with the p-values visR::visr(surv_object) %>% visR::add_annotation( label = lbl, base_family = "sans", base_size = 9, xmin = 100, xmax = 180, ymin = 0.80 )
Method to add pointwise confidence intervals to a an object
created by visR through an S3 method. The method is set up to use
the pipe %>%
. There are two options to display CI's, a "ribbon" or
as "step" lines.
No default method is available at the moment.
add_CI(gg, ...) ## S3 method for class 'ggsurvfit' add_CI(gg, alpha = 0.1, style = "ribbon", linetype, ...) ## S3 method for class 'ggtidycuminc' add_CI(gg, alpha = 0.1, style = "ribbon", linetype, ...)
add_CI(gg, ...) ## S3 method for class 'ggsurvfit' add_CI(gg, alpha = 0.1, style = "ribbon", linetype, ...) ## S3 method for class 'ggtidycuminc' add_CI(gg, alpha = 0.1, style = "ribbon", linetype, ...)
gg |
A ggplot created with visR |
... |
other arguments passed on to the method to modify |
alpha |
aesthetic of ggplot2 |
style |
aesthetic of ggplot2 |
linetype |
aesthetic of ggplot2 |
Pointwise confidence interval overlayed on a visR ggplot
library(visR) # Estimate KM curves by treatment group survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) ## plot without confidence intervals (CI) p <- visR::visr(survfit_object) p # add CI to plot with default settings p %>% add_CI() # change transparency of CI ribbon p %>% add_CI(alpha = 0.9, style = "ribbon") # plot CI as a step line instead of ribbon p %>% add_CI(alpha = 0.1, style = "step") # change linetype of CI p %>% add_CI(style = "step", linetype = 1)
library(visR) # Estimate KM curves by treatment group survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) ## plot without confidence intervals (CI) p <- visR::visr(survfit_object) p # add CI to plot with default settings p %>% add_CI() # change transparency of CI ribbon p %>% add_CI(alpha = 0.9, style = "ribbon") # plot CI as a step line instead of ribbon p %>% add_CI(alpha = 0.1, style = "step") # change linetype of CI p %>% add_CI(style = "step", linetype = 1)
Add censoring symbols to a visR ggplot through an S3 method.
The S3 method is for adding censoring symbols to a visR ggplot.
The method is set up to use the pipe %>%
.
No default method is available at the moment.
add_CNSR(gg, ...) ## S3 method for class 'ggsurvfit' add_CNSR(gg, shape = 3, size = 2, ...) ## S3 method for class 'ggtidycuminc' add_CNSR(gg, shape = 3, size = 2, ...)
add_CNSR(gg, ...) ## S3 method for class 'ggsurvfit' add_CNSR(gg, shape = 3, size = 2, ...) ## S3 method for class 'ggtidycuminc' add_CNSR(gg, shape = 3, size = 2, ...)
gg |
A ggplot created with visR |
... |
other arguments passed on to the method to modify |
shape |
aesthetic of ggplot2 |
size |
aesthetic of ggplot2 |
Censoring symbols overlayed on a visR ggplot
library(visR) # Estimate KM curves by treatment group survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) ## plot without confidence intervals p <- visR::visr(survfit_object) p # add censoring to plot p %>% visR::add_CNSR() # change censor symbol shape p %>% visR::add_CNSR(shape = 1) # change size and shape p %>% visR::add_CNSR(size = 4, shape = 2)
library(visR) # Estimate KM curves by treatment group survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) ## plot without confidence intervals p <- visR::visr(survfit_object) p # add censoring to plot p %>% visR::add_CNSR() # change censor symbol shape p %>% visR::add_CNSR(shape = 1) # change size and shape p %>% visR::add_CNSR(size = 4, shape = 2)
S3 method for highlighting a specific strata by lowering the opacity of all other strata.
add_highlight(gg, ...) ## S3 method for class 'ggsurvfit' add_highlight(gg = NULL, strata = NULL, bg_alpha = 0.2, ...)
add_highlight(gg, ...) ## S3 method for class 'ggsurvfit' add_highlight(gg = NULL, strata = NULL, bg_alpha = 0.2, ...)
gg |
A ggplot created with visR |
... |
other arguments passed on to the method |
strata |
String representing the name and value of the strata to be highlighted as shown in the legend. |
bg_alpha |
A numerical value between 0 and 1 that is used to decrease the opacity off all strata not chosen to be highlighted in |
The input ggsurvfit
object with adjusted alpha
values
adtte %>% visR::estimate_KM(strata = "SEX") %>% visR::visr() %>% visR::add_CI(alpha = 0.4) %>% visR::add_highlight(strata = "M", bg_alpha = 0.2) strata <- c("Placebo", "Xanomeline Low Dose") adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_CI(alpha = 0.4) %>% visR::add_highlight(strata = strata, bg_alpha = 0.2)
adtte %>% visR::estimate_KM(strata = "SEX") %>% visR::visr() %>% visR::add_CI(alpha = 0.4) %>% visR::add_highlight(strata = "M", bg_alpha = 0.2) strata <- c("Placebo", "Xanomeline Low Dose") adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_CI(alpha = 0.4) %>% visR::add_highlight(strata = strata, bg_alpha = 0.2)
Method to add quantile lines to a plot.
add_quantiles(gg, ...) ## S3 method for class 'ggsurvfit' add_quantiles( gg, quantiles = 0.5, linetype = "dashed", linecolour = "grey50", alpha = 1, ... )
add_quantiles(gg, ...) ## S3 method for class 'ggsurvfit' add_quantiles( gg, quantiles = 0.5, linetype = "dashed", linecolour = "grey50", alpha = 1, ... )
gg |
A ggplot created with visR |
... |
other arguments passed on to the method to modify |
quantiles |
vector of quantiles to be displayed on the probability scale, default: 0.5 |
linetype |
string indicating the linetype as described in the aesthetics of ggplot2 |
linecolour |
string indicating the linetype as described in the aesthetics of ggplot2 |
alpha |
numeric value between 0 and 1 as described in the aesthetics of ggplot2 |
Lines indicating the quantiles overlayed on a visR ggplot
library(visR) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles() adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles(quantiles = c(0.25, 0.50)) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles( quantiles = c(0.25, 0.50), linetype = "solid", linecolour = "grey" ) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles( quantiles = c(0.25, 0.50), linetype = "mixed", linecolour = "strata" )
library(visR) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles() adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles(quantiles = c(0.25, 0.50)) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles( quantiles = c(0.25, 0.50), linetype = "solid", linecolour = "grey" ) adtte %>% estimate_KM("SEX") %>% visr() %>% add_quantiles( quantiles = c(0.25, 0.50), linetype = "mixed", linecolour = "strata" )
S3 method for adding risk tables to visR plots. The function has following workflow:
The risktables are calculated using get_risktable
The risktables are placed underneath visR plots using plot_grid
Both the initial visR plot as the individual risktables are stored as attribute component
in the final object to allow post-modification of the individual plots if desired
add_risktable(gg, ...) ## S3 method for class 'ggsurvfit' add_risktable( gg, times = NULL, statlist = "n.risk", label = NULL, group = "strata", collapse = FALSE, rowgutter = 0.16, ... ) ## S3 method for class 'ggtidycuminc' add_risktable( gg, times = NULL, statlist = "n.risk", label = NULL, group = "strata", collapse = FALSE, rowgutter = 0.16, ... )
add_risktable(gg, ...) ## S3 method for class 'ggsurvfit' add_risktable( gg, times = NULL, statlist = "n.risk", label = NULL, group = "strata", collapse = FALSE, rowgutter = 0.16, ... ) ## S3 method for class 'ggtidycuminc' add_risktable( gg, times = NULL, statlist = "n.risk", label = NULL, group = "strata", collapse = FALSE, rowgutter = 0.16, ... )
gg |
visR plot of class |
... |
other arguments passed on to the method add_risktable |
times |
Numeric vector indicating the times at which the risk set, censored subjects, events are calculated. |
statlist |
Character vector indicating which summary data to present. Current choices are "n.risk" "n.event" "n.censor", "cum.event", "cum.censor". Default is "n.risk". |
label |
Character vector with labels for the statlist. Default matches "n.risk" with "At risk", "n.event" with "Events", "n.censor" with "Censored", "cum.event" with "Cum. Event", and "cum.censor" with "Cum. Censor". |
group |
String indicating the grouping variable for the risk tables. Current options are:
Default is "strata". |
collapse |
Boolean, indicates whether to present the data overall. Default is FALSE. |
rowgutter |
A numeric relative value between 0 and 1 indicates the height used by the table versus the height
used by the plot, as described in |
Object of class ggplot
with added risk table.
## Display 2 risk tables, 1 per statlist adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable( label = c("Subjects at Risk", "Censored"), statlist = c("n.risk", "n.censor", "n.event"), group = "statlist" ) ## Display overall risk table at selected times adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable( label = c("Subjects at Risk", "Censored"), statlist = c("n.risk", "n.censor"), collapse = TRUE, times = c(0, 20, 40, 60) ) ## Add risk set as specified times adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable(times = c(0, 20, 40, 100, 111, 200))
## Display 2 risk tables, 1 per statlist adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable( label = c("Subjects at Risk", "Censored"), statlist = c("n.risk", "n.censor", "n.event"), group = "statlist" ) ## Display overall risk table at selected times adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable( label = c("Subjects at Risk", "Censored"), statlist = c("n.risk", "n.censor"), collapse = TRUE, times = c(0, 20, 40, 60) ) ## Add risk set as specified times adtte %>% visR::estimate_KM(strata = "TRTP") %>% visR::visr() %>% visR::add_risktable(times = c(0, 20, 40, 100, 111, 200))
ADTTE data copied from the 2013 CDISC Pilot
adtte
adtte
A data frame with 254 rows and 26 variables:
Study Identifier
Study Site Identifier
Unique Subject Identifier
Age
Pooled Age Group 1
Pooled Age Group 1 (N)
Race
Race (N)
Sex
Date of First Exposure to Treatment
Date of Last Exposure to Treatment
Duration of treatment (days)
Planned Treatment
Actual Treatment
Actual Treatment (N)
Parameter Description
Parameter Code
Analysis Value
Time to Event Origin Date for Subject
Analysis Date
Censor
Event or Censoring Description
Source Domain
Source Variable
Source Sequence Number
Safety Population Flag
CDISC SDTM/ADAM Pilot Project. https://github.com/phuse-org/phuse-scripts/tree/master/data
data("adtte")
data("adtte")
This function aligns multiple ggplot
graphs by making them the same width by taking into account the legend width.
align_plots(pltlist)
align_plots(pltlist)
pltlist |
A list of plots |
List of ggplot
with equal width.
https://stackoverflow.com/questions/26159495
## create 2 graphs p1 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE), fill = "Age")) + ggplot2::geom_histogram(bins = 15) p2 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE))) + ggplot2::geom_histogram(bins = 15) ## default alignment does not take into account legend size cowplot::plot_grid( plotlist = list(p1, p2), align = "none", nrow = 2 ) ## align_plots() takes into account legend width cowplot::plot_grid( plotlist = visR::align_plots(pltlist = list(p1, p2)), align = "none", nrow = 2 )
## create 2 graphs p1 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE), fill = "Age")) + ggplot2::geom_histogram(bins = 15) p2 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE))) + ggplot2::geom_histogram(bins = 15) ## default alignment does not take into account legend size cowplot::plot_grid( plotlist = list(p1, p2), align = "none", nrow = 2 ) ## align_plots() takes into account legend width cowplot::plot_grid( plotlist = visR::align_plots(pltlist = list(p1, p2)), align = "none", nrow = 2 )
Apply list of inclusion/exclusion criteria to a patient-level dataframe
apply_attrition(data, criteria_conditions)
apply_attrition(data, criteria_conditions)
data |
|
criteria_conditions |
|
Filtered data frame
adtte_filtered <- visR::apply_attrition(adtte, criteria_conditions = c( "TRTP=='Placebo'", "AGE>=75", "RACE=='WHITE'", "SITEID==709" ) )
adtte_filtered <- visR::apply_attrition(adtte, criteria_conditions = c( "TRTP=='Placebo'", "AGE>=75", "RACE=='WHITE'", "SITEID==709" ) )
Takes in the styling options defined through visR::define_theme
and applies them to a plot.
apply_theme(gg, visR_theme_dict = NULL)
apply_theme(gg, visR_theme_dict = NULL)
gg |
object of class |
visR_theme_dict |
nested list containing possible font options |
object of class ggplot
library(visR) theme <- visR::define_theme( strata = list( "SEX" = list( "F" = "red", "M" = "blue" ), "TRTA" = list( "Placebo" = "cyan", "Xanomeline High Dose" = "purple", "Xanomeline Low Dose" = "brown" ) ), fontsizes = list( "axis" = 12, "ticks" = 10, "legend_title" = 10, "legend_text" = 8 ), fontfamily = "Helvetica", grid = FALSE, bg = "transparent", legend_position = "top" ) gg <- adtte %>% visR::estimate_KM(strata = "SEX") %>% visR::visr() %>% visR::apply_theme(theme) gg
library(visR) theme <- visR::define_theme( strata = list( "SEX" = list( "F" = "red", "M" = "blue" ), "TRTA" = list( "Placebo" = "cyan", "Xanomeline High Dose" = "purple", "Xanomeline Low Dose" = "brown" ) ), fontsizes = list( "axis" = 12, "ticks" = 10, "legend_title" = 10, "legend_text" = 8 ), fontfamily = "Helvetica", grid = FALSE, bg = "transparent", legend_position = "top" ) gg <- adtte %>% visR::estimate_KM(strata = "SEX") %>% visR::visr() %>% visR::apply_theme(theme) gg
Creation script in data-raw
brca_cohort
brca_cohort
An object of class data.frame
with 1098 rows and 10 columns.
This function collects several lists if they are present. If absent, reasonable defaults are used. When strata are not defined in the theme, they default to grey50 and will not be presented in the legend.
define_theme( strata = NULL, fontsizes = NULL, fontfamily = "Helvetica", grid = FALSE, bg = "transparent", legend_position = NULL )
define_theme( strata = NULL, fontsizes = NULL, fontfamily = "Helvetica", grid = FALSE, bg = "transparent", legend_position = NULL )
strata |
named list containing the different strata and name:colour value pairs |
fontsizes |
named list containing the font sizes for different options |
fontfamily |
string with the name of a supported font |
grid |
boolean that specifies whether the major and minor grid should be drawn. The drawing of major and minor
gridlines can be manipulated separately by using a boolean indicator in a named |
bg |
string defining the colour for the background of the plot |
legend_position |
string defining the legend position. Valid options are NULL, 'top' 'bottom' 'right' 'left' |
Nested list with styling preferences for a ggplot object
theme <- visR::define_theme( strata = list("SEX" = list( "F" = "red", "M" = "blue" )), fontsizes = list( "axis" = 12, "ticks" = 10, "legend_title" = 10, "legend_text" = 8 ), fontfamily = "Helvetica", grid = list( "major" = FALSE, "minor" = FALSE ), bg = "transparent", legend_position = "top" )
theme <- visR::define_theme( strata = list("SEX" = list( "F" = "red", "M" = "blue" )), fontsizes = list( "axis" = 12, "ticks" = 10, "legend_title" = 10, "legend_text" = 8 ), fontfamily = "Helvetica", grid = list( "major" = FALSE, "minor" = FALSE ), bg = "transparent", legend_position = "top" )
Function creates a cumulative incidence object using the
tidycmprsk::cuminc()
function.
estimate_cuminc( data = NULL, strata = NULL, CNSR = "CNSR", AVAL = "AVAL", conf.int = 0.95, ... )
estimate_cuminc( data = NULL, strata = NULL, CNSR = "CNSR", AVAL = "AVAL", conf.int = 0.95, ... )
data |
A data frame. The dataset is expected to have one record per subject per analysis parameter. Rows with missing observations included in the analysis are removed. |
AVAL , CNSR , strata
|
These arguments are used to construct a formula to be passed to
|
conf.int |
Confidence internal level. Default is 0.95. Parameter is passed to |
... |
Additional argument passed to |
A cumulative incidence object as explained at https://mskcc-epi-bio.github.io/tidycmprsk/reference/cuminc.html
cuminc <- visR::estimate_cuminc( data = tidycmprsk::trial, strata = "trt", CNSR = "death_cr", AVAL = "ttdeath" ) cuminc cuminc %>% visR::visr() %>% visR::add_CI() %>% visR::add_risktable(statlist = c("n.risk", "cum.event"))
cuminc <- visR::estimate_cuminc( data = tidycmprsk::trial, strata = "trt", CNSR = "death_cr", AVAL = "ttdeath" ) cuminc cuminc %>% visR::visr() %>% visR::add_CI() %>% visR::add_risktable(statlist = c("n.risk", "cum.event"))
This function is a wrapper around survival::survfit.formula()
to perform a Kaplan-Meier analysis, assuming right-censored data.
The result is an object of class survfit
which can be used in
downstream functions and methods that rely on the survfit
class.
The function can leverage the conventions and controlled vocabulary from
CDISC ADaM ADTTE data model,
and also works with standard, non-CDISC datasets through the formula
argument.
estimate_KM( data = NULL, strata = NULL, CNSR = "CNSR", AVAL = "AVAL", formula = NULL, ... )
estimate_KM( data = NULL, strata = NULL, CNSR = "CNSR", AVAL = "AVAL", formula = NULL, ... )
survfit object ready for downstream processing in estimation or visualization functions and methods.
The estimate_KM()
function utilizes the defaults in survival::survfit()
:
The Kaplan Meier estimate is estimated directly (stype = 1).
The cumulative hazard is estimated using the Nelson-Aalen estimator (ctype = 1): H.tilde = cumsum(x$n.event/x$n.risk). The MLE (H.hat(t) = -log(S.hat(t))) can't be requested.
A two-sided pointwise 0.95 confidence interval is estimated using a log transformation (conf.type = "log").
When strata are present, the returned survfit object is supplemented with the a named list of the stratum and associated label. To support full traceability, the data set name is captured in the named list and the call is captured within its corresponding environment.
If the data frame includes columns PARAM/PARAMCD (part of the CDISC format), the function expects the data has been filtered on the parameter of interest.
https://github.com/therneau/survival
## No stratification visR::estimate_KM(data = adtte) ## Stratified Kaplan-Meier analysis by `TRTP` visR::estimate_KM(data = adtte, strata = "TRTP") ## Stratified Kaplan-Meier analysis by `TRTP` and `SEX` visR::estimate_KM(data = adtte, strata = c("TRTP", "SEX")) ## Stratification with one level visR::estimate_KM(data = adtte, strata = "PARAMCD") ## Analysis on subset of adtte visR::estimate_KM(data = adtte[adtte$SEX == "F", ]) ## Modify the default analysis by using the ellipsis visR::estimate_KM( data = adtte, strata = NULL, type = "kaplan-meier", conf.int = FALSE, timefix = TRUE ) ## Example working with non CDISC data head(survival::veteran[c("time", "status", "trt")]) # Using non-CDSIC data visR::estimate_KM(data = survival::veteran, formula = Surv(time, status) ~ trt)
## No stratification visR::estimate_KM(data = adtte) ## Stratified Kaplan-Meier analysis by `TRTP` visR::estimate_KM(data = adtte, strata = "TRTP") ## Stratified Kaplan-Meier analysis by `TRTP` and `SEX` visR::estimate_KM(data = adtte, strata = c("TRTP", "SEX")) ## Stratification with one level visR::estimate_KM(data = adtte, strata = "PARAMCD") ## Analysis on subset of adtte visR::estimate_KM(data = adtte[adtte$SEX == "F", ]) ## Modify the default analysis by using the ellipsis visR::estimate_KM( data = adtte, strata = NULL, type = "kaplan-meier", conf.int = FALSE, timefix = TRUE ) ## Example working with non CDISC data head(survival::veteran[c("time", "status", "trt")]) # Using non-CDSIC data visR::estimate_KM(data = survival::veteran, formula = Surv(time, status) ~ trt)
This is an experimental function that may be developed over time.
This function calculates the subjects counts excluded and included for each step of the cohort selection process.
get_attrition(data, criteria_descriptions, criteria_conditions, subject_column_name)
get_attrition(data, criteria_descriptions, criteria_conditions, subject_column_name)
data |
Dataframe. It is used as the input data to count the subjects that meets the criteria of interest |
criteria_descriptions |
|
criteria_conditions |
|
subject_column_name |
|
criteria_descriptions and criteria_conditions need to be of same length
The counts and percentages of the remaining and excluded subjects for each step of the cohort selection in a table format.
visR::get_attrition(adtte, criteria_descriptions = c( "1. Placebo Group", "2. Be 75 years of age or older.", "3. White", "4. Site 709" ), criteria_conditions = c( "TRTP=='Placebo'", "AGE>=75", "RACE=='WHITE'", "SITEID==709" ), subject_column_name = "USUBJID" )
visR::get_attrition(adtte, criteria_descriptions = c( "1. Placebo Group", "2. Be 75 years of age or older.", "3. White", "4. Site 709" ), criteria_conditions = c( "TRTP=='Placebo'", "AGE>=75", "RACE=='WHITE'", "SITEID==709" ), subject_column_name = "USUBJID" )
S3 method for extracting information regarding Hazard Ratios. The function allows the survival object's formula to be updated. No default method is available at the moment.
get_COX_HR(x, ...) ## S3 method for class 'survfit' get_COX_HR(x, update_formula = NULL, ...)
get_COX_HR(x, ...) ## S3 method for class 'survfit' get_COX_HR(x, update_formula = NULL, ...)
x |
An object of class |
... |
other arguments passed on to the method survival::coxph |
update_formula |
Template which specifies how to update the formula of the survfit object |
A tidied object of class coxph
containing Hazard Ratios
## treatment effect survfit_object_trt <- visR::estimate_KM(data = adtte, strata = c("TRTP")) visR::get_COX_HR(survfit_object_trt) ## treatment and gender effect survfit_object_trt_sex <- visR::estimate_KM(data = adtte, strata = c("TRTP", "SEX")) visR::get_COX_HR(survfit_object_trt_sex) ## update formula of KM estimates by treatment to include "SEX" for HR estimation visR::get_COX_HR(survfit_object_trt, update_formula = ". ~ . + SEX") ## update formula of KM estimates by treatment to include "AGE" for ## HR estimation with ties considered via the efron method visR::get_COX_HR(survfit_object_trt, update_formula = ". ~ . + survival::strata(AGE)", ties = "efron" )
## treatment effect survfit_object_trt <- visR::estimate_KM(data = adtte, strata = c("TRTP")) visR::get_COX_HR(survfit_object_trt) ## treatment and gender effect survfit_object_trt_sex <- visR::estimate_KM(data = adtte, strata = c("TRTP", "SEX")) visR::get_COX_HR(survfit_object_trt_sex) ## update formula of KM estimates by treatment to include "SEX" for HR estimation visR::get_COX_HR(survfit_object_trt, update_formula = ". ~ . + SEX") ## update formula of KM estimates by treatment to include "AGE" for ## HR estimation with ties considered via the efron method visR::get_COX_HR(survfit_object_trt, update_formula = ". ~ . + survival::strata(AGE)", ties = "efron" )
Wrapper around survival::survdiff that tests the null hypothesis of equality across strata.
get_pvalue( survfit_object, ptype = "All", rho = NULL, statlist = c("test", "Chisq", "df", "pvalue"), ... )
get_pvalue( survfit_object, ptype = "All", rho = NULL, statlist = c("test", "Chisq", "df", "pvalue"), ... )
survfit_object |
An object of class |
ptype |
Character vector containing the type of p-value desired. Current options are "Log-Rank" "Wilcoxon" "Tarone-Ware" "Custom" "All".
"Custom" allows the user to specify the weights on the Kaplan-Meier estimates using the argument |
rho |
a scalar parameter that controls the type of test. |
statlist |
Character vector containing the desired information to be displayed. The order of the arguments determines the order in which they are displayed in the final result. Default is the test name ("test"), Chi-squared test statistic ("Chisq"), degrees of freedom ("df") and p-value ("pvalue"). |
... |
other arguments passed on to the method |
A data frame with summary measures for the Test of Equality Across Strata
## general examples survfit_object <- visR::estimate_KM(data = adtte, strata = "TRTP") visR::get_pvalue(survfit_object) visR::get_pvalue(survfit_object, ptype = "All") ## examples to obtain specific tests visR::get_pvalue(survfit_object, ptype = "Log-Rank") visR::get_pvalue(survfit_object, ptype = "Wilcoxon") visR::get_pvalue(survfit_object, ptype = "Tarone-Ware") ## Custom example - obtain Harrington and Fleming test visR::get_pvalue(survfit_object, ptype = "Custom", rho = 1) ## Get specific information and statistics visR::get_pvalue(survfit_object, ptype = "Log-Rank", statlist = c("test", "Chisq", "df", "pvalue")) visR::get_pvalue(survfit_object, ptype = "Wilcoxon", statlist = c("pvalue"))
## general examples survfit_object <- visR::estimate_KM(data = adtte, strata = "TRTP") visR::get_pvalue(survfit_object) visR::get_pvalue(survfit_object, ptype = "All") ## examples to obtain specific tests visR::get_pvalue(survfit_object, ptype = "Log-Rank") visR::get_pvalue(survfit_object, ptype = "Wilcoxon") visR::get_pvalue(survfit_object, ptype = "Tarone-Ware") ## Custom example - obtain Harrington and Fleming test visR::get_pvalue(survfit_object, ptype = "Custom", rho = 1) ## Get specific information and statistics visR::get_pvalue(survfit_object, ptype = "Log-Rank", statlist = c("test", "Chisq", "df", "pvalue")) visR::get_pvalue(survfit_object, ptype = "Wilcoxon", statlist = c("pvalue"))
S3 method for extracting quantiles. No default method is available at the moment.
get_quantile(x, ...) ## S3 method for class 'survfit' get_quantile( x, ..., probs = c(0.25, 0.5, 0.75), conf.int = TRUE, tolerance = sqrt(.Machine$double.eps) )
get_quantile(x, ...) ## S3 method for class 'survfit' get_quantile( x, ..., probs = c(0.25, 0.5, 0.75), conf.int = TRUE, tolerance = sqrt(.Machine$double.eps) )
x |
An object of class |
... |
other arguments passed on to the method |
probs |
probabilities Default = c(0.25,0.50,0.75) |
conf.int |
should lower and upper confidence limits be returned? |
tolerance |
tolerance for checking that the survival curve exactly equals one of the quantiles |
A data frame with quantiles of the object
## Kaplan-Meier estimates survfit_object <- visR::estimate_KM(data = adtte, strata = c("TRTP")) ## visR quantiles visR::get_quantile(survfit_object) ## survival quantiles quantile(survfit_object)
## Kaplan-Meier estimates survfit_object <- visR::estimate_KM(data = adtte, strata = c("TRTP")) ## visR quantiles visR::get_quantile(survfit_object) ## survival quantiles quantile(survfit_object)
Create a risk table from an object using an S3 method. Currently, no default method is defined.
get_risktable(x, ...) ## S3 method for class 'survfit' get_risktable( x, times = NULL, statlist = "n.risk", label = NULL, group = c("strata", "statlist"), collapse = FALSE, ... ) ## S3 method for class 'tidycuminc' get_risktable( x, times = pretty(x$tidy$time, 10), statlist = "n.risk", label = NULL, group = c("strata", "statlist"), collapse = FALSE, ... )
get_risktable(x, ...) ## S3 method for class 'survfit' get_risktable( x, times = NULL, statlist = "n.risk", label = NULL, group = c("strata", "statlist"), collapse = FALSE, ... ) ## S3 method for class 'tidycuminc' get_risktable( x, times = pretty(x$tidy$time, 10), statlist = "n.risk", label = NULL, group = c("strata", "statlist"), collapse = FALSE, ... )
x |
an object of class |
... |
other arguments passed on to the method |
times |
Numeric vector indicating the times at which the risk set, censored subjects, events are calculated. |
statlist |
Character vector indicating which summary data to present. Current choices are "n.risk" "n.event" "n.censor", "cum.event", "cum.censor". Default is "n.risk". |
label |
Character vector with labels for the statlist. Default matches "n.risk" with "At risk", "n.event" with "Events", "n.censor" with "Censored", "cum.event" with "Cum. Event", and "cum.censor" with "Cum. Censor". |
group |
String indicating the grouping variable for the risk tables. Current options are:
Default is "strata". |
collapse |
Boolean, indicates whether to present the data overall. Default is FALSE. |
return list of attributes the form the risk table i.e. number of patients at risk per strata
S3 method for extracting descriptive statistics across strata. No default method is available at the moment.
get_summary(x, ...) ## S3 method for class 'survfit' get_summary( x, statlist = c("strata", "records", "events", "median", "LCL", "UCL", "CI"), ... )
get_summary(x, ...) ## S3 method for class 'survfit' get_summary( x, statlist = c("strata", "records", "events", "median", "LCL", "UCL", "CI"), ... )
x |
An object of class |
... |
other arguments passed on to the method |
statlist |
Character vector containing the desired information to be displayed. The order of the arguments determines the order in which they are displayed in the final result. Default is the strata ("strata"), number of subjects ("records"), number of events ("events"), the median survival time ("median"), the Confidence Interval ("CI"), the Lower Confidence Limit ("UCL") and the Upper Confidence Limit ("UCL"). |
list of summary statistics from survfit object
A data frame with summary measures from a survfit
object
survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) get_summary(survfit_object)
survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1 - CNSR) ~ TRTP) get_summary(survfit_object)
S3 method for creating a table of summary statistics. The summary statistics can be used for presentation in tables such as table one or baseline and demography tables.
The summary statistics estimated are conditional on the variable type: continuous, binary, categorical, etc.
By default the following summary stats are calculated:
Numeric variables: mean, min, 25th-percentile, median, 75th-percentile, maximum, standard deviation
Factor variables: proportion of each factor level in the overall dataset
Default: number of unique values and number of missing values
get_tableone( data, strata = NULL, overall = TRUE, summary_function = summarize_short ) ## Default S3 method: get_tableone( data, strata = NULL, overall = TRUE, summary_function = summarize_short )
get_tableone( data, strata = NULL, overall = TRUE, summary_function = summarize_short ) ## Default S3 method: get_tableone( data, strata = NULL, overall = TRUE, summary_function = summarize_short )
data |
The dataset to summarize as dataframe or tibble |
strata |
Stratifying/Grouping variable name(s) as character vector. If NULL, only overall results are returned |
overall |
If TRUE, the summary statistics for the overall dataset are also calculated |
summary_function |
A function defining summary statistics for numeric and categorical values |
It is possible to provide your own summary function. Please have a loot at summary for inspiration.
object of class tableone. That is a list of data specified summaries for all input variables.
All columns in the table will be summarized. If only some columns shall be used, please select only those variables prior to creating the summary table by using dplyr::select()
# Example using the ovarian data set survival::ovarian %>% dplyr::select(-fustat) %>% dplyr::mutate( age_group = factor( dplyr::case_when( age <= 50 ~ "<= 50 years", age <= 60 ~ "<= 60 years", age <= 70 ~ "<= 70 years", TRUE ~ "> 70 years" ) ), rx = factor(rx), ecog.ps = factor(ecog.ps) ) %>% dplyr::select(age, age_group, everything()) %>% visR::get_tableone() # Examples using ADaM data # display patients in an analysis set adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(TRTA) %>% visR::get_tableone() ## display overall summaries for demog adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, RACE) %>% visR::get_tableone() ## By actual treatment adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, RACE, TRTA) %>% visR::get_tableone(strata = "TRTA") ## By actual treatment, without overall adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::get_tableone(strata = "TRTA", overall = FALSE)
# Example using the ovarian data set survival::ovarian %>% dplyr::select(-fustat) %>% dplyr::mutate( age_group = factor( dplyr::case_when( age <= 50 ~ "<= 50 years", age <= 60 ~ "<= 60 years", age <= 70 ~ "<= 70 years", TRUE ~ "> 70 years" ) ), rx = factor(rx), ecog.ps = factor(ecog.ps) ) %>% dplyr::select(age, age_group, everything()) %>% visR::get_tableone() # Examples using ADaM data # display patients in an analysis set adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(TRTA) %>% visR::get_tableone() ## display overall summaries for demog adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, RACE) %>% visR::get_tableone() ## By actual treatment adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, RACE, TRTA) %>% visR::get_tableone(strata = "TRTA") ## By actual treatment, without overall adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::get_tableone(strata = "TRTA", overall = FALSE)
This function takes the legend position and orientation, defined by the user and puts them into a list for ggplot2.
legendopts(legend_position = "right", legend_orientation = NULL)
legendopts(legend_position = "right", legend_orientation = NULL)
legend_position |
Default = "right". |
legend_orientation |
Default = NULL. |
List of legend options for ggplot2.
Render a previously created data.frame, tibble or tableone object to html, rtf or latex
render( data, title = "", datasource, footnote = "", output_format = "html", engine = "gt", download_format = c("copy", "csv", "excel") )
render( data, title = "", datasource, footnote = "", output_format = "html", engine = "gt", download_format = c("copy", "csv", "excel") )
data |
Input data.frame or tibble to visualize |
title |
Specify the title as a text string to be displayed in the rendered table. Default is no title. |
datasource |
String specifying the data source underlying the data set. Default is no title. |
footnote |
String specifying additional information to be displayed as a footnote alongside the data source and specifications of statistical tests. |
output_format |
Type of output that is returned, can be "html" or "latex". Default is "html". |
engine |
If "html" is selected as |
download_format |
Options formats generated for downloading the data. Default is a list "c('copy', 'csv', 'excel')". |
A table data structure with possible interactive functionality depending on the choice of the engine.
Provides stair-step values for ribbon plots, often using in
conjunction with ggplot2::geom_step()
.
The step ribbon can be added with stat_stepribbon()
or
identically with ggplot2::geom_ribbon(stat = "stepribbon")
stat_stepribbon( mapping = NULL, data = NULL, geom = "ribbon", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, direction = "hv", ... ) StatStepribbon
stat_stepribbon( mapping = NULL, data = NULL, geom = "ribbon", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, direction = "hv", ... ) StatStepribbon
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
which geom to use; defaults to " |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
direction |
|
... |
Other arguments passed on to |
An object of class StatStepRibbon
(inherits from Stat
, ggproto
, gg
) of length 3.
a ggplot
https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/9cFWHaH1CPs
# using ggplot2::geom_ribbon() survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) %>% survival::survfit0() %>% broom::tidy() %>% ggplot2::ggplot(ggplot2::aes(x = time, y = estimate, ymin = conf.low, ymax = conf.high)) + ggplot2::geom_step() + ggplot2::geom_ribbon(stat = "stepribbon", alpha = 0.2) # using stat_stepribbon() with the same result survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) %>% survival::survfit0() %>% broom::tidy() %>% ggplot2::ggplot(ggplot2::aes(x = time, y = estimate, ymin = conf.low, ymax = conf.high)) + ggplot2::geom_step() + visR::stat_stepribbon(alpha = 0.2)
# using ggplot2::geom_ribbon() survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) %>% survival::survfit0() %>% broom::tidy() %>% ggplot2::ggplot(ggplot2::aes(x = time, y = estimate, ymin = conf.low, ymax = conf.high)) + ggplot2::geom_step() + ggplot2::geom_ribbon(stat = "stepribbon", alpha = 0.2) # using stat_stepribbon() with the same result survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) %>% survival::survfit0() %>% broom::tidy() %>% ggplot2::ggplot(ggplot2::aes(x = time, y = estimate, ymin = conf.low, ymax = conf.high)) + ggplot2::geom_step() + visR::stat_stepribbon(alpha = 0.2)
Calculates several summary statistics. The summary statistics depend on the vector class
summarize_long(x) ## S3 method for class 'factor' summarize_long(x) ## S3 method for class 'integer' summarize_long(x) ## S3 method for class 'numeric' summarize_long(x) ## Default S3 method: summarize_long(x)
summarize_long(x) ## S3 method for class 'factor' summarize_long(x) ## S3 method for class 'integer' summarize_long(x) ## S3 method for class 'numeric' summarize_long(x) ## Default S3 method: summarize_long(x)
x |
an object |
A summarized version of the input.
This function creates summaries combines multiple summary measures in a single formatted string. Create variable summary for numeric variables. Calculates mean (standard deviation), median (IQR), min-max range and N/% missing elements for a numeric vector.
Create variable summary for integer variables Calculates mean (standard deviation), median (IQR), min-max range and N/% missing elements for a integer vector.
summarize_short(x) ## S3 method for class 'factor' summarize_short(x) ## S3 method for class 'numeric' summarize_short(x) ## S3 method for class 'integer' summarize_short(x) ## Default S3 method: summarize_short(x)
summarize_short(x) ## S3 method for class 'factor' summarize_short(x) ## S3 method for class 'numeric' summarize_short(x) ## S3 method for class 'integer' summarize_short(x) ## Default S3 method: summarize_short(x)
x |
a vector to be summarized |
A summarized less detailed version of the input.
The aim of Surv_CNSR()
is to map the inconsistency in convention between
the survival package and
CDISC ADaM ADTTE data model.
The function creates a survival object (e.g. survival::Surv()
) that
uses CDISC ADaM ADTTE coding conventions and converts the arguments to the
status/event variable convention used in the
survival package.
The AVAL
and CNSR
arguments are passed to
survival::Surv(time = AVAL, event = 1 - CNSR, type = "right", origin = 0)
.
Surv_CNSR(AVAL, CNSR)
Surv_CNSR(AVAL, CNSR)
AVAL |
The follow-up time. The follow-up time is assumed to originate from zero.
When no argument is passed, the default value is a column/vector named |
CNSR |
The censoring indicator where |
Object of class 'Surv'
The Surv_CNSR()
function creates a survival object utilizing the
expected data structure in the CDISC ADaM ADTTE data model,
mapping the CDISC ADaM ADTTE coding conventions with the expected
status/event variable convention used in the survival package—specifically,
the coding convention used for the status/event indicator.
The survival package expects the status/event indicator in the
following format: 0=alive
, 1=dead
. Other accepted choices are
TRUE
/FALSE
(TRUE = death
) or 1
/2
(2=death
).
A final but risky option is to omit the indicator variable, in which case
all subjects are assumed to have an event.
The CDISC ADaM ADTTE data model adopts a different coding convention for
the event/status indicator. Using this convention, the event/status variable
is named 'CNSR'
and uses the following coding: censor = 1
, status/event = 0
.
survival::Surv()
, estimate_KM()
# Use the `Surv_CNSR()` function with visR functions adtte %>% visR::estimate_KM(formula = visR::Surv_CNSR() ~ SEX) # Use the `Surv_CNSR()` function with functions from other packages as well survival::survfit(visR::Surv_CNSR() ~ SEX, data = adtte) survival::survreg(visR::Surv_CNSR() ~ SEX + AGE, data = adtte) %>% broom::tidy()
# Use the `Surv_CNSR()` function with visR functions adtte %>% visR::estimate_KM(formula = visR::Surv_CNSR() ~ SEX) # Use the `Surv_CNSR()` function with functions from other packages as well survival::survfit(visR::Surv_CNSR() ~ SEX, data = adtte) survival::survreg(visR::Surv_CNSR() ~ SEX + AGE, data = adtte) %>% broom::tidy()
Wrapper function to produce a summary table (i.e. Table One). Create and render a summary table for a dataset. A typical example of a summary table are "table one", the first table in an applied medical research manuscript.
Calculate summary statistics and present them in a formatted table
tableone( data, title, datasource, footnote = "", strata = NULL, overall = TRUE, summary_function = summarize_short, ... )
tableone( data, title, datasource, footnote = "", strata = NULL, overall = TRUE, summary_function = summarize_short, ... )
data |
The dataframe or tibble to visualize |
title |
Table title to include in the rendered table. Input is a text string. |
datasource |
String specifying the datasource underlying the data set |
footnote |
Table footnote to include in the rendered table. Input is a text string. |
strata |
Character vector with column names to use for stratification in the summary table. Default: NULL , which indicates no stratification. |
overall |
If TRUE, the summary statistics for the overall dataset are also calculated |
summary_function |
A function defining summary statistics for numeric and categorical values Pre-implemented functions are summarize_long and summarize_short |
... |
Pass options to render_table |
A table-like data structure, possibly interactive depending on the choice of the engine
tableone(engine = "gt")
tableone(engine = "DT")
tableone(engine = "kable")
tableone(engine = "kable", output_format = "latex")
# metadata for table t1_title <- "Cohort Summary" t1_ds <- "ADaM Interim Dataset for Time-to-Event Analysis" t1_fn <- "My table one footnote" ## table by treatment - without overall and render with GT tbl_gt <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "gt" ) ## table by treatment - without overall and render with DT tbl_DT <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "DT" ) ## table by treatment - without overall and render with kable tbl_kable_html <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "kable" ) ## table by treatment - without overall and render with kable as ## a latex table format rather than html tbl_kable_latex <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, output_format = "latex", engine = "kable" )
# metadata for table t1_title <- "Cohort Summary" t1_ds <- "ADaM Interim Dataset for Time-to-Event Analysis" t1_fn <- "My table one footnote" ## table by treatment - without overall and render with GT tbl_gt <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "gt" ) ## table by treatment - without overall and render with DT tbl_DT <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "DT" ) ## table by treatment - without overall and render with kable tbl_kable_html <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, engine = "kable" ) ## table by treatment - without overall and render with kable as ## a latex table format rather than html tbl_kable_latex <- adtte %>% dplyr::filter(SAFFL == "Y") %>% dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>% visR::tableone( strata = "TRTA", overall = FALSE, title = t1_title, datasource = t1_ds, footnote = t1_fn, output_format = "latex", engine = "kable" )
This function finds the left-hand sided symbol in a magrittr pipe and returns it as a character.
the_lhs()
the_lhs()
Left-hand sided symbol as string in the magrittr pipe.
https://github.com/tidyverse/magrittr/issues/115#issuecomment-173894787
blah <- function(x) the_lhs() adtte %>% blah()
blah <- function(x) the_lhs() adtte %>% blah()
S3 method for extended tidying of selected model outputs. Note
that the visR method retains the original nomenclature of the objects,
and adds the one of broom::tidy to ensure compatibility with tidy workflows.
The default method relies on broom::tidy
to return a tidied object
tidyme(x, ...) ## Default S3 method: tidyme(x, ...) ## S3 method for class 'survfit' tidyme(x, ...)
tidyme(x, ...) ## Default S3 method: tidyme(x, ...) ## S3 method for class 'survfit' tidyme(x, ...)
x |
An S3 object |
... |
other arguments passed on to the method |
Data frame containing all list elements of the S3 object as columns.
The column 'strata' is a factor to ensure that the strata are sorted
in agreement with the order in the survfit
object
## Extended tidying for a survfit object surv_object <- visR::estimate_KM(data = adtte, strata = "TRTA") tidied <- visR::tidyme(surv_object) ## Tidyme for non-included classes data <- cars lm_object <- stats::lm(data = cars, speed ~ dist) lm_tidied <- visR::tidyme(lm_object) lm_tidied
## Extended tidying for a survfit object surv_object <- visR::estimate_KM(data = adtte, strata = "TRTA") tidied <- visR::tidyme(surv_object) ## Tidyme for non-included classes data <- cars lm_object <- stats::lm(data = cars, speed ~ dist) lm_tidied <- visR::tidyme(lm_object) lm_tidied
S3 method for creating plots directly from objects using ggplot2
,
similar to the base R plot()
function.
Methods visr.survfit()
and visr.tidycuminc()
have been deprecated
in favor of ggsurvfit::ggsurvfit()
and ggsurvfit::ggcuminc()
, respectively.
visr.attrition()
function to draw a Consort flow diagram chart is currently being questioned.
visr(x, ...) ## Default S3 method: visr(x, ...) ## S3 method for class 'survfit' visr( x = NULL, x_label = NULL, y_label = NULL, x_units = NULL, x_ticks = NULL, y_ticks = NULL, fun = "surv", legend_position = "right", ... ) ## S3 method for class 'attrition' visr( x, description_column_name = "Criteria", value_column_name = "Remaining N", complement_column_name = "", box_width = 50, font_size = 12, fill = "white", border = "black", ... ) ## S3 method for class 'tidycuminc' visr( x = NULL, x_label = "Time", y_label = "Cumulative Incidence", x_units = NULL, x_ticks = pretty(x$tidy$time, 10), y_ticks = pretty(c(0, 1), 5), legend_position = "right", ... )
visr(x, ...) ## Default S3 method: visr(x, ...) ## S3 method for class 'survfit' visr( x = NULL, x_label = NULL, y_label = NULL, x_units = NULL, x_ticks = NULL, y_ticks = NULL, fun = "surv", legend_position = "right", ... ) ## S3 method for class 'attrition' visr( x, description_column_name = "Criteria", value_column_name = "Remaining N", complement_column_name = "", box_width = 50, font_size = 12, fill = "white", border = "black", ... ) ## S3 method for class 'tidycuminc' visr( x = NULL, x_label = "Time", y_label = "Cumulative Incidence", x_units = NULL, x_ticks = pretty(x$tidy$time, 10), y_ticks = pretty(c(0, 1), 5), legend_position = "right", ... )
x |
Object of class |
|||||||||||||||
... |
other arguments passed on to the method |
|||||||||||||||
x_label |
|
|||||||||||||||
y_label |
|
|||||||||||||||
x_units |
Unit to be added to the x_label (x_label (x_unit)). Default is NULL. |
|||||||||||||||
x_ticks |
Ticks for the x-axis. When not specified, the default will do a proposal. |
|||||||||||||||
y_ticks |
Ticks for the y-axis. When not specified,
the default will do a proposal based on the |
|||||||||||||||
fun |
Function that represents the scale of the estimate. The current options are:
|
|||||||||||||||
legend_position |
Specifies the legend position in the plot. Character values allowed are "top" "left" "bottom" "right". Numeric coordinates are also allowed. Default is "right". |
|||||||||||||||
description_column_name |
|
|||||||||||||||
value_column_name |
|
|||||||||||||||
complement_column_name |
|
|||||||||||||||
box_width |
|
|||||||||||||||
font_size |
|
|||||||||||||||
fill |
The color (string or hexcode) to use to fill the boxes in the flowchart |
|||||||||||||||
border |
The color (string or hexcode) to use for the borders of the boxes in the flowchart |
Object of class ggplot
and ggsurvplot
for survfit
objects.
# fit KM km_fit <- survival::survfit(survival::Surv(AVAL, 1 - CNSR) ~ TRTP, data = adtte) # plot curves using survival plot function plot(km_fit) # plot same curves using visR::visr plotting function visR::visr(km_fit) # estimate KM using visR wrapper survfit_object <- visR::estimate_KM(data = adtte, strata = "TRTP") # Plot survival probability visR::visr(survfit_object, fun = "surv") # Plot survival percentage visR::visr(survfit_object, fun = "pct") # Plot cumulative hazard visR::visr(survfit_object, fun = "cloglog") ## Create attrition attrition <- visR::get_attrition(adtte, criteria_descriptions = c( "1. Not in Placebo Group", "2. Be 75 years of age or older.", "3. White", "4. Female" ), criteria_conditions = c( "TRTP != 'Placebo'", "AGE >= 75", "RACE=='WHITE'", "SEX=='F'" ), subject_column_name = "USUBJID" ) ## Draw a CONSORT attrition chart without specifying extra text for the complement attrition %>% visr("Criteria", "Remaining N") ## Add detailed complement descriptions to the "exclusion" part of the CONSORT diagram # Step 1. Add new column to attrition dataframe attrition$Complement <- c( "NA", "Placebo Group", "Younger than 75 years", "Non-White", "Male" ) # Step 2. Define the name of the column in the call to the plotting function attrition %>% visr("Criteria", "Remaining N", "Complement") ## Styling the CONSORT flowchart # Change the fill and outline of the boxes in the flowchart attrition %>% visr("Criteria", "Remaining N", "Complement", fill = "lightblue", border = "grey") ## Adjust the font size in the boxes attrition %>% visr("Criteria", "Remaining N", font_size = 10)
# fit KM km_fit <- survival::survfit(survival::Surv(AVAL, 1 - CNSR) ~ TRTP, data = adtte) # plot curves using survival plot function plot(km_fit) # plot same curves using visR::visr plotting function visR::visr(km_fit) # estimate KM using visR wrapper survfit_object <- visR::estimate_KM(data = adtte, strata = "TRTP") # Plot survival probability visR::visr(survfit_object, fun = "surv") # Plot survival percentage visR::visr(survfit_object, fun = "pct") # Plot cumulative hazard visR::visr(survfit_object, fun = "cloglog") ## Create attrition attrition <- visR::get_attrition(adtte, criteria_descriptions = c( "1. Not in Placebo Group", "2. Be 75 years of age or older.", "3. White", "4. Female" ), criteria_conditions = c( "TRTP != 'Placebo'", "AGE >= 75", "RACE=='WHITE'", "SEX=='F'" ), subject_column_name = "USUBJID" ) ## Draw a CONSORT attrition chart without specifying extra text for the complement attrition %>% visr("Criteria", "Remaining N") ## Add detailed complement descriptions to the "exclusion" part of the CONSORT diagram # Step 1. Add new column to attrition dataframe attrition$Complement <- c( "NA", "Placebo Group", "Younger than 75 years", "Non-White", "Male" ) # Step 2. Define the name of the column in the call to the plotting function attrition %>% visr("Criteria", "Remaining N", "Complement") ## Styling the CONSORT flowchart # Change the fill and outline of the boxes in the flowchart attrition %>% visr("Criteria", "Remaining N", "Complement", fill = "lightblue", border = "grey") ## Adjust the font size in the boxes attrition %>% visr("Criteria", "Remaining N", font_size = 10)