| Title: | Tests for Departure from Normality |
|---|---|
| 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. |
| Authors: | Joon-Keat Lai [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9840-5836>) |
| Maintainer: | Joon-Keat Lai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.5 |
| Built: | 2026-10-06 08:44:36 UTC |
| Source: | https://github.com/p10911004-npust/normality |
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.
Anderson_Darling_test( x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE )Anderson_Darling_test( x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
A list.
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, pg. 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, (Table 4.8 & 4.9) pg. 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
out <- Anderson_Darling_test(rnorm(10)) print(out$summary)out <- Anderson_Darling_test(rnorm(10)) print(out$summary)
A wrapper function for the normality tests available in this package.
check_normality( data, formula = NULL, alpha = 0.05, method = "SWR", summary = TRUE )check_normality( data, formula = NULL, alpha = 0.05, method = "SWR", summary = TRUE )
data |
A data frame or a numeric vector. |
formula |
Formula (default: NULL). If |
alpha |
Numeric (default: |
method |
Character. Abbreviation specifying the normality test to perform.
Available options are |
summary |
Logical (default: |
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:
"AD": Anderson–Darling test.
A modification of the empirical distribution function (EDF)
approach that gives greater weight to observations in the tails
of the distribution. Compared with several alternative normality
tests, the Anderson–Darling procedure is often more sensitive to
deviations occurring in extreme values and tail behavior. This test is
applicable only for sample sizes n >= 8.
"CVM": Cramér–von Mises test.
An empirical distribution function (EDF)-based goodness-of-fit test
that measures the overall discrepancy between the empirical and
theoretical cumulative distribution functions by assigning relatively
uniform weight across the entire distribution. Compared with the
Anderson–Darling test, the Cramér–von Mises test is generally less
sensitive to deviations in the tails but performs well for detecting
overall departures from normality. This test is applicable only for
sample sizes n >= 8.
"DAP": D'Agostino–Pearson test.
A combined omnibus moment test based on sample skewness and kurtosis.
The procedure transforms the skewness and kurtosis statistics into
approximately standard normal variables and combines them into a
single test statistic. This method is designed to detect a broad
range of departures from normality rather than emphasizing any
particular feature. This test is applicable only for sample sizes
n >= 20.
"JB": Jarque–Bera test.
An omnibus moment test based on sample skewness and kurtosis.
The test evaluates whether the observed skewness and kurtosis
differ significantly from the values expected under a normal
distribution. The method is commonly used in econometrics and is
generally more appropriate for moderate to large sample sizes.
"LF": Lilliefors test.
The Lilliefors test is an EDF omnibus test modified from Kolmogorov-Smirnov
test for the composite hypothesis of normality. The test statistic is the
maximal absolute difference between empirical and hypothetical cumulative
distribution function.
"SW": Shapiro–Wilk test.
The original normality test proposed by Shapiro and Wilk (1965),
based on the correlation between ordered observations and their
expected values under normality. It is widely regarded as one of
the most powerful tests for detecting departures from normality in
small samples. Applicable only for sample sizes
3 <= n <= 50.
"SF": Shapiro–Francia test.
Proposed by Shapiro and Francia (1972) and subsequently simplified
and extended by Royston (1993). This method is a computationally
simpler modification of the Shapiro–Wilk procedure that performs
particularly well for detecting departures associated with
heavier-tailed distributions. Applicable only for sample sizes
5 <= n <= 5000.
"SWR": Shapiro–Wilk test with Royston's modifications.
Uses Royston's (1992) approximations for the null distribution of
the Shapiro–Wilk statistic and extends applicability to larger
samples while maintaining behavior similar to the original test.
Applicable only for sample sizes 3 <= n <= 5000.
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.
A list.
out_AD <- check_normality(rnorm(20), method = "AD") out_DAP <- check_normality(rnorm(20), method = "DAP") out_SW <- check_normality(rnorm(20), method = "SW")out_AD <- check_normality(rnorm(20), method = "AD") out_DAP <- check_normality(rnorm(20), method = "DAP") out_SW <- check_normality(rnorm(20), method = "SW")
An empirical distribution function (EDF)-based goodness-of-fit test that measures the overall discrepancy between the empirical and theoretical cumulative distribution functions by assigning relatively uniform weight across the entire distribution.
Cramer_von_Mises_test( x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE )Cramer_von_Mises_test( x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
A list.
Thode, H. C., Jr., 2002. Goodness of fit tests. Testing for normality. Marcel Dekker, New York. (Section 5.1.3, pg. 103)
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, (Table 4.9, pg. 127). https://doi.org/10.1201/9780203753064
out <- Cramer_von_Mises_test(rnorm(10)) print(out$summary)out <- Cramer_von_Mises_test(rnorm(10)) print(out$summary)
The D'Agostino–Pearson chi-squared (K2) test is a moment-based omnibus test for normality.
D.Agostino_Pearson_test( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = TRUE, misc = FALSE )D.Agostino_Pearson_test( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = TRUE, misc = FALSE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
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.
A list
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
out <- D.Agostino_Pearson_test(rnorm(50)) print(out$summary)out <- D.Agostino_Pearson_test(rnorm(50)) print(out$summary)
A handy wrapper for data normality assessment using the Shapiro-Wilk-Royston, D'Agostino-Pearson, and Anderson-Darling tests.
is_normal(data, formula = NULL, alpha = 0.05, sensitivity = 2, summary = FALSE)is_normal(data, formula = NULL, alpha = 0.05, sensitivity = 2, summary = FALSE)
data |
A data frame or a numeric vector. |
formula |
Formula (default: NULL). If |
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 |
A boolean value (or a list if summary = TRUE).
is_normal(iris, Sepal.Length ~ Species)is_normal(iris, Sepal.Length ~ Species)
Tied data
is_tied(x, ratio = 0.3, remove_NA = FALSE)is_tied(x, ratio = 0.3, remove_NA = FALSE)
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. |
Logical
is_tied(c(1, 1, 2, 2, 2, 3, 4, 5)) #> TRUEis_tied(c(1, 1, 2, 2, 2, 3, 4, 5)) #> TRUE
Performs the Jarque-Bera chi-squared test, a moment-based omnibus test for assessing normality.
Jarque_Bera_test( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = TRUE )Jarque_Bera_test( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = TRUE )
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: |
silent |
Logical (default: |
summary |
Logical (default: TRUE). Produce a summary table. |
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.
A list
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
out <- Jarque_Bera_test(rnorm(50)) print(out$summary)out <- Jarque_Bera_test(rnorm(50)) print(out$summary)
Performs a kurtosis test to assess whether a distribution deviates from normality in terms of tail heaviness.
kurtosis( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), method = c("G2", "b2", "g2"), silent = FALSE, summary = TRUE )kurtosis( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), method = c("G2", "b2", "g2"), silent = FALSE, summary = TRUE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
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.
A list
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
x <- c(10:17, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15) kurtosis(x)x <- c(10:17, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15) kurtosis(x)
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).
Lilliefors_test(x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE)Lilliefors_test(x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE)
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
A list.
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.
out <- Lilliefors_test(rnorm(10)) print(out$summary)out <- Lilliefors_test(rnorm(10)) print(out$summary)
The standard output format for normality package.
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 )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 )
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. |
A list.
Coefficients (ai) for the W test for normality.
Shapiro_Wilk_coef_tableShapiro_Wilk_coef_table
A data frame with 50 rows and 25 variables:
rownames is the sample size (n); colnames is the corresponding coefficients (ai).
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
The percentage points (critical values of W) of the W test for n = 3(1)50.
Shapiro_Wilk_pval_tableShapiro_Wilk_pval_table
A data frame with 50 rows and 10 variables:
rownames is the sample size (n); colnames is the corresponding p-values.
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
Performs the Shapiro–Wilk normality test, which assesses whether a sample originates from a normally distributed population using a regression-based correlation method.
Shapiro_Wilk_test( x, alpha = 0.05, method = c("SWR", "SF", "SW"), silent = FALSE, summary = TRUE, misc = FALSE, resampling = TRUE )Shapiro_Wilk_test( x, alpha = 0.05, method = c("SWR", "SF", "SW"), silent = FALSE, summary = TRUE, misc = FALSE, resampling = TRUE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
resampling |
Logical (default: TRUE).
If |
method
"SW": Shapiro–Wilk test, the original normality test proposed by Shapiro and Wilk (1965). Applicable only for sample sizes 3 <= n <= 50.
"SF": Shapiro–Francia test, proposed by Shapiro and Francia (1972) and subsequently simplified and extended by Royston (1993). Applicable only for sample sizes 5 <= n <= 5000.
"SWR": Shapiro–Wilk test with Royston's (1992) modifications for approximating the null distribution and extending the test to larger sample sizes. Applicable only for sample sizes 3 <= n <= 5000.
A list.
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
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)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)
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.
skewness( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), method = c("G1", "b1", "g1"), silent = FALSE, summary = TRUE )skewness( x, alpha = 0.05, alternative = c("two.sided", "less", "greater"), method = c("G1", "b1", "g1"), silent = FALSE, summary = TRUE )
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 |
summary |
Logical (default: TRUE). Produce a summary table. |
A list
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
skewness(rnorm(30))skewness(rnorm(30))