Package {normality}


Title: Tests for Departure from Normality
Version: 0.0.3
Description: A toolkit for assessing data normality using a comprehensive collection of statistical methods. It includes descriptive measures and formal hypothesis tests, such as skewness and kurtosis tests, the Anderson–Darling test, the Shapiro–Wilk test, and the D'Agostino–Pearson K2 omnibus test.
License: MIT + file LICENSE
URL: https://github.com/P10911004-NPUST/normality
BugReports: https://github.com/P10911004-NPUST/normality/issues
Encoding: UTF-8
Depends: R (≥ 3.5)
LazyData: true
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-07-07 09:25:47 UTC; ABRC
Author: Joon-Keat Lai ORCID iD [aut, cre, cph]
Maintainer: Joon-Keat Lai <p10911004@gmail.com>
Repository: CRAN
Date/Publication: 2026-07-07 09:40:02 UTC

Anderson-Darling Normality Test

Description

Performs the Anderson–Darling (A2) normality test, an EDF-based goodness-of-fit test that gives greater weight to deviations in the tails of the distribution.

Usage

Anderson_Darling_test(
  x,
  alpha = 0.05,
  silent = FALSE,
  summary = TRUE,
  misc = FALSE
)

Arguments

x

A numeric vector, at least length of 8.

alpha

Numeric (default: 0.05). Significance threshold, range from 0 to 1.

silent

Logical (default: FALSE). If FALSE, print out the results.

summary

Logical (default: TRUE). Produce a summary table.

misc

Logical (default: FALSE). Output other unimportant parameters.

Value

A list.

References

D’Agostino, R.B., 2017. Tests for the Normal Distribution. In: D’Agostino, R.B., Stephens, M.A. (Eds.), Goodness-of-Fit Techniques, 1st ed. Routledge, New York, pp. 372–373. https://doi.org/10.1201/9780203753064

Stephens, M.A., 2017. Tests Based on EDF Statistics. In: D’Agostino, R.B., Stephens, M.A. (Eds.), Goodness-of-Fit Techniques, 1st ed. Routledge, New York, pp. 126–128. https://doi.org/10.1201/9780203753064

Anderson, T.W., Darling, D.A., 1954. A Test of Goodness of Fit. J. Am. Stat. Assoc. 49, 765–769. https://doi.org/10.1080/01621459.1954.10501232

Examples

out <- Anderson_Darling_test(rnorm(10))
print(out$summary)


D'Agostino–Pearson K2 Normality Test

Description

The D'Agostino–Pearson chi-squared (K2) test is a moment-based omnibus test for normality.

Usage

D.Agostino_Pearson_test(
  x,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater"),
  silent = FALSE,
  summary = TRUE,
  misc = FALSE
)

Arguments

x

Numeric vector. Must have length at least 20.

alpha

Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1.

alternative

Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). Note that this option is only applied to the skewness and kurtosis components of the test.

silent

Logical (default: FALSE). If FALSE, results are printed to the console.

summary

Logical (default: TRUE). Produce a summary table.

misc

Logical (default: FALSE). Output other unimportant parameters.

Details

It evaluates the null hypothesis that the data come from a normal distribution by combining standardized measures of skewness and kurtosis into a single chi-squared test statistic.

Value

A list

References

D’Agostino, R.B., Belanger, A., D’Agostino, R.B., 1990. A Suggestion for Using Powerful and Informative Tests of Normality. Am. Stat. 44, 316–321. https://doi.org/10.1080/00031305.1990.10475751

Examples

out <- D.Agostino_Pearson_test(rnorm(50))
print(out$summary)


Jarque-Bera Normality Test

Description

Performs the Jarque-Bera chi-squared test, a moment-based omnibus test for assessing normality.

Usage

Jarque_Bera_test(
  x,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater"),
  silent = FALSE,
  summary = TRUE
)

Arguments

x

Numeric vector. Must contain at least 20 observations.

alpha

Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1.

alternative

Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). This argument applies only to the skewness and kurtosis components and does not affect the Jarque-Bera omnibus test statistic itself.

silent

Logical (default: FALSE). If FALSE, results are printed to the console.

summary

Logical (default: TRUE). Produce a summary table.

Details

The test evaluates the null hypothesis that the data are drawn from a normal distribution by combining standardized measures of skewness and kurtosis into a single chi-squared test statistic.

Value

A list

References

Jarque, C.M., Bera, A.K., 1987. A Test for Normality of Observations and Regression Residuals. Int. Stat. Rev. 55, 163–172. https://doi.org/10.2307/1403192

See Also

D.Agostino_Pearson_test()

Examples

out <- Jarque_Bera_test(rnorm(50))
print(out$summary)


Lilliefors Normality Test

Description

Performs the Lilliefors normality test, which is an empirical distribution function (EDF)-based goodness-of-fit test derived from the Kolmogorov–Smirnov test, using the approximation proposed by Molin and Abdi (1998).

Usage

Lilliefors_test(x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE)

Arguments

x

A numeric vector, at least length of 8.

alpha

Numeric (default: 0.05). Significance threshold, range from 0 to 1.

silent

Logical (default: FALSE). If FALSE, print out the results.

summary

Logical (default: TRUE). Produce a summary table.

misc

Logical (default: FALSE). Output other unimportant parameters.

Value

A list.

References

Molin, P., Abdi, H., 1998. New tables and numerical approximation for the Kolmogorov-Smirnov/Lillierfors/Van Soest test of normality. Technical report, University of Bourgogne.

Examples

out <- Lilliefors_test(rnorm(10))
print(out$summary)


Shapiro-Wilk normality test (coefficients)

Description

Coefficients (ai) for the W test for normality.

Usage

Shapiro_Wilk_coef_table

Format

A data frame with 50 rows and 25 variables:

rownames is the sample size (n); colnames is the corresponding coefficients (ai).

References

Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709


Shapiro-Wilk normality test (p-values)

Description

The percentage points (critical values of W) of the W test for n = 3(1)50.

Usage

Shapiro_Wilk_pval_table

Format

A data frame with 50 rows and 10 variables:

rownames is the sample size (n); colnames is the corresponding p-values.

References

Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709


Shapiro-Wilk Normality Test

Description

Performs the Shapiro–Wilk normality test, which assesses whether a sample originates from a normally distributed population using a regression-based correlation method.

Usage

Shapiro_Wilk_test(
  x,
  alpha = 0.05,
  method = c("SWR", "SF", "SW"),
  silent = FALSE,
  summary = TRUE,
  misc = FALSE,
  resampling = TRUE
)

Arguments

x

A numeric vector.

alpha

Significance threshold (default: 0.05).

method

Character (default: "SWR"). Use which modification of the test? Available options are c("SWR", "SF", "SW").

silent

Logical (default: FALSE). If FALSE, print out the results.

summary

Logical (default: TRUE). Produce a summary table.

misc

Logical (default: FALSE). Output other unimportant parameters.

resampling

Logical (default: TRUE). If TRUE, unlock the sample size limitation of the test by using sample resampling method.

Details

method

Value

A list.

References

Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709

Shapiro, S.S., Francia, R.S., 1972. An Approximate Analysis of Variance Test for Normality. J. Am. Stat. Assoc. 67, 215–216. https://doi.org/10.1080/01621459.1972.10481232

Royston, P., 1993. A pocket-calculator algorithm for the Shapiro–Francia test for non-normality: an application to medicine. Stat. Med. 12, 181–184. https://doi.org/10.1002/sim.4780120209

Royston, P., 1992. Approximating the Shapiro–Wilk W-test for non-normality. Stat. Comput. 2, 117–119. https://doi.org/10.1007/BF01891203

Examples

sw <- Shapiro_Wilk_test(rnorm(20), method = "SW")
print(sw$summary)
sf <- Shapiro_Wilk_test(rnorm(100) ^ 2, method = "SF")
print(sf$summary)
swr <- Shapiro_Wilk_test(rnorm(1e6), method = "SWR")
print(swr$summary)

Normality test

Description

A wrapper function for the normality tests available in this package.

Usage

check_normality(
  x,
  alpha = 0.05,
  silent = FALSE,
  summary = TRUE,
  method = "SWR",
  ...
)

Arguments

x

A numeric vector containing the sample observations.

alpha

Numeric (default: 0.05). Significance level used to determine whether the null hypothesis is rejected. Must be between 0 and 1.

silent

Logical (default: FALSE). If FALSE, print the test results to the console.

summary

Logical (default: TRUE). If TRUE, return a summary table of the test results.

method

Character. Abbreviation specifying the normality test to perform. Available options are c("AD", "DAP", "JB", "LF", "SW", "SF", "SWR").

...

Additional arguments passed to the selected test function.

Details

The method argument specifies the statistical procedure used to assess whether a sample is consistent with a normal distribution. Different tests emphasize different characteristics of departures from normality, such as skewness, kurtosis, or discrepancies in the tails of the distribution. Because no single test performs optimally under all circumstances, the choice of method may depend on sample size and the expected type of non-normality.

Available methods are:

In all methods, the null hypothesis is that the sample is drawn from a normal distribution. Small p-values indicate evidence against the assumption of normality.

Value

A list.

Examples

out_AD <- check_normality(rnorm(20), method = "AD")
out_DAP <- check_normality(rnorm(20), method = "DAP")
out_SW <- check_normality(rnorm(20), method = "SW")

Normality test

Description

A handy wrapper for data normality assessment using the Shapiro-Wilk-Royston, D'Agostino-Pearson, and Anderson-Darling tests.

Usage

is_normal(data, formula = NULL, alpha = 0.05, sensitivity = 2, summary = FALSE)

Arguments

data

A data frame or a numeric vector.

formula

Formula (default: NULL). If data is a data frame, define the val ~ group.

alpha

Significance threshold, range from 0 to 1 (default: 0.05).

sensitivity

Numeric, range from 1 to 3 (default: 2). The greater the value, the greater chance to consider as non-normal.

summary

Logical (default: FALSE). If TRUE, show the summary table.

Value

A boolean value (or a list if summary = TRUE).

Examples

is_normal(iris, Sepal.Length ~ Species)

Tied data

Description

Tied data

Usage

is_tied(x, ratio = 0.3, remove_NA = FALSE)

Arguments

x

A numeric vector

ratio

Numeric (default: 0.3). The ratio threshold of being considred as tied-data. The value range from 0 to 1.

remove_NA

Logical (default: TRUE). Whether or not to remove NAs.

Value

Logical

Examples

is_tied(c(1, 1, 2, 2, 2, 3, 4, 5))
#> TRUE

Kurtosis test

Description

Performs a kurtosis test to assess whether a distribution deviates from normality in terms of tail heaviness.

Usage

kurtosis(
  x,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater"),
  method = c("G2", "b2", "g2"),
  silent = FALSE,
  summary = TRUE
)

Arguments

x

Numeric vector containing the input data.

alpha

Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1.

alternative

Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater").

method

Character (default: "G2"). Formula used to estimate kurtosis. Available options are c("G2", "b2", "g2"). The "g2" statistic is the classical sample kurtosis estimator, while "G2" and "b2" are bias-corrected versions of "g2".

silent

Logical (default: FALSE). If FALSE, results are printed to the console.

summary

Logical (default: TRUE). Produce a summary table.

Details

The test evaluates the null hypothesis that the population kurtosis is equal to 3, which is the kurtosis of a normal distribution. Values significantly different from 3 indicate deviations from normality, such as heavy-tailed or light-tailed behavior.

Value

A list

References

Joanes, D.N., Gill, C.A., 1998. Comparing measures of sample skewness and kurtosis. J. R. Stat. Soc. D (The Statistician) 47, 183–189. https://doi.org/10.1111/1467-9884.00122

Wright, D.B., Herrington, J.A., 2011. Problematic standard errors and confidence intervals for skewness and kurtosis. Behav. Res. Methods 43, 8–17. https://doi.org/10.3758/s13428-010-0044-x

Examples

x <- c(10:17, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15)
kurtosis(x)

Standard output format

Description

The standard output format for normality package.

Usage

normality_standard_output(
  method = "what test?",
  is_normal = NA,
  alpha = NA_real_,
  alternative = c("two.sided", "less", "greater"),
  summary = NULL,
  statistic = NA_real_,
  pvalue = NA_real_,
  misc = NULL
)

Arguments

method

Character. The name of the test.

is_normal

Logical. Is the input data normally distributed?

alpha

Numeric (default: 0.05). Significance threshold.

alternative

Character. The alternative hypothesis (H1) to test. Available options are c("two.sided", "less", "greater").

summary

Statistic summary, if any.

statistic

Numeric. The value used to calculate p-value.

pvalue

Numeric. The p-value of the test.

misc

List. Miscellaneous elements.

Value

A list.


Skewness test

Description

The test evaluates whether the population skewness is equal to zero. Under the null hypothesis, the data are assumed to originate from a symmetric distribution. Significant positive or negative skewness indicates asymmetry in the distribution and may suggest a departure from normality.

Usage

skewness(
  x,
  alpha = 0.05,
  alternative = c("two.sided", "less", "greater"),
  method = c("G1", "b1", "g1"),
  silent = FALSE,
  summary = TRUE
)

Arguments

x

Numeric vector containing the input data.

alpha

Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1.

alternative

Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater").

method

Character (default: "G1"). Formula used to estimate skewness. Available options are c("G1", "b1", "g1"). The "g1" statistic is the conventional moment-based sample skewness. The "G1" and "b1" statistics apply finite-sample corrections to reduce the bias of "g1".

silent

Logical (default: FALSE). If FALSE, the test results are printed to the console.

summary

Logical (default: TRUE). Produce a summary table.

Value

A list

References

Joanes, D.N., Gill, C.A., 1998. Comparing measures of sample skewness and kurtosis. J. R. Stat. Soc. D (The Statistician) 47, 183–189. https://doi.org/10.1111/1467-9884.00122

Wright, D.B., Herrington, J.A., 2011. Problematic standard errors and confidence intervals for skewness and kurtosis. Behav. Res. Methods 43, 8–17. https://doi.org/10.3758/s13428-010-0044-x

Examples

skewness(rnorm(30))