Saturday, October 8, 2022

[FIXED] How do I display test statistic (F value) for anova using tbl_summary

Issue

Here is the code that I am using to output a anova summary table with:

hiv %>% 
  select(education, sexfirsttime) %>% 
  mutate(education=
  factor(education, levels= c("no education", "primary","secondary","college"))) %>% 
  tbl_summary(missing="no", 
              by=education,
    statistic = all_continuous() ~"{mean} ({sd})", 
    label = sexfirsttime ~ "Age of first time sex") %>% 
  add_p(test= all_continuous() ~ "aov") %>% 
  modify_header(statistic ~ "**Test Statistic**") 

After executing the code, I get the following error message: Error: Error in update= argument input. Select from ‘variable’, ‘test_name’, ‘var_type’, ‘var_label’, ‘row_type’, ‘label’, ‘stat_1’, ‘stat_2’, ‘stat_3’, ‘stat_4’, ‘test_result’, ‘p.value’

When I try replacing statistic in modify_header with test_result, the output that I get a bizarre output as shown is in the image.

I am fairly new to using gtsummary. Any help would be greatly appreciated. Thank you.


Solution

Use the most recent version of gtsummary and try again. In the most recent version, the handling of "aov" tests was made more consistent with the other tests, including returning the "statistic" column.

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'

tbl <- 
  trial %>%
  select(grade, age, marker) %>%
  tbl_summary(
    by = grade, 
    missing = "no"
  ) %>%
  add_p(all_continuous() ~ "aov") %>%
  # add a header (which also unhides a hidden column)
  modify_header(statistic ~ "**Test Statistic**") %>%
  # add a function to format the column
  modify_fmt_fun(statistic ~ style_sigfig)

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



Answered By - Daniel D. Sjoberg
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.