0

Trying to create a table that resembles below and would like to obtain a p value (using chi square testing, have approx 34000 patients and there is some missing data which I would like to exclude in analysis and also to include in the table below.

Ethnicity A Ethnicity B Ethnicity C
CD_loc 1 456 555 348
CD_loc 2 452 158 257
CD_loc 3 50 18 58
Missing 3 4 8
  meta1_CD %>%
  select(ethnicity,CD_loc) %>%
  tbl_summary(
    by = ethnicity,
    statistic = list(all_continuous() ~ "{mean} ({sd})",
                     all_categorical() ~ "{n} ({p}%)"),
    digits = all_continuous() ~ 1,
    type = all_categorical() ~ "categorical",
    missing_text = "Missing") %>%
  add_p()

but then I get the following error message "There was an error in 'add_p()/add_difference()' for variable 'CD_loc', p-value omitted: Error in stats::fisher.test(structure(c(6L, 1L, 5L, 1L, 1L, 3L, 1L, 1L, : Bug in fexact3, it[i=4]=0: negative key -1556839370 (kyy=13301)"

Any ideas? Would be very grateful!

  • Does this answer your question? [error in add\_p()' for variable X and test 'fisher.test', p-value omitted](https://stackoverflow.com/questions/61360954/error-in-add-p-for-variable-x-and-test-fisher-test-p-value-omitted) –  Jun 16 '22 at 09:40
  • It looks like Fishers Exact test is not calculable with your data. You can try updating to the chi-squared test or one of the others. https://www.danieldsjoberg.com/gtsummary/reference/tests.html – Daniel D. Sjoberg Jun 16 '22 at 11:24
  • I wasn't sure how to add this into the code - would you please be able to give an example? Thank you. – Sharmili Balarajah Jun 28 '22 at 07:55

0 Answers0