normTest: Test values for normality of distribution

View source: R/normTest.R

normTestR Documentation

Test values for normality of distribution

Description

Normality test: histogram with corresponding normal density distribution line, as well as p values for various normality tests.
The package nortest is needed for full functionality.

Usage

normTest(
  v,
  plot = TRUE,
  main = deparse(substitute(v)),
  breaks = 15,
  col = "tan",
  legend = TRUE,
  ...
)

Arguments

v

Vector of values to be tested for normality

plot

Plot the histogram with the corresponding normal density distribution? DEFAULT: TRUE

main

Graph title. DEFAULT: deparse(substitute(v))

breaks

Number of bins. Exact, unlike in hist. DEFAULT: 15

col

Color of bars. DEFAULT: "tan"

legend

Add legend text in topright? DEFAULT: TRUE

...

Further arguments passed to hist

Value

named vector of p values

Author(s)

Berry Boessenkool, berry-b@gmx.de, Sep 2021

See Also

ks.test, shapiro.test

Examples

normTest(rnorm(1000, mean=97, sd=8.9))
# if p > 0.05: accept Nullhypothesis that data are normally distributed.
normTest(rexp(30))

if(requireNamespace("pbapply")) replicate <- pbapply::pbreplicate
par(mfcol=c(7,6), mar=c(0,0.1,1,0.1), oma=c(2.5,1.5,2.5,0), las=1)
invisible(sapply(c("rnorm(10)", "rnorm(100)", 
                   "rexp(10)", "rexp(100)", 
                   "runif(10)", "runif(100)"), function(vv){
  check <- replicate(1e2, normTest(v=eval(str2lang(vv)), plot=FALSE))
  for(n in rownames(check)) 
   {hist(check[n,], breaks=seq(0,1,len=20), axes=FALSE, ylab="", xlab="", main="")
   if(n=="ShapiroWilk") title(main=vv, line=1, xpd=NA)
   if(vv=="rnorm(10)") title(ylab=n, line=0, xpd=NA)
   abline(v=0.05, col="blue", lwd=1, xpd=TRUE)
   }
  axis(1, at=0:1)
  }))
title(main="P values of tests for normality with", outer=TRUE, line=1.5)


berryFunctions documentation built on May 29, 2024, 4:01 a.m.