Learn R Programming

tidysummary (version 0.1.0)

normal_test: Perform normality test on a variable

Description

Conducts normality tests for a specified variable, optionally by group. Supports automatic testing and interactive visualization.

Usage

normal_test(data = NULL, var = NULL, group = NULL, norm = "auto")

Value

A logical value:

  • TRUE: data are normally distributed

  • FALSE: data are not normally distributed

Arguments

data

A data frame containing the variables to be tested.

var

A character string specifying the numeric variable in data to test.

group

A character string specifying the grouping variable in data. If NULL, treated as one group.

norm

Control parameter for test behavior. Accepts:

  • 'auto': Automatically decide based on p-values, but the same as 'ask' when n > 1000, default

  • 'ask': Show p-values, plots QQ plots and prompts for decision

  • TRUE/'true': Always returns TRUE

  • FALSE/'false': Always returns FALSE

Methodology for p-values

Automatically selects test based on sample size per group:

  • n < 3: Too small, assuming non-normal

  • (3, 50] Shapiro-Wilk test

  • (50, 1000]: D'Agostino Chi2 test, instead of Kolmogorov-Smirnov test

  • n > 1000: Show p-values, plots QQ plots and prompts for decision

Examples

Run this code
normal_test(iris, "Sepal.Length", "Species", norm = "auto")
normal_test(iris, "Sepal.Length", "Species", norm = TRUE)

Run the code above in your browser using DataLab