normtest: Normality tests for one or more variables

View source: R/normality.R

normtestR Documentation

Normality tests for one or more variables

Description

Runs normality/distribution tests consistently for one or many variables, overall or within hierarchical groups.

Usage

normtest(x = NULL,
  vars = NULL,
  by = NULL,
  data = NULL,
  method = c("all",
    "shapiro",
    "ks",
    "lilliefors",
    "anderson",
    "cramer.von.mises",
    "shapiro.francia",
    "pearson",
    "jarque.bera"),
  digits = 4,
  p_digits = 3,
  show = TRUE,
  console = FALSE)

Arguments

x

One numeric variable. May be omitted when vars is supplied.

vars

Optional vars(...) selection of several numeric variables.

by

Optional grouping specification. With by = vars(province, sex, group), province and sex are ordered outer strata and group is the innermost group.

data

Data frame; the active R4VN data frame is used when omitted.

method

Test or tests to run. "all" runs built-in Shapiro-Wilk, fitted-normal KS and Jarque-Bera plus available optional tests from nortest.

digits, p_digits

Decimal places for statistics and p-values.

show, console

R4VN display controls.

Details

Different normality tests have different sensitivities and sample-size behavior. The ordinary fitted-normal Kolmogorov-Smirnov p-value is approximate because mean and SD are estimated from the same sample; use the Lilliefors option when available. A nonsignificant test does not prove normality, so graphical inspection remains important.

Value

An R4VN result object, invisibly.

See Also

swilk, varform

Examples

d <- data.frame(
  x = rnorm(80),
  y = rexp(80),
  province = rep(c("A", "B"), each = 40),
  sex = rep(rep(c("F", "M"), each = 20), 2)
)
normtest(x, data = d)
normtest(vars = vars(x, y), data = d, method = c("shapiro", "jarque.bera"))
normtest(vars = vars(x, y), by = vars(province, sex), data = d)


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.