Package 'maraca'

Title: The Maraca Plot: Visualization of Hierarchical Composite Endpoints in Clinical Trials
Description: Library that supports visual interpretation of hierarchical composite endpoints (HCEs). HCEs are complex constructs used as primary endpoints in clinical trials, combining outcomes of different types into ordinal endpoints, in which each patient contributes the most clinically important event (one and only one) to the analysis. See Karpefors M et al. (2022) <doi:10.1177/17407745221134949>.
Authors: Martin Karpefors [aut] , Samvel B. Gasparyan [aut] , Stefano Borini [ctb], Monika Huhn [aut, cre]
Maintainer: Monika Huhn <[email protected]>
License: Apache License (>= 2)
Version: 0.7
Built: 2024-11-13 04:45:04 UTC
Source: https://github.com/astrazeneca/maraca

Help Index


Function to create a plot showing the components used in calculating win odds (wins and ties) separately for each outcome for a hierarchical endpoint.

Description

Implemented for objects of type 'maraca' and 'hce'.

Usage

component_plot(x, ...)

Arguments

x

an object of S3 class 'maraca' or 'hce'.

...

further arguments to be passed to the object-specific functions


Generic function to create a plot showing the components used in calculating win odds (wins and ties) separately for each outcome directly from an hce object. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Description

Generic function to create a plot showing the components used in calculating win odds (wins and ties) separately for each outcome directly from an hce object. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Usage

## S3 method for class 'hce'
component_plot(
  x,
  step_outcomes = NULL,
  last_outcome = "C",
  arm_levels = c(active = "A", control = "P"),
  fixed_followup_days = NULL,
  theme = "maraca",
  lowerBetter = FALSE,
  ...
)

Arguments

x

an object of S3 class 'hce'.

step_outcomes

A vector of strings containing the outcome labels for all outcomes displayed as part of the step function on the left side of the plot. The order is kept for the plot. By default (when set to NULL) this is automatically updated by taking the non-continuous outcomes from the GROUP variable in alphabetical order.

last_outcome

A single string containing the last outcome label displayed on the right side of the plot. Default value "C".

arm_levels

A named vector of exactly two strings, mapping the values used for the active and control arms to the values used in the data. The names must be "active" and "control" in this order. Note that this parameter only need to be specified if you have labels different from "active" and "control".

fixed_followup_days

Not needed if HCE object contains information on fixed follow-up days in the study (column PADY or TTEfixed, depending on hce version). Otherwise, this argument must be specified. Note: If argument is specified and HCE object contains PADY or TTEfixed column, then fixed_followup_days argument is used.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Plotting win odds".

lowerBetter

Flag for the final outcome variable, indicating if lower values are considered better/advantageous. This flag is need to make sure the win odds are calculated correctly. Default value is FALSE, meaning higher values are considered advantageous.

...

not used

Value

Component plot as a ggplot2 object.

Examples

Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1)
Rates_P <- c(2.47, 2.24, 2.9, 4, 6)
hce_dat <- hce::simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P,
             CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3,
             seed = 31337)

component_plot(hce_dat)

Generic function to create a plot showing the components used in calculating win odds (wins and ties) separately for each outcome directly from a maraca object. Note that for this plot, when creating the maraca object using the maraca() function, the argument "compute_win_odds" has to be set to TRUE. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Description

Generic function to create a plot showing the components used in calculating win odds (wins and ties) separately for each outcome directly from a maraca object. Note that for this plot, when creating the maraca object using the maraca() function, the argument "compute_win_odds" has to be set to TRUE. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Usage

## S3 method for class 'maraca'
component_plot(x, theme = "maraca", ...)

Arguments

x

an object of S3 class 'maraca'.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Plotting win odds".

...

not used

Value

Component plot as a ggplot2 object.

Examples

data(hce_scenario_a)

maraca_dat <- maraca(data = hce_scenario_a,
                     step_outcomes = c("Outcome I", "Outcome II",
                                      "Outcome III", "Outcome IV"),
                     last_outcome = "Continuous outcome",
                     fixed_followup_days = 3 * 365,
                     column_names = c(outcome = "GROUP",
                                      arm = "TRTP",
                                      value = "AVAL0"),
                     arm_levels = c(active = "Active",
                                    control = "Control"),
                     compute_win_odds = TRUE
                     )

component_plot(maraca_dat)

Function to create a plot showing the components used in calculating win odds (wins and ties) cumulated for all outcomes for a hierarchical endpoint.

Description

Implemented for objects of type 'maraca' and 'hce'.

Usage

cumulative_plot(x, ...)

Arguments

x

an object of S3 class 'maraca' or 'hce'.

...

further arguments to be passed to the object-specific functions


Generic function to create a plot showing the components used in calculating win odds (wins and ties) cumulated for all outcomes directly from an hce object. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Description

Generic function to create a plot showing the components used in calculating win odds (wins and ties) cumulated for all outcomes directly from an hce object. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Usage

## S3 method for class 'hce'
cumulative_plot(
  x,
  step_outcomes = NULL,
  last_outcome = "C",
  arm_levels = c(active = "A", control = "P"),
  fixed_followup_days = NULL,
  theme = "maraca",
  include = c("win odds", "win ratio"),
  reverse = FALSE,
  lowerBetter = FALSE,
  ...
)

Arguments

x

an object of S3 class 'hce'.

step_outcomes

A vector of strings containing the outcome labels for all outcomes displayed as part of the step function on the left side of the plot. The order is kept for the plot. By default (when set to NULL) this is automatically updated by taking the non-continuous outcomes from the GROUP variable in alphabetical order.

last_outcome

A single string containing the last outcome label displayed on the right side of the plot. Default value "C".

arm_levels

A named vector of exactly two strings, mapping the values used for the active and control arms to the values used in the data. The names must be "active" and "control" in this order. Note that this parameter only need to be specified if you have labels different from "active" and "control".

fixed_followup_days

Not needed if HCE object contains information on fixed follow-up days in the study (column PADY or TTEfixed, depending on hce version). Otherwise, this argument must be specified. Note: If argument is specified and HCE object contains PADY or TTEfixed column, then fixed_followup_days argument is used.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Plotting win odds".

include

Vector or single string indicating which statistics to include in the right hand side plot. Acceptable values are "win odds" and/or "win ratio". Default is c("win odds", "win ratio").

reverse

Flag indicating if the cumulated outcomes should be displayed in order from top to bottom (FALSE, the default) or in reverse (TRUE).

lowerBetter

Flag for the final outcome variable, indicating if lower values are considered better/advantageous. This flag is need to make sure the win odds are calculated correctly. Default value is FALSE, meaning higher values are considered advantageous.

...

not used

Value

Cumulative plot as a patchwork list. Individual plots can be accessed like list items (plot[[1]] and plot[[2]]).

Examples

Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1)
Rates_P <- c(2.47, 2.24, 2.9, 4, 6)
hce_dat <- hce::simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P,
             CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3,
             seed = 31337)

cumulative_plot(hce_dat)

Generic function to create a plot showing the components used in calculating win odds (wins and ties) cumulated for all outcomes directly from a maraca object. Note that for this plot, when creating the maraca object using the maraca() function, the argument "compute_win_odds" has to be set to TRUE. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Description

Generic function to create a plot showing the components used in calculating win odds (wins and ties) cumulated for all outcomes directly from a maraca object. Note that for this plot, when creating the maraca object using the maraca() function, the argument "compute_win_odds" has to be set to TRUE. Check the vignette "Maraca Plots - Plotting win odds" for more details.

Usage

## S3 method for class 'maraca'
cumulative_plot(
  x,
  theme = "maraca",
  include = c("win odds", "win ratio"),
  reverse = FALSE,
  ...
)

Arguments

x

an object of S3 class 'maraca'.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Plotting win odds".

include

Vector or single string indicating which statistics to include in the right hand side plot. Acceptable values are "win odds" and/or "win ratio". Default is c("win odds", "win ratio").

reverse

Flag indicating if the cumulated outcomes should be displayed in order from top to bottom (FALSE, the default) or in reverse (TRUE).

...

not used

Value

Cumulative plot as a patchwork list. Individual plots can be accessed like list items (plot[[1]] and plot[[2]]).

Examples

data(hce_scenario_a)

maraca_dat <- maraca(data = hce_scenario_a,
                     step_outcomes = c("Outcome I", "Outcome II",
                                      "Outcome III", "Outcome IV"),
                     last_outcome = "Continuous outcome",
                     fixed_followup_days = 3 * 365,
                     column_names = c(outcome = "GROUP",
                                      arm = "TRTP",
                                      value = "AVAL0"),
                     arm_levels = c(active = "Active",
                                    control = "Control"),
                     compute_win_odds = TRUE
                     )

cumulative_plot(maraca_dat)

Example HCE scenario A.

Description

This is example data frame containing the example for scenario A.

Usage

data(hce_scenario_a)

Format

A data frame with 1000 rows.

SUBJID

The patient identifier

GROUP

Which type of outcome the row belongs to

GROUPN

Not required for computation. The group as an arbitrary numerical value

AVAL0

Contains both the time-to-event data for hard outcomes and the continuous data for the continuous outcome

AVAL

Not required for computation. Create an ordered sequence of values where the AVAL0 value associated with the patient is offset by GROUPN

TRTP

Treatment group


Example HCE scenario B.

Description

This is example data frame containing the example for scenario B.

Usage

data(hce_scenario_b)

Format

A data frame with 1000 rows.

SUBJID

The patient identifier

GROUP

Which type of outcome the row belongs to

GROUPN

Not required for computation. The group as an arbitrary numerical value

AVAL0

Contains both the time-to-event data for hard outcomes and the continuous data for the continuous outcome

AVAL

Not required for computation. Create an ordered sequence of values where the AVAL0 value associated with the patient is offset by GROUPN

TRTP

Treatment group


Example HCE scenario C.

Description

This is example data frame containing the example for scenario C.

Usage

data(hce_scenario_c)

Format

A data frame with 1000 rows.

SUBJID

The patient identifier

GROUP

Which type of outcome the row belongs to

GROUPN

Not required for computation. The group as an arbitrary numerical value

AVAL0

Contains both the time-to-event data for hard outcomes and the continuous data for the continuous outcome

AVAL

Not required for computation. Create an ordered sequence of values where the AVAL0 value associated with the patient is offset by GROUPN

TRTP

Treatment group


Example HCE scenario D.

Description

This is example data frame containing the example for scenario D.

Usage

data(hce_scenario_d)

Format

A data frame with 1000 rows.

SUBJID

The patient identifier

GROUP

Which type of outcome the row belongs to

GROUPN

Not required for computation. The group as an arbitrary numerical value

AVAL0

Contains both the time-to-event data for hard outcomes and the continuous data for the continuous outcome

AVAL

Not required for computation. Create an ordered sequence of values where the AVAL0 value associated with the patient is offset by GROUPN

TRTP

Treatment group


Example HCE scenario KCCQ3.

Description

This is example data frame containing the example for scenario KCCQ3.

Usage

data(hce_scenario_kccq3)

Format

A data frame with 5000 rows.

SUBJID

The patient identifier

GROUP

Which type of outcome the row belongs to

GROUPN

Not required for computation. The group as an arbitrary numerical value

AVAL0

Contains both the time-to-event data for hard outcomes and the continuous data for the continuous outcome

AVAL

Not required for computation. Create an ordered sequence of values where the AVAL0 value associated with the patient is offset by GROUPN

TRTP

Treatment group

HFHT

Not needed

SEED

Not needed


maraca package.

Description

Creates the maraca analysis object as an S3 object of class 'maraca'.

Usage

maraca(
  data,
  step_outcomes,
  last_outcome,
  arm_levels = c(active = "active", control = "control"),
  column_names = c(outcome = "outcome", arm = "arm", value = "value"),
  fixed_followup_days = NULL,
  compute_win_odds = FALSE,
  step_types = "tte",
  last_type = "continuous",
  lowerBetter = FALSE,
  tte_outcomes = lifecycle::deprecated(),
  continuous_outcome = lifecycle::deprecated()
)

## S3 method for class 'maraca'
print(x, ...)

Arguments

data

A data frame with columns for the following information: - outcome column, containing the time-to-event and continuous labels - arm column, containing the arm a given row belongs to. - value column, containing the values.

step_outcomes

A vector of strings containing the outcome labels for all outcomes displayed as part of the step function on the left side of the plot. The order is kept for the plot.

last_outcome

A single string containing the last outcome label displayed on the right side of the plot.

arm_levels

A named vector of exactly two strings, mapping the values used for the active and control arms to the values used in the data. The names must be "active" and "control" in this order. Note that this parameter only need to be specified if you have labels different from "active" and "control".

column_names

A named vector to map the outcome, arm, value to the associated column names in the data. The vector names must match in order "outcome", "arm", and "value". Note that this parameter only need to be specified if you have column names different from the ones above.

fixed_followup_days

A mandatory specification of the fixed follow-up days in the study. Can be a single integer value for all tte-outcomes or a vector with one integer value per tte-outcome.

compute_win_odds

If TRUE compute the win odds, otherwise (default) don't compute them.

step_types

The type of each outcome in the step_outcomes vector. Can be a single string (if all outcomes of same type) or a vector of same length as step_outcomes. Possible values in the vector are "tte" (default) or "binary".

last_type

A single string giving the type of the last outcome. Possible values are "continuous" (default), "binary" or "multinomial".

lowerBetter

Flag for the final outcome variable, indicating if lower values are considered better/advantageous. This flag is need to make sure the win odds are calculated correctly. Default value is FALSE, meaning higher values are considered advantageous.

tte_outcomes

Deprecated and substituted by the more general 'step_outcomes'. A vector of strings containing the time-to-event outcome labels. The order is kept for the plot.

continuous_outcome

Deprecated and substituted by the more general 'last_outcome'. A single string containing the continuous outcome label.

x

an object of class maraca

...

further arguments passed to or from other methods.

Value

An object of class 'maraca'. The object information must be considered private.

Examples

data(hce_scenario_a)
hce_test <- maraca(
  data = hce_scenario_a,
  step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
  last_outcome = "Continuous outcome",
  fixed_followup_days = 3 * 365,
  column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
  arm_levels = c(active = "Active", control = "Control"),
  compute_win_odds = TRUE
)

Creates and returns the plot of the maraca data.

Description

Creates and returns the plot of the maraca data.

Usage

plot_maraca(
  obj,
  continuous_grid_spacing_x = NULL,
  trans = c("identity", "log", "log10", "sqrt", "reverse")[1],
  density_plot_type = c("default", "violin", "box", "scatter")[1],
  vline_type = NULL,
  theme = "maraca"
)

Arguments

obj

an object of S3 class 'maraca'

continuous_grid_spacing_x

The spacing of the x grid to use for the continuous section of the plot.

trans

the transformation to apply to the x-axis scale for the last outcome. Possible values are "identity", "log" (only for continuous endpoint), "log10" (only for continuous endpoint), "sqrt" (only for continuous endpoint) and "reverse". The default value is "identity".

density_plot_type

which type of plot to display in the continuous part of the plot. Options are "default", "violin", "box", "scatter".

vline_type

what the vertical dashed line should represent. Accepts "median" (only for continuous last endpoint), "mean", "none" and NULL (default). By default (vline_type = NULL), vline_type will be set to "median" for a continuous last endpoint and to "mean" for a binary last endpoint.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "maraca_old", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Themes and Styling".

Value

a ggplot2 object of the data. This function will not render the plot immediately. You have to print() the returned object for it to be displayed.

Examples

data(hce_scenario_a)
hce_test <- maraca(
  data = hce_scenario_a,
  step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
  last_outcome = "Continuous outcome",
  fixed_followup_days = 3 * 365,
  column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
  arm_levels = c(active = "Active", control = "Control"),
  compute_win_odds = TRUE
)
plot <- plot_maraca(hce_test)

Generic function to plot the hce object using plot().

Description

Generic function to plot the hce object using plot().

Usage

## S3 method for class 'hce'
plot(
  x,
  step_outcomes = NULL,
  last_outcome = "C",
  arm_levels = c(active = "A", control = "P"),
  continuous_grid_spacing_x = 10,
  trans = c("identity", "log", "log10", "sqrt", "reverse")[1],
  density_plot_type = c("default", "violin", "box", "scatter")[1],
  vline_type = NULL,
  fixed_followup_days = NULL,
  compute_win_odds = FALSE,
  step_types = "tte",
  last_type = "continuous",
  theme = "maraca",
  lowerBetter = FALSE,
  tte_outcomes = lifecycle::deprecated(),
  continuous_outcome = lifecycle::deprecated(),
  ...
)

Arguments

x

an object of S3 class 'hce'.

step_outcomes

A vector of strings containing the outcome labels for all outcomes displayed as part of the step function on the left side of the plot. The order is kept for the plot. By default (when set to NULL) this is automatically updated by taking the non-continuous outcomes from the GROUP variable in alphabetical order.

last_outcome

A single string containing the last outcome label displayed on the right side of the plot. Default value "C".

arm_levels

A named vector of exactly two strings, mapping the values used for the active and control arms to the values used in the data. The names must be "active" and "control" in this order. Note that this parameter only need to be specified if you have labels different from "active" and "control".

continuous_grid_spacing_x

The spacing of the x grid to use for the continuous section of the plot.

trans

the transformation to apply to the x-axis scale for the last outcome. Possible values are "identity", "log" (only for continuous endpoint), "log10" (only for continuous endpoint), "sqrt" (only for continuous endpoint) and "reverse". The default value is "identity".

density_plot_type

The type of plot to use to represent the density. Accepts "default", "violin", "box" and "scatter".

vline_type

what the vertical dashed line should represent. Accepts "median" (only for continuous last endpoint), "mean", "none" and NULL (default). By default (vline_type = NULL), vline_type will be set to "median" for a continuous last endpoint and to "mean" for a binary last endpoint.

fixed_followup_days

Not needed if HCE object contains information on fixed follow-up days in the study (column PADY or TTEfixed, depending on hce version). Otherwise, this argument must be specified to give the fixed follow-up days in the study. Can be a single integer value for all tte-outcomes or a vector with one integer value per tte-outcome. Note: If argument is specified and HCE object also contains PADY or TTEfixed column, then fixed_followup_days argument is used.

compute_win_odds

If TRUE compute the win odds, otherwise (default) don't compute them.

step_types

The type of each outcome in the step_outcomes vector. Can be a single string (if all outcomes of same type) or a vector of same length as step_outcomes. Possible values in the vector are "tte" (default) or "binary".

last_type

A single string giving the type of the last outcome. Possible values are "continuous" (default), "binary" or "multinomial".

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "maraca_old", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Themes and Styling". [companion vignette for package users](themes.html)

lowerBetter

Flag for the final outcome variable, indicating if lower values are considered better/advantageous. This flag is need to make sure the win odds are calculated correctly. Default value is FALSE, meaning higher values are considered advantageous.

tte_outcomes

Deprecated and substituted by the more general 'step_outcomes'. A vector of strings containing the time-to-event outcome labels. The order is kept for the plot.

continuous_outcome

Deprecated and substituted by the more general 'last_outcome'. A single string containing the continuous outcome label.

...

not used

Value

Returns ggplot2 plot of the hce object.

Examples

Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1)
Rates_P <- c(2.47, 2.24, 2.9, 4, 6)
hce_dat <- hce::simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P,
             CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3,
             seed = 31337)
plot(hce_dat)
plot(hce_dat, fixed_followup_days = 3 * 365)

Generic function to plot the maraca object using plot().

Description

Generic function to plot the maraca object using plot().

Usage

## S3 method for class 'maraca'
plot(
  x,
  continuous_grid_spacing_x = 10,
  trans = c("identity", "log", "log10", "sqrt", "reverse")[1],
  density_plot_type = c("default", "violin", "box", "scatter")[1],
  vline_type = NULL,
  theme = "maraca",
  ...
)

Arguments

x

An object of S3 class 'maraca'.

continuous_grid_spacing_x

The spacing of the x grid to use for the continuous section of the plot.

trans

the transformation to apply to the x-axis scale for the last outcome. Possible values are "identity", "log" (only for continuous endpoint), "log10" (only for continuous endpoint), "sqrt" (only for continuous endpoint) and "reverse". The default value is "identity".

density_plot_type

The type of plot to use to represent the density. Accepts "default", "violin", "box" and "scatter".

vline_type

what the vertical dashed line should represent. Accepts "median" (only for continuous last endpoint), "mean", "none" and NULL (default). By default (vline_type = NULL), vline_type will be set to "median" for a continuous last endpoint and to "mean" for a binary last endpoint.

theme

Choose theme to style the plot. The default theme is "maraca". Options are "maraca", "maraca_old", "color1", "color2" and none". For more details, check the vignette called "Maraca Plots - Themes and Styling".

...

not used

Value

Returns ggplot2 plot of the maraca object.

Examples

data(hce_scenario_a)
hce_test <- maraca(
  data = hce_scenario_a,
  step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
  last_outcome = "Continuous outcome",
  fixed_followup_days = 3 * 365,
  column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
  arm_levels = c(active = "Active", control = "Control"),
  compute_win_odds = TRUE
)
plot(hce_test)

Generic function to generate validation data for the maraca plot object.

Description

This will produce the 4 validation datasets.

Usage

validate_maraca_plot(x, ...)

Arguments

x

An object of S3 class 'maracaPlot'.

...

Not used.

Value

Creates a list of datasets for validation purposes.

Examples

data(hce_scenario_a)
hce_test <- maraca(
  data = hce_scenario_a,
  step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
  last_outcome = "Continuous outcome",
  fixed_followup_days = 3 * 365,
  column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
  arm_levels = c(active = "Active", control = "Control"),
  compute_win_odds = TRUE
)
p <- plot(hce_test)
validate_maraca_plot(p)