Comparing Means: t-Tests and ANOVA

Before You Start

Basic Procedure

Report Results

Summary and Practice

Syntax

Group comparison table

  • Functions:
    • gtsummary package: tbl_summary() with add_p()
    • modelsummary package: datasummary()
  • Comment:
    • gtsummary is very full-featured, and its output tables are customizable and look great. add_p() chooses the test for each variable by its type, not by whether the data are normal: by default, continuous variables get a nonparametric test (Wilcoxon rank-sum for two groups, Kruskal-Wallis for more), and categorical variables get a chi-square test (Fisher’s exact test when expected counts are small). For a t-test, use add_p(test = all_continuous() ~ "t.test").
    • modelsummary is also a very powerful package that outputs good-looking tables. It can do most of what gtsummary can.
  • Resources: gtsummary: tbl_summary() tutorial, modelsummary: Data summaries

Resources & References