Login     Register

        Contact Us     Search

XLeratorDB/statistics Documentation

SQL Server Shapiro and Wilk's W


Updated: 27 June 2012

Note: This documentation is for the SQL2008 (and later) version of this XLeratorDB function, it is not compatible with SQL Server 2005.
Click here for the SQL2005 version of the SWTEST function

Use the aggregate function SWTEST to compute Shapiro and Wilk’s W statistic and its p-value. The p-value is the probability of observing the given result by chance.
syntax for sql server analytic function SWTEST
the sample values. @x is an expression of type float or of a type that can be implicitly converted to float.
identifies the return value as either the Shapiro-Wilk statistic (w) or the p-value (p).
Return Types
·         If @x is null then @x is not included in the aggregate.
·         @statistic must be invariant for the GROUP.
·         SWTEST is an aggregate function and follows the same conventions as all other aggregate functions in SQL Server.
·         @x must have at least 3 rows
In this example, we have two samples, which we have identified as sample 1 and sample 2 and we perform the Shapiro Wilk test on both in a single SELECT, grouping the results by sample number.
SELECT n.s as sample_num
,wct.SWTEST(x,'w') as w_observed
,wct.SWTEST(x,'p') as p_value
      ) n(s,x)
This produces the following result
sample_num             w_observed                p_value
----------- ---------------------- ----------------------
          1      0.900472879494979     0.0420895755448932
          2      0.959026946057681      0.524597930966881

Copyright 2008-2013 WestClinTech LLC         Privacy Policy        Terms of Service