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.
CodePudding user response:
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)
Created on 2021-10-17 by the reprex package (v2.0.1)