pharmaverse / pharmaverse/tern

[Feature Request]: different factor levels for different split contexts

Open
#824 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement low-priority sme
Dominant language
R
Stars
106
Forks
34
Avg merge
8d 9h
Merged PRs (30d)
6

Description

Feature description

similar to https://github.com/insightsengineering/chevron/pull/343 where different precisions are needed, we have similar cases that, when splitting by "parameters", the levels need to be adjusted.

library(dplyr)

data <- expand.grid(
  USUBJID = c("1", "2", "3"),
  ARM = c("arm a", "arm b"),
  PARAMCD = c("test a", "test b", "test c"),
  AVISIT = c("VISIT 1", "VISIT 2", "VISIT 3")
) %>%
mutate(
  AVALCAT = case_when(
    PARAMCD == "test a" ~ sample(c("high", "low"), size = n(), replace = TRUE),
    PARAMCD == "test b" ~ sample(c("normal", "abnormal"), size = n(), replace = TRUE),
    PARAMCD == "test c" ~ sample(c("high", "middle", "low"), size = n(), replace = TRUE),
    TRUE ~ sample(c("high", "low"), size = n(), replace = TRUE),
  )
) %>%
df_explicit_na

basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("PARAMCD") %>%
  split_rows_by("AVISIT") %>%
  summarize_vars("AVALCAT") %>%
  build_table(data)

even if we there are no actual categories in that parameter, the levels are there; pruning is removing all zeros so maybe not optimal if we want to keep some 0 count rows. Best if it could be achieved in analysis part.

Looping @barnett11 for your comments. This arise up when I review a template of egt05_qtcat_1 where Tim asks if by parameter analysis is possible

Code of Conduct
  • I agree to follow this project's Code of Conduct.
Contribution Guidelines
  • I agree to follow this project's Contribution Guidelines.
Security Policy
  • I agree to follow this project's Security Policy.

Contributor guide

Open the contributing guide

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 with the linked chevron pull request 343, then run the example using basic_table(), split_cols_by(), split_rows_by(), summarize_vars(), and build_table(). Define how factor levels should vary by PARAMCD while retaining selected zero-count rows, and verify the resulting table against the demonstrated data and egt05_qtcat_1 use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
analytics, data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.