Chapter 7: Tests of Goodness of Fit > shapiro_wilk_normality_test

shapiro_wilk_normality_test

Performs the Shapiro-Wilk test for normality.

Synopsis

#include <imsls.h>

float imsls_f_shapiro_wilk_normality_test (int n_observations, float x[], ..., 0)

The type double function is imsls_d_shapiro_wilk_normality_test.

Required Arguments

int n_observations   (Input)
Number of observations.

float x[]   (Input)
Array of size n_observations containing the observations.

Return Value

The p-value for the Shapiro-Wilk test for normality is returned.

Synopsis with Optional Arguments

#include <imsls.h>

float imsls_f_shapiro_wilk_normality_test (int n_observations, float x[],
IMSLS_SHAPIRO_WILK_W, float *shapiro_wilk_w,
0)

Optional Arguments

IMSLS_SHAPIRO_WILK_W, float *shapiro_wilk_w,  (Output)   
A pointer to a scalar for the Shapiro-Wilk W test statistic.

Description

The Shapiro-Wilk test for normality is thought by D’Agostino and Stevens (1986, p. 406) to be one of the best omnibus tests of normality. The function is based on the approximations and code given by Royston (1982a, b, c; and 1991). The minimum sample size is 3 and sample sizes as large as 5000 have been validated. In the Shapiro and Wilk test, W is given by

where x(i) is the i-th largest order statistic and  is the sample mean. Royston (1982 and 1991) gives approximations and tabled values that can be used to compute the coefficients aii = 1, n, and obtains the significance level of the W statistic.

Example

This example is taken from Conover (1980, pp. 195, 364). The data consists of 50 two-digit numbers taken from a telephone book. The W test fails to reject the null hypothesis of normality at the .05 level of significance.

#include <imsls.h>

#include <stdio.h>

 

int main()

{

  int    n_observations = 50;

  float  x[] = {23.0, 36.0, 54.0, 61.0, 73.0, 23.0,

                37.0, 54.0, 61.0, 73.0, 24.0, 40.0,

                56.0, 62.0, 74.0, 27.0, 42.0, 57.0,

                63.0, 75.0, 29.0, 43.0, 57.0, 64.0,

                77.0, 31.0, 43.0, 58.0, 65.0, 81.0,

                32.0, 44.0, 58.0, 66.0, 87.0, 33.0,

                45.0, 58.0, 68.0, 89.0, 33.0, 48.0,

                58.0, 68.0, 93.0, 35.0, 48.0, 59.0,

                70.0, 97.0};

  float  p_value, shapiro_wilk_w;

 

  /* Shapiro-Wilk test */

  p_value = imsls_f_shapiro_wilk_normality_test (n_observations, x,

      IMSLS_SHAPIRO_WILK_W, &shapiro_wilk_w, 0);

 

  printf ("p-value = %11.4f\n", p_value);

  printf ("Shapiro Wilk W statistic = %11.4f\n",

      shapiro_wilk_w);

 

}

Output

p-value =      0.3473

Shapiro Wilk W statistic =      0.9744


RW_logo.jpg
Contact Support