PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 8, 2022

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

 October 08, 2022     anova, gtsummary, r, statistics     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing