independent_sample_means: Conduct a comparison for independent sample means - either...

View source: R/independent_sample_means.R

independent_sample_meansR Documentation

Conduct a comparison for independent sample means - either t-test or one-way ANOVA

Description

A convenience function, that provides and easy to use wrapper for a step-by-step comparison of means from independent groups. The steps that are run for each analysis are:

  • 0. Determination of groups For 2 groups conduct independent sample t-test. For more than 2 groups an ANOVA is conducted instead

  • 1. Detect outliers and extreme values including boxplots to identify those values. Utilizes identify_outliers

  • 2. Calculate descriptive statistics for each groups, self-explanatory.

  • 3. Check normal distribution (assumptions) uses a formal test (Shapiro-Wilk) as well as a visual inspection method (qqplots). Carefully judge this step, as the function has no default handling for non-normality. Options include check the literature if the test in your scenario is robust for violations (see also central limit theorem and Glass, 1972), or switch to a non-parametric alternative.

  • 4. Check homogeneity of variances (assumption) for this purpose a levene test will be conducted. A significant (by convention p < .05) result indicates the H0 (of equal variances) must be disregarded. Depending on the result the student t-test with pooled variance / "normal" ANOVA will be used. If there is heterogeneity of variances (i.e., unequal variances) the Welch correction of the degrees of freedom will be used instead.

  • 5. The test (t-Test or ANOVA) will be conducted, including Post-Hoc Comparisons and a calculation of an effect size. Additionally the ggpubr package is used together with rstatix to display a Boxplot including the result of the hypothesis test.

This function is a mere wrapper for the excellent tutorials provided by Alboukadel Kassambara over at Datanovia. See the original Guide for the t-test and for the ANOVA. It just packages all the steps in one function for convenience

Usage

independent_sample_means(
  data,
  dv,
  iv,
  alternative = c("two.sided", "less", "greater"),
  stepwise = TRUE,
  verbose = TRUE,
  add = "jitter",
  fill = iv,
  palette = "jco",
  ...
)

Arguments

data

The dataset containing the variables for the table1 call (all terms from the str_formula must be present)

dv

The name of the dependend variable as character.

iv

The name of the independend variable as character.

alternative

In case of only two groups one can specify if a directed hypothesis should be tested. Default is "two.sided"

stepwise

Boolean, default = TRUE, if TRUE the analysis is carried out in small steps, after each step (e.g. test for normality), the output is printed is to the console and a user input is required. For a list of the steps see the description

verbose

Boolean, default = TRUE, if TRUE the output of each step is printed to the console

add

Additions to the boxplot, see also ggboxplot. I primarily recommend to use either "none" or "jitter"

fill

False for no filled colors

palette

Color palette for the boxplot, see also ggboxplot.

...

(Optional), Additional arguments that can be passed to t_test (e.g., fontsize, font ...), to serialNext or to ggboxplot

Value

A list with all results of the check for the assumptions as well as the hypothesis test itself.

Author(s)

Bjoern Buedenbender (adapted from Alboukadel Kassambara)

See Also

ggboxplot t_test Guide for the t-test and for the ANOVA

Examples

t_test <- independent_sample_means(mtcars, dv = "disp", iv = "vs", add = "none")
ANOVA <- independent_sample_means(mtcars, dv = "disp", iv = "gear", add = "none")

Buedenbender/datscience documentation built on Nov. 21, 2022, 11:14 a.m.