Merck / Merck/metalite.ae

format_ae_specific fails in single group tables

Open
#254 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
27
Forks
5
Avg merge
17h 4m
Merged PRs (30d)
4

Description

The function fails when producing a table with only a single group. For reproducibility see example code at the end.

This only fails when a total column is not included. I believe this is due to a larger edge case issue: when statistics are calculated they are stored as a matrix in the meta data, but if there is only a single group in the analysis R will default to storing them as a vector instead. The format_ae_specific function (and possibly others) then fail because they make use of apply, which requires a matrix. When 'total' is included in display it gives two identical groups, so a matrix is produced.

I am new to metalite, is there a preferred way of generating single group tables?

Example

adsl <- forestly::forestly_adsl
adae <- forestly::forestly_adae

# For the example, modify the treatment columns to only have a single group
adsl$TRT01A <- factor(
  adsl$TRT01A,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Blinded", "Blinded")
)
adae$TRTA <- factor(
  adae$TRTA,
  levels = c("Xanomeline Low Dose", "Placebo"),
  labels = c("Blinded", "Blinded")
)

analysis_plan <- metalite::plan(
  analysis = "ae_specific",
  population = "apat",
  observation = "wk12",
  parameter = "rel"
)

analysis_plan <- metalite::plan(
  analysis = "ae_specific",
  population = "apat",
  observation = "wk12",
  parameter = "rel"
)
meta <- metalite::meta_adam(observation = adae, population = adsl) |>
  metalite::define_plan(analysis_plan) |>
  metalite::define_population(
    name = "apat",
    var = c("USUBJID", "SAFFL", "TRT01A", "SITEID", "SEX", "RACE", "AGE"),
    group = "TRT01A",
    subset = SAFFL == "Y",
    label = "All Participants as Treated"
  ) |>
  metalite::define_observation(
    name = "wk12",
    var = c(
      "USUBJID", "SAFFL", "TRTA", "SEX", "AEDECOD", "AEBODSYS",
      "AEREL", "AESER", "AEOUT", "AEACN", "AESDTH", "ASTDT", "AENDT"
    ),
    group = "TRTA",
    subset = SAFFL == "Y",
    label = "Weeks 0 to 12"
  ) |>
  metalite::define_parameter(
    name = "rel",
    term1 = "Drug-Related",
    term2 = "",
    subset = AEREL %in% c("POSSIBLE", "PROBABLE"),
    var = "AEDECOD",
    soc = "AEBODSYS",
    label = "Drug-related AEs"
  ) |>
  metalite::define_analysis(
    name = "ae_specific",
    title = "Participants With Drug-Related Adverse Events"
  ) |>
  metalite::meta_build()

outdata <- prepare_ae_specific(meta,
                               population = "apat",
                               observation = "wk12",
                               parameter = "rel"
)

# works with total row included
tbl <- outdata |>
  format_ae_specific(display = c('n','prop','total'))

# fails when total row is excluded.
tbl <- outdata |>
  format_ae_specific(display = c('n','prop'))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied reproducible example and inspect format_ae_specific, using prepare_ae_specific as the preceding entry point. Compare the single-group output with and without the total display option, then verify that formatting succeeds when only n and prop are requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.