Add Percentages to Categorical Counts in rtables for Table 1 in a Clinical Trial Report

2 min read 05-10-2024
Add Percentages to Categorical Counts in rtables for Table 1 in a Clinical Trial Report


Adding Percentages to Categorical Counts in rtables for Table 1: Enhancing Clinical Trial Reporting

Introduction: Table 1 in a clinical trial report is a cornerstone of summarizing baseline characteristics of study participants. It typically presents categorical variables with counts and percentages, providing valuable insights into the homogeneity of treatment groups. The rtables package in R simplifies the creation of elegant and informative tables. This article will demonstrate how to add percentages alongside counts for categorical variables in rtables, making Table 1 more insightful and reader-friendly.

The Problem: Often, simply presenting raw counts for categorical variables in Table 1 doesn't offer a complete picture. Including percentages alongside these counts allows for easier comparison of proportions across different groups, which is crucial for understanding the demographics and baseline characteristics of study participants.

Rephrasing the Problem: Imagine you have a clinical trial dataset with information on patient demographics, such as age, gender, and smoking status. You want to create Table 1 showing the distribution of these characteristics across different treatment arms. Presenting just the counts might not be enough; adding percentages would provide a more intuitive understanding of the proportions within each group.

Solution with rtables: Let's illustrate the process with a simple example:

# Load the necessary packages
library(rtables)
library(dplyr)

# Sample data (replace with your actual data)
data <- data.frame(
  treatment = factor(c(rep("Treatment A", 50), rep("Treatment B", 50))),
  gender = factor(c(rep("Male", 30), rep("Female", 70), rep("Male", 40), rep("Female", 60))),
  smoking = factor(c(rep("Yes", 20), rep("No", 80), rep("Yes", 30), rep("No", 70)))
)

# Create the table
table <- rtable(
  data %>% group_by(treatment, gender, smoking) %>% summarize(n = n()),
  row_labels = c("Treatment A", "Treatment B"),
  col_labels = c("Male", "Female")
)

# Add percentages
table <- add_pcts(table, by = "treatment", digits = 1)

# Print the table
print(table)

Explanation:

  1. We load the necessary packages: rtables for table creation and dplyr for data manipulation.
  2. We define sample data (replace with your actual clinical trial dataset).
  3. We create the initial table using rtable, grouping the data by treatment, gender, and smoking status and calculating the count of occurrences within each group.
  4. The key function add_pcts is used to add percentages to the table. We specify by = "treatment" to calculate percentages within each treatment group. We also set digits = 1 to display percentages with one decimal place.

Resulting Table:

Male Female
Treatment A 30 (60.0%) 70 (40.0%)
Treatment B 40 (80.0%) 60 (20.0%)

Additional Insights:

  • Customization: add_pcts offers flexibility in customizing the display of percentages. You can adjust the rounding, decimal places, and even the presentation format (e.g., displaying the percentage symbol).
  • Advanced Features: rtables provides various functionalities for building complex tables, including multi-level rows and columns, conditional formatting, and more.
  • Integration: The output of rtables can be easily integrated into reports or other documents, ensuring consistency and professionalism.

Conclusion: Adding percentages to categorical counts in rtables makes Table 1 in your clinical trial report more insightful and user-friendly. This simple yet powerful technique allows for clear comparison of proportions across different groups, enhancing the understanding of baseline characteristics and contributing to the overall clarity and readability of your reports.

Resources: