ntest_by: Perform normality test for multiple variables by groups

View source: R/ntest_by.R

ntest_byR Documentation

Perform normality test for multiple variables by groups

Description

This function performs a Shapiro-Wilk normality test on multiple variables in a dataframe by groups.

Usage

ntest_by(df, cols, group)

Arguments

df

A dataframe containing the data to be tested.

cols

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

group

A column name in the dataframe that defines the groups.

Details

The function first creates subsets of the data for each group. It then performs a Shapiro-Wilk normality test ('shapiro.test()') on each group and returns the results in a tidy format. the function also checks whether the number of observations for each variable and group lies within the permissible range of the 'shapiro.test()'. If not, the function will provide diagnostics on why a test could not be performed base on which groups are affected.

Value

A data frame with the results of the Shapiro-Wilk test for each group and variable.

See Also

[ntest()] to run normality tests for ungrouped data

Examples

## Not run: 
# Perform a normality test for groups
ntest_by(df    = mtcars,
         cols  = mpg,
         group = cyl)

# Perform a normality test for multiple variables by groups
ntest_by(df    = starwars,
         cols  = c(mass, birth_year),
         group = species)

## End(Not run)


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