Skip to contents

This function computes p-values using ANOVA for each variable in vars and grouping variable specified in group

Usage

ana_fn_aov(
  df,
  vars,
  group,
  add_statistic = FALSE,
  add_posthoc = FALSE,
  posthoc_adjust = "none",
  posthoc_equalvar = TRUE
)

Arguments

df

data.frame

vars

Vector of variable names

group

Name of grouping variable

add_statistic

(logical) Whether to add F-test to table

add_posthoc

(logical) Whether to add post-hoc pairwise comparisons to table

posthoc_adjust

Method for adjusting p-values (see stats::p.adjust(); default 'none')

posthoc_equalvar

(logical) Whether to assume equal variances in all groups (see Details; default TRUE)

Value

data.frame with columns Var, p (formatted p-values), F-test (if requested), and (possibly adjusted) p-values from pairwise comparisons (if requested)

Details

Post-hoc pairwise comparisons are obtained using stats::pairwise.t.test(). If no adjustment for multiple comparisons is made and equal variances across groups are assumed (the default), the tests correspond to Fisher's LSD. If equal variances are not assumed (by setting posthoc_equalvar to FALSE), the tests correspond to Welch's t-tests.

This function should be passed as ana_fn when calling get_desc_table() with a group argument to obtain p-values. If you want to create a custom ana_fn, you should model it after this one.

Examples

if (FALSE) {
df |> ana_fn_aov("age", "TreatmentGroup")
}