I’m struggling to figure this out and it seems like there should be a way to do this, but I can’t find a solution online.
Basically, I have three gtsummary tbl_cross() objects, and I am going to merge them so they are side by side. Each table is doing a fisher exact test, so it has a p-value and I want to add an adjusted p-value (q-value) to account for the multiple testing.
The problem is, gtsummary doesn’t allow you to add a q-value AFTER the tables are merged, but if I add the q-value to each table BEFORE they’re merged, it thinks I am adjusting for a single test, and the q-value = p-value.
I looked into the add_q() documentation and while there is an option to change the type of correction, there’s no option to feed additional arguments into the method it is using to adjust. I see that when I use add_q() it prints out this message:
add_q: Adjusting p-values with
`stats::p.adjust(x$table_body$p.value, method = "holm")`
But I don’t know how to get in there to add the ‘n=3’ argument you would add to p.adjust() in this case. Example below.
library(gtsummary)
toy_1 <- data.frame(x1 = c("A","A", "B", "B", "B", "B", "C", "A", "C", "B"),
x2 = c("A", "B", "A", "B", "B", "A", "C", "B", "C", "B"),
x3 = c("B", "A", "C", "B", "B", "B", "A", "B", "C", "A"))
toy_2 <- data.frame(x1 = c("R","R", "G", "G", "G", "G", "G", "R", "G", "G"),
x2 = c("R", "G", "R", "R", "G", "R", "R", "G", "G", "G"),
x3 = c("G", "R", "R", "R", "G", "G", "G", "G", "G", "G"))
## Initiate empty list
list_out <- vector(mode = "list", length = 3)
for (i in 1:3){
## Combine
toy_combine <- data.frame(toy_1[,i], toy_2[,i])
## Rename
colnames(toy_combine) <- c("toy_1", "toy_2")
## Create table
tbl_toy <- tbl_cross(data = toy_combine,
row = toy_1,
col = toy_2,
missing_text = "Missing") |>
modify_header(label ~ "**toy_2**") |>
bold_labels() |>
add_p() |>
add_q(method = "holm")
## Store in list
list_out[[i]] <- tbl_toy
}
tbl_merge(tbls = list_out,
tab_spanner = colnames(toy_1))
This results in the following table:
enter image description here
If I remove the add_q() from the individual tables and instead put:
tbl_merge(tbls = list_out,
tab_spanner = colnames(toy_1)) |>
add_q(method = "holm")
I get the following error:
Error: There is no p-value column. `x$table_body` must have a column called 'p.value'
Any help?