Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_p() t.test method change rendering issue #1209

Closed
postgres-newbie opened this issue Apr 20, 2022 · 6 comments
Closed

add_p() t.test method change rendering issue #1209

postgres-newbie opened this issue Apr 20, 2022 · 6 comments
Milestone

Comments

@postgres-newbie
Copy link

When generating a tbl_summary, if an add_p(test = everything() ~ "t.test") was used and later the tbl_summary object (let's call it: sample_tbl_summary) was run through the statement:
add_p(sample_tbl_summary, test = everything() ~ aov),
the output in viewer still displays the p-values from the t.test instead of updating them to those obtained from an ANOVA.

@ddsjoberg
Copy link
Owner

Thank you for your post. Please update your post with a reproducible example, aka a reprex. A reprex includes both data and code I can run on my machine that replicates the issue you're reporting. Take just a few minutes to review reprex.tidyverse.org for detailed instructions on how to create a reprex.

I am going to go ahead and close this issue for now. But please do re-open the issue after you've added your reproducible example.

@postgres-newbie
Copy link
Author

Here's some reproducible code:

library(gtsummary);
library(gt);
library(survival)
library(dplyr);
library(stringr);
library(purrr);
library(forcats);
library(tidyr)

save_tbl_summary<-trial %>%
select(response, age, grade) %>%
mutate(response = factor(response, labels = c("No Tumor Response", "Tumor Responded"))) %>%
tbl_summary(
by = response,
missing = "no",
label = list(age ~ "Patient Age", grade ~ "Tumor Grade")
) %>%
add_p(pvalue_fun = ~style_pvalue(.x, digits = 2)) %>%
add_q()

The p-value that gets rendered is >0.9 when it is 0.813

add_p(save_tbl_summary, test = everything() ~ "aov")

Here is the p-value when calculated using "aov"

aov(as.numeric(as.factor(grade)) ~ as.factor(response),
data = subset(trial, subset= response %in% c(1, 0))) %>% summary()

Df Sum Sq Mean Sq F value Pr(>F)

as.factor(response) 1 0.04 0.0383 0.056 0.813 # The p-value that gets rendered is >0.9 when it is 0.813

Residuals 191 129.88 0.6800

Here's the code to show that the chisel.test p-value gets reported which is 0.93

chisq.test(x = trial$response[which(trial$response %in% c(0, 1))],
y = trial$grade[which(trial$response%in% c(0, 1))])

Pearson's Chi-squared test

data: trial$response[which(trial$response %in% c(0, 1))] and trial$grade[which(trial$response %in% c(0, 1))]

X-squared = 0.15014, df = 2, p-value = 0.9277

@ddsjoberg ddsjoberg reopened this Apr 20, 2022
@ddsjoberg
Copy link
Owner

Thanks for adding the example.

I wasn't expecting users to run add_p() multiple times on the same table. It looks like I need add a check that the p-value column is not already present, and if it is then throw an error.

@postgres-newbie
Copy link
Author

Yes, an error message would be nice or what would be better is to allow for the p-values to be overwritten in the rendered version with the new method.

@ddsjoberg
Copy link
Owner

you can create another table and merge them together with tbl_merge(). We rely on the column names, so cannot allow more than one run without causing issues downstream

@ddsjoberg ddsjoberg added this to the v1.5.3 milestone Apr 20, 2022
@ddsjoberg
Copy link
Owner

error messaging added to main branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants