ntest: Perform normality test for multiple variables at once

View source: R/ntest.R

ntestR Documentation

Perform normality test for multiple variables at once

Description

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.

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.

Value

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

See Also

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

Examples

## Not run: 
# Perform multiple normality tests at once
ntest(df   = mtcars,
      cols = mpg)

## End(Not run)


ddauber/r4np documentation built on Jan. 15, 2025, 8:46 p.m.