Skip to contents

This function performs a Shapiro-Wilk normality test on multiple variables in a dataframe. It returns the results in a tidy format.

Usage

ntest(df, cols)

Arguments

df

A dataframe containing the data to be tested.

cols

A vector of column names in the dataframe to be tested for normality.

Value

A dataframe with the test results. Each row corresponds to a variable, and the columns contain the test statistics and p-values.

Details

The function first reshapes the dataframe to a long format and calculates the sample size for each variable. It then checks if the sample size for any variable is less than 3 or greater than 5000, and if so, aborts the function with an error message because the `shapiro.test()` only expects this range of observations. The function then performs the Shapiro-Wilk test on each variable and returns a formatted dataframe with the test results.

See also

[ntest_by()] to run normality tests for grouped data

Examples

if (FALSE) { # \dontrun{
# Perform multiple normality tests at once
ntest(df   = mtcars,
      cols = mpg)
} # }