Search code examples
rt-testgtsummary

Is there a way to conduct one tailed t-test using add_p or add_difference function in tbl_summary?


I wanted to include the results of one-tailed t-test using gtsummary. Is there a way to do this?


Solution

  • You can pass arguments to t.test() via the add_p(test.args=) argument. In your case, you'll want to pass the t.test(alternative = "less") (or "greater") argument. Example below!

    library(gtsummary)
    
    tbl <-
      trial %>%
      select(age, marker, trt) %>%
      tbl_summary(by = trt, missing = "no") %>%
      add_p(
        all_continuous() ~ "t.test",
        test.args = all_tests("t.test") ~ list(alternative = "less")
      )
    

    enter image description here Created on 2021-10-10 by the reprex package (v2.0.1)