# Maraca Plots - Alternative Endpoints

#### Monika Huhn

#### 2025-11-20

The maraca package can also be used for hierarchical endpoints containing other type of endpoints than time-to-event and continuous. Currently binary endpoints are also supported with further type of endpoints under development

## Binary endpoints

### Last outcome

First we go through an example where the final outcome instead of being continuous, is a binary outcome. As an example, this could for example be weight loss above a certain threshold at the end of the study. The way the outcome should be included in the data is as a numeric vector with 1 for those patients that had the outcome and 0 for those that had not.

We do not have any example dataset with a final binary endpoint included in the package, so for this vignette we modify an existing dataset:

    data("hce_scenario_a")
    # Create data with binary version of continuous final endpoint
    bin_data <- hce_scenario_a
    # Index of all continuous outcome rows
    idx_cont <- bin_data$GROUP == "Continuous outcome"
    # Rename outcome
    bin_data[idx_cont,"GROUP"] <- "Binary outcome"
    # Binary version (>= 0/< 0)
    bin_data[idx_cont,"AVAL0"] <- bin_data[idx_cont,"AVAL0"] >= 0
    bin_data[idx_cont,"AVAL"] <- bin_data[idx_cont,"AVAL0"] +
      bin_data[idx_cont,"GROUPN"]
    head(bin_data)
    ##   SUBJID          GROUP GROUPN    AVAL0       AVAL    TRTP
    ## 1      1      Outcome I      0 120.4409   120.4409  Active
    ## 2      2 Binary outcome  40000   1.0000 40001.0000 Control
    ## 3      3 Binary outcome  40000   1.0000 40001.0000  Active
    ## 4      4      Outcome I      0 577.3114   577.3114 Control
    ## 5      5     Outcome II  10000 781.7581 10781.7581  Active
    ## 6      6    Outcome III  20000 985.0980 20985.0980 Control

If we now want to create a maraca object for this data, we need to slightly update the default code. By default, maraca expects the last outcome to be continuous. In order for the function to know that the last outcome is binary, we have to update the parameter `last_type`. The parameter currently accepts the inputs `"binary"` and `"continuous"`.

    column_names <- c(
        outcome = "GROUP",
        arm = "TRTP",
        value = "AVAL0"
    )

    step_outcomes <- c("Outcome I", "Outcome II",
                       "Outcome III", "Outcome IV")

    last_outcome <- "Binary outcome"

    arm_levels <- c(active = "Active",
                    control = "Control")

    mar <- maraca(
      bin_data, step_outcomes, last_outcome,
      arm_levels, column_names,
      fixed_followup_days = 3*365,
      compute_win_odds = TRUE,
      # Important change: Add information that last endpoint is
      # not continuous (the default)
      last_type = "binary"
    )

The maraca object can now be plotted. A binary endpoint is plotted as an ellipsis. The point in the middle of the ellipsis indicates the proportion that has met the binary endpoint. The width of the ellipsis (x-axis range) shows the confidence interval. Specifying `vline_type = "mean"` (the default) will add vertical lines indicating the proportions in each treatment group for easier readibility. Note that `vline_type = "median"` (the default for continuous endpoints) will result in an error. The same is true for setting `density_plot_type` to anything other than `"default"`.

    plot(mar)

### Step outcome

What if the binary outcome is not the last outcome of the hierarchical endpoint but rather one (or several) of the previous outcomes? So rather than solely having time-to-event endpoints within the step function part of the plot, we also have at least one binary (so not time depending) variable. To include a binary variable, we expect the data for this outcome to include only patients that had the outcome and they all have to have the original analysis value 1.

Let’s create a dataset with 2 binary outcomes.

    data("hce_scenario_a")
    # Create data with binary version of continuous final endpoint
    bin_data2 <- hce_scenario_a
    # Index of all continuous outcome rows
    idx_bin <- bin_data2$GROUP %in% c("Outcome III", "Outcome IV")
    # Binary version (>= 0/< 0), coded as 1
    bin_data2[idx_bin,"AVAL0"] <- bin_data2[idx_bin,"AVAL0"] >= 500
    bin_data2[idx_bin,"AVAL"] <- bin_data2[idx_bin,"AVAL0"] +
      bin_data2[idx_bin,"GROUPN"]
    # Remove 0 rows (only include patients that had the outcome)
    bin_data2 <- bin_data2[bin_data2$AVAL0 != 0,]
    head(bin_data2)
    ##   SUBJID              GROUP GROUPN      AVAL0       AVAL    TRTP
    ## 1      1          Outcome I      0 120.440921   120.4409  Active
    ## 2      2 Continuous outcome  40000   3.345229 40003.3452 Control
    ## 3      3 Continuous outcome  40000  22.802615 40022.8026  Active
    ## 4      4          Outcome I      0 577.311386   577.3114 Control
    ## 5      5         Outcome II  10000 781.758081 10781.7581  Active
    ## 6      6        Outcome III  20000   1.000000 20001.0000 Control

Again we need to slightly update the default code if we want to create a maraca object for this data. By default, maraca expects all the step outcomes to be time-to-event endpoints. In order for the function to know that there are binary outcomes, we have to update the parameter `step_types`. The parameter currently accepts the inputs `"binary"` and `"tte"`. If all the step outcomes are of the same type, the user can give the type as a string (such as by default `step_types = "tte"`). If there are different endpoint types, then the user has to provide a vector with one element for each step outcome. Similarly, the fixed-follow up time can be given as a single number or a vector. Note that the fixed-follow-up time is only needed for time-to-event endpoints, so if providing a vector then it should contain one value for each time-to-event endpoint.

    column_names <- c(
        outcome = "GROUP",
        arm = "TRTP",
        value = "AVAL0"
    )

    step_outcomes <- c("Outcome I", "Outcome II",
                       "Outcome III", "Outcome IV")

    last_outcome <- "Continuous outcome"

    arm_levels <- c(active = "Active",
                    control = "Control")

    mar <- maraca(
      bin_data2, step_outcomes, last_outcome,
      arm_levels, column_names,
      fixed_followup_days = 3*365,
      compute_win_odds = TRUE,
      # Important change: Add information that last endpoint is
      # not continuous (the default)
      step_types = c("tte","tte","binary","binary")
    )

Again, we can plot the final object.

    plot(mar)

As with all maraca objects, the different plotting parameters can be used.

    plot(mar, continuous_grid_spacing_x = 20,
         theme = "color1")

Also, the win odds plots can be created as usual.

    component_plot(mar,
         theme = "color2")

    cumulative_plot(mar,
         theme = "color1")