Sharmili Balarajah
Sharmili Balarajah

Reputation: 13

Unable to obtain chisq for tbl_summary

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!

Upvotes: 0

Views: 292

Answers (0)

Related Questions