Test for detecting violation of normality assumption.
Value
ols_test_normality returns an object of class "ols_test_normality".
An object of class "ols_test_normality" is a list containing the
following components:
- kolmogorv
kolmogorv smirnov statistic
- shapiro
shapiro wilk statistic
- cramer
cramer von mises statistic
- anderson
anderson darling statistic
Details
The tests differ in the sample sizes they support. shapiro.test()
requires between 3 and 5000 observations, and nortest::ad.test() and
nortest::cvm.test() require at least 8. ks.test() does not
document a sample-size limit of its own, but a minimum of 3 observations is
required here so that the test is meaningful. Tests whose sample-size
requirement is not met are skipped: their statistic and p-value are returned
as NA and a single warning lists the skipped tests and the reason. If
the sample is too small for every test, the function stops with an error.
The Cramér–von Mises test is nortest::cvm.test(), the test of
composite normality, which compares the data with a normal distribution
whose mean and standard deviation are estimated from the data. It is
deterministic. For very small p-values the test reports 7.37e-10
with a warning instead of a more precise value.
References
Stephens, M. A. (1986). Tests based on EDF statistics. In R. B. D'Agostino and M. A. Stephens (Eds.), Goodness-of-Fit Techniques (pp. 97–193). New York: Marcel Dekker.
Thode, H. C. (2002). Testing for Normality. New York: Marcel Dekker.
See also
Other residual diagnostics:
ols_plot_resid_box(),
ols_plot_resid_fit(),
ols_plot_resid_hist(),
ols_plot_resid_qq(),
ols_test_correlation()
Examples
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
ols_test_normality(model)
#> -----------------------------------------------
#> Test Statistic pvalue
#> -----------------------------------------------
#> Shapiro-Wilk 0.9366 0.0600
#> Kolmogorov-Smirnov 0.1152 0.7464
#> Cramer-von Mises 0.0764 0.2230
#> Anderson-Darling 0.5859 0.1188
#> -----------------------------------------------