test_normality {LambertW}R Documentation

Visual and statistical Gaussianity check

Description

Graphical and statistical check if data is Gaussian (three common Normality tests, QQ-plots, histograms, etc).

test_normality does not show the autocorrelation function (ACF) estimate for lag 0, since it always equals 1. Thus removing it does not lose any information, but greatly improves the y-axis scale for higher order lags (which are usually very small compared to 1).

test_norm is a shortcut for test_normality.

Usage

test_normality(
  data,
  show.volatility = FALSE,
  plot = TRUE,
  pch = 1,
  add.legend = TRUE,
  seed = sample(1e+06, 1)
)

test_norm(...)

Arguments

data

a numeric vector of data values.

show.volatility

logical; if TRUE the squared (centered) data and its ACF are also shown. Useful for time series data to see if squares exhibit dependence (for financial data they typically do); default: FALSE.

plot

Should visual checks (histogram, densities, qqplot, ACF) be plotted? Default TRUE; otherwise only hypothesis test results are returned.

pch

a vector of plotting characters or symbols; default pch = 1.

add.legend

logical; if TRUE (default) a legend is placed in histogram/density plot.

seed

optional; if sample size > 5,000, then some normality tests fail to run. In this case it uses a subsample of size 5,000. For reproducibility, the seed can be specified by user. By default it uses a random seed.

...

arguments as in test_normality.

Value

A list with results of 3 normality tests (each of class htest) and the seed used for subsampling:

anderson.darling

Anderson Darling (if nortest package is available),

shapiro.francia

Shapiro-Francia (if nortest package is available),

shapiro.wilk

Shapiro-Wilk,

seed

seed for subsampling (only used if sample size > 5,000).

References

Thode Jr., H.C. (2002): “Testing for Normality”. Marcel Dekker, New York.

See Also

shapiro.test in the stats package; ad.test, sf.test in the nortest package.

Examples


y <- rLambertW(n = 1000, theta = list(beta = c(3, 4), gamma = 0.3),
               distname = "normal")
test_normality(y)

x <- rnorm(n = 1000)
test_normality(x)

# mixture of exponential and normal
test_normality(c(rexp(100), rnorm(100, mean = -5)))


[Package LambertW version 0.6.9-1 Index]