results_pivot_longer {SimNPH}R Documentation

Functions for Plotting and Reporting Results

Description

Functions for Plotting and Reporting Results

Usage

results_pivot_longer(data, exclude_from_methods = c("descriptive"))

combined_plot(
  data,
  methods,
  xvars,
  yvar,
  facet_x_vars = c(),
  facet_y_vars = c(),
  split_var = 1,
  heights_plots = c(3, 1),
  scale_stairs = NULL,
  grid_level = 2,
  scales = "fixed",
  hlines = numeric(0),
  use_colours = NULL,
  use_shapes = NULL
)

Arguments

data

for results_pivot_longer: simulation result as retured by SimDesign, for combined_plot: simulation results in long format, as returned by results_pivot_longer.

exclude_from_methods

"methods" that should not be pivoted into long format

methods

methods to include in the plot

xvars

orderd vector of variable names to display on the x axis

yvar

variable name of the variable to be displayed on the y axis (metric)

facet_x_vars

vector of variable names to create columns of facets

facet_y_vars

vector of variable names to create rows of facets

split_var

where should the lines be split, see details

heights_plots

relative heights of the main plot and the stairs on the bottom

scale_stairs

this argument is deprecated and will be ignored

grid_level

depth of loops for which the grid-lines are drawn

scales

passed on to facet_grid

hlines

position of horizontal lines, passed as yintercept to geom_hline

use_colours

optional named vector of colours used in scale_colour_manual

use_shapes

optional named vector of shapes used in scale_shape_manual

Details

With exclude_from_methods descriptive statistics or results of reference methods can be kept as own columns and used like the columns of the simulation parameters.

use_colours and use_shapes both use the method variable in their respective aesthetics.

split_var break the lines after the 1st, 2nd, ... variable in xvars. Use 0 for one continuous line per method.

Value

dataset in long format with one row per method and scenario and one column per metric

a ggplot/patchwork object containing the plots

Functions

Examples


data("combination_tests_delayed")

combination_tests_delayed |>
  results_pivot_longer() |>
  head()


library("ggplot2")
library("patchwork")
data("combination_tests_delayed")

results_long <- results_pivot_longer(combination_tests_delayed)

# plot the rejection rate of two methods
combined_plot(
  results_long,
  c("logrank", "mwlrt", "maxcombo"),
  c("hr", "n_pat_design", "delay", "hazard_ctrl", "recruitment"),
  "rejection_0.025",
  grid_level=2
)

# use custom colour and shape scales
# this can be used to group methods by shape or colour
# this is also helpful if methods should have the same aesthetics across plots
my_colours <- c(
  logrank="black",
  mwlrt="blue",
  maxcombo="green"
)

my_shapes <- c(
  logrank=1,
  mwlrt=2,
  maxcombo=2
)

combined_plot(
  results_long,
  c("logrank", "mwlrt", "maxcombo"),
  c("hr", "n_pat_design", "delay", "hazard_ctrl", "recruitment"),
  "rejection_0.025",
  grid_level=2,
  use_colours = my_colours,
  use_shapes = my_shapes
)

# if one has a dataset of metadata with categories of methods
# one could uses those two definitions
# colours for methods, same shapes for methods of same category
metadata <- data.frame(
  method = c("logrank", "mwlrt", "maxcombo"),
  method_name = c("logrank test", "modestly weighed logrank test", "maxcombo test"),
  category = c("logrank test", "combination test", "combination test")
)

my_colours <- ggplot2::scale_colour_discrete()$palette(n=nrow(metadata)) |>
  sample() |>
  setNames(metadata$method)

my_shapes <- metadata$category |>
  as.factor() |>
  as.integer() |>
  setNames(metadata$method)

combined_plot(
  results_long,
  c("logrank", "mwlrt", "maxcombo"),
  c("hr", "n_pat_design", "delay", "hazard_ctrl", "recruitment"),
  "rejection_0.025",
  grid_level=2,
  use_colours = my_colours,
  use_shapes = my_shapes
)


[Package SimNPH version 0.5.5 Index]