ntest_by | R Documentation |
This function performs a Shapiro-Wilk normality test on multiple variables in a dataframe by groups.
ntest_by(df, cols, group)
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. |
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.
A data frame with the results of the Shapiro-Wilk test for each group and variable.
[ntest()] to run normality tests for ungrouped data
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.