README.md

checknormality: because you should always check your assumptions

Travis build
status Codecov test
coverage

Overview

The goal of checknormality is to provide implementations of popular normality tests that return the test statistics and p-values. As of 2020/11/30, the package contains an implementation of the Shapiro-Wilk Test of Normality.

A Note on the Algorithms

Shapiro-Wilk Test

Inverse of Normal CDF (Phi inverse)

stats::qnorm(p)

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("chrsshn/checknormality")

Usage

Example 1: Testing a small sample from an exponential distribution using the original, modified, and Royston approaches

set1 <- rexp (30, .8)
checknormality::sw_test (set1, "original")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set1
#> W = 0.83101, p-value = 0.001
checknormality::sw_test (set1, "modified")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set1
#> W = 0.83101, p-value = 0.001
checknormality::sw_test (set1, "royston")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set1
#> W = 0.82613, p-value = 2e-04
stats::shapiro.test (set1) 
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  set1
#> W = 0.82643, p-value = 0.0002067
plot(density (set1))

Note: you can also get the W test statistic using the functions checknormality::R_get_W () and checknormality::C_get_W()

Example 2: Testing a small sample from a normal distribution using the original, modified, and Royston approaches

set2 <- rnorm (40, 20, 5)
checknormality::sw_test (set2, "original")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set2
#> W = 0.96354, p-value = 0.355
checknormality::sw_test (set2, "modified")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set2
#> W = 0.96354, p-value = 0.355
checknormality::sw_test (set2, "royston")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set2
#> W = 0.9722, p-value = 0.4215
stats::shapiro.test (set2)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  set2
#> W = 0.96989, p-value = 0.3569
plot(density (set2))   

Example 3: Testing a large sample from a Poisson distribution using the Royston approach

note: the original and modified approaches are only valid for n \< 50 points

set3 <- rpois(4000, .787)
checknormality::sw_test (set3, "royston")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set3
#> W = 0.78822, p-value < 2.2e-16
stats::shapiro.test (set3)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  set3
#> W = 0.78829, p-value < 2.2e-16
plot(density (set3))   

Example 4: Testing a large sample from a normal distribution using the Royston approach

note: the original and modified approaches are only valid for n \< 50 points

set4 <- rnorm(4000)
checknormality::sw_test (set4, "royston")
#> 
#>  Shapiro-Wilk Test of Normality
#> 
#> data:  set4
#> W = 0.99926, p-value = 0.1011
stats::shapiro.test (set4)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  set4
#> W = 0.99934, p-value = 0.1608
plot(density (set4))   



chrsshn/checknormality documentation built on Dec. 31, 2020, 10:01 p.m.