The “shapiro.test” Function in R

  • Package: stats (part of the base R installation)

  • Purpose: To perform the Shapiro-Wilk test for normality.

  • General Class: Statistical Testing

  • Required Argument(s):

    • x: A numeric vector containing the data to be tested for normality.

  • Notable Optional Arguments:

    • method: A character string indicating the method to be used. The default is "shapiro.test", which is the classical Shapiro-Wilk test. Other methods include "swilk" for Royston’s W test and "naive" for the Shapiro-Francia test.

  • Example:

  • # Example usage
    set.seed(123)
    my_data <- rnorm(100) # Generating a random normal sample

    # Performing the Shapiro-Wilk test
    result <- shapiro.test(my_data)

    # Displaying the test result
    print(result)

  • In this example, shapiro.test is a function from the stats package that is used to assess whether a given numeric vector (x) comes from a normal distribution. The method argument is optional and allows you to choose different variants of the Shapiro-Wilk test. The result object contains the test statistic, p-value, and other information related to the test.

Previous
Previous

The “duplicated” Function in R

Next
Next

The “unique” Function in R