| test.norm | R Documentation |
This function performs the Kolmogorov-Smirnov-Lilliefors, the Shapiro-Wilk test,
the Anderson–Darling test, and the Cramer-von Mises test for testing for testing
univariate normality (null hypothesis) against univariate non-normality (alternative
hypothesis), and the Henze-Zirkler test, Henze-Wagner test, and the Royston test
for testing multivariate normality (null hypothesis) against multivariate non-normality
(alternative hypothesis). By default, the function performs the Shapiro-Wilk
test for testing univariate normality, and Henze-Zirkler test for testing multivariate
normality. Note that the function also tests normality of residuals of a linear
model when specifying an object of class "lm" for the argument data.
test.norm(data, ..., print = c("all", "multi", "uni"),
method.uni = c("lillie", "sw", "ad", "cm"),
method.multi = c("hz", "hw", "royston"), p.adj = "none", digits = 2,
p.digits = 3, as.na = NULL, plot = FALSE, geom = c("all", "qq", "hist"),
impute = FALSE, filename = NULL, width = NA, height = NA, dpi = 600,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
data |
a fitted model of class |
... |
an expression indicating the variable names in |
print |
a character vector indicating which results to show on the
console, i.e. |
method.uni |
a character string indicating the method used for testing univariate
normality, i.e., |
method.multi |
a character string indicating the method used for testing
multivariate normality, i.e., |
p.adj |
a character string indicating an adjustment method for multiple
testing based on |
digits |
an integer value indicating the number of decimal places to be used for displaying results. |
p.digits |
an integer value indicating the number of decimal places to be used for displaying the p-value. |
as.na |
a numeric vector indicating user-defined missing values,
i.e. these values are converted to |
plot |
logical: if |
geom |
a character vector indicating which plot to draw, i.e.,
|
impute |
logical: if |
filename |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
dpi |
a numeric value indicating the |
write |
a character string naming a text file with file extension
|
append |
logical: if |
check |
logical: if |
output |
logical: if |
Returns an object of class misty.object, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
numeric vector or data frame |
plot |
ggplot2 object for plotting the results |
args |
specification of function arguments |
result |
list with result tables, i.e., |
This function is based on the hz(), hw(), and royston()
function in the MVN package by Selcuk Korkmaz, Dincer Goksuluk and Gokmen
Zararsiz, and the ad.test(), lillie.test(), and cvm.test()
function in the nortest package by Juergen Gross and Uwe Ligges.
Takuya Yanagida
Anderson, T. W., & Darling, D. A. (1954). A test of goodness of fit. Journal of the American Statistical Association, 49(268), 765-769. https://doi.org/10.1080/01621459.1954.10501232
Gross J, & Ligges U (2015). nortest: Tests for Normality. R package version 1.0-4, https://doi.org/10.32614/CRAN.package.nortest
Henze, N., & Zirkler, B. (1990). A class of invariant consistent tests for multivariate normality. Communications in Statistics—Theory and Methods, 19(10), 3595-3617. https://doi.org/10.1080/03610929008830400
Henze, N., & Wagner, T. (1997). A new approach to the BHEP tests for multivariate normality. Journal of Multivariate Analysis, 62(1), 1-23
Korkmaz S, Goksuluk D, & Zararsiz G. (2014) MVN: An R Package for Assessing Multivariate Normality. The R Journal, 6(2), 151-162.
Lilliefors, H. W. (1967). On the Kolmogorov-Smirnov test for normality with mean and variance unknown. Journal of the American Statistical Association, 62(318), 399-402. https://doi.org/10.1080/01621459.1967.10482916
Royston, J.P. (1983). Some techniques for assessing multivariate normality based on the Shapiro-Wilk W. Journal of the Royal Statistical Society. Series C (Applied Statistics), 32, 121-133. https://doi.org/10.2307/2347291
Shapiro, S. S., & Wilk, M. B. (1965). An analysis of variance test for normality (complete samples). Biometrika, 52(3–4), 591–611. https://doi.org/10.1093/biomet/52.3-4.591
Stephens, M. A. (1986). Tests based on EDF statistics. In R. B. D'Agostino & M. A. Stephens (Eds.), Goodness-of-Fit Techniques (pp. 97.193). Marcel Dekker.
skewness, kurtosis, check.resid,
test.linear, test.homo, test.levene
## Not run:
#————————————————————————————————————————————————————————————————————————————
# Fitted Model of Class "lm"
# Estimate linear model
mod <- lm(mpg ~ cyl + disp, data = mtcars)
# Example 1a: Shapiro-Wilk test for normality of residuals
test.norm(mod)
# Example 1b: Lilliefors (Kolomorov-Smirnov) test for normality of residuals
test.norm(mod, method.uni = "lillie")
#————————————————————————————————————————————————————————————————————————————
# One Variable
# Example 2: Shapiro-Wilk test for normality
test.norm(mtcars, mpg)
#————————————————————————————————————————————————————————————————————————————
# Multiple Variables
# Example 3a: Henze-Zirkler test for multivariate normality
test.norm(mtcars, hp, drat, wt, qsec)
# Example 3b: Henze-Wagner test for multivariate normality
test.norm(mtcars, hp, drat, wt, qsec, method.multi = "hw")
# Example 3c: Multiple Shapiro-Wilk tests for normality
test.norm(mtcars, hp, drat, wt, qsec, print = "uni")
# Example 3c: Henze-Wagner test for multivariate normality
# Multiple Shapiro-Wilk tests for normality
test.norm(mtcars, hp, drat, wt, qsec, print = "all")
#————————————————————————————————————————————————————————————————————————————
# Plot
# Example 4a: Q-Q plot and histogram
test.norm(mtcars, mpg, plot = TRUE)
# Example 4b: Multivariate Mahalanobis Q-Q plot
test.norm(mtcars, hp, drat, wt, qsec, plot = TRUE)
# Example 4c: Multiple Q-Q plots
test.norm(mtcars, hp, drat, wt, qsec, print = "uni", plot = TRUE)
# Example 4d: Multiple histograms
test.norm(mtcars, hp, drat, wt, qsec, print = "uni", plot = TRUE, geom = "hist")
# Example 4e: Multivariate Mahalanobis Q-Q plot, impute data for plotting
test.norm(airquality, plot = TRUE, impute = TRUE)
# Example 4f: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- test.norm(mtcars, mpg)
plot(object, point.shape = 2, ribbon.fill = "red", xlim = c(0, 40))
#————————————————————————————————————————————————————————————————————————————
# Write Results and Save Plot
# Example 5a: Write results into a text file
test.norm(mtcars, hp, drat, wt, qsec, write = "Multinorm.txt")
# Example 5b: Write results into an Excel file
test.norm(mtcars, hp, drat, wt, qsec, write = "Multinorm.xlsx")
# Example 5c: Save plot as PNG file
test.norm(mtcars, mpg, plot = TRUE, filename = "Multinorm.png",
width = 13, height = 6)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.