0

My question can be conceptualized using the same sample data used for the tbl_summary trial dataset from the tutorial here: https://www.danieldsjoberg.com/gtsummary/articles/tbl_summary.html.

How would I calculate the mortality rate based on grade of tumor instead of calculating the incidence of grade I-III tumors? So far as I can find, there is not a way to calculate a custom statistic based on a third column, which is essentially what I am trying to do.

--- Edit ---

My input data has 3 columns - stent_type, success, stent_30. stent_type is either a category 0 or 1, success is either a 0 or 1, and stent_30 is either a 0 or 1 (basically was the stent placed before or after 30 days). I would like to create a 2x3 table with the percent/number of successfully placed stents for category 0 or 1 stents, along with a p-value comparing the two columns for stent_30. Something like this:

Stent < 30 Stent > 30 p-value
stent 0 75%(10) 70% (9) 0.1
stent 1 50% (6) 40% (2) 0.05

I'm basically having trouble because I'm not sure how to summarize a category based on 2 different categories (if that makes sense?)

1 Answer 1

0

You can do this with general tidyverse operations (group_by and summarise).

# Load the required libraries.

library(gtsummary)
library(tidyverse)

# Get the mortality counts.

mortality_counts <- trial %>%
  group_by(grade, death) %>%
  summarise(count = n()) %>%
  ungroup()

# Get the mortality proportions.

mortality_proportions <- mortality_counts %>%
  group_by(grade) %>%
  mutate(total = sum(count),
         proportion = count / total)

With the output of mortality_proportions as:

grade death count total proportion
I 0 35 68 0.5147059
I 1 33 68 0.4852941
II 0 32 68 0.4705882
II 1 36 68 0.5294118
III 0 21 64 0.3281250
III 1 43 64 0.6718750

If you wanted to make that clearer just to show the grade and proportions, you could do:

mortality_proportions %>%
  filter(death == 1) %>%
  select(grade, proportion) %>%
  mutate(proportion = round(proportion, 2))

For output:

grade proportion
I 0.49
II 0.53
III 0.67
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I guess I should have made it more clear in the initial question. This is very helpful but the comparison that I would like to make is to then compare death rates across drug A and drug B. With this approach it doesn't seem like that would be possible right?
Can you edit your question to include your desired output? So a table showing what the end result should look like, even if it has fake numbers.
Okay, I think you should ask this as a new question. The original question was about data from gtsummary but the edit is about a different dataset and now includes p-values. I feel like it's definitely possible to achieve this, but better as a new question after reading these links: (1) stackoverflow.com/help/minimal-reproducible-example and (2) stackoverflow.com/questions/5963269/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.