![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Shapiro-Wilk test for univariate normality. More...
#include <algorithm>#include <cmath>#include <cstddef>#include <limits>#include <vector>#include <boost/math/constants/constants.hpp>#include "line/api/sim/sim_dist.h"#include "line/api/sim/sim_types.h"#include "line/num/number.h"#include "line/util/error.h"Go to the source code of this file.
Classes | |
| struct | line::sim::ShapiroWilkResult< T > |
| Outcome of the Shapiro-Wilk normality test. More... | |
Namespaces | |
| namespace | line |
| namespace | line::sim |
Functions | |
| template<class T> | |
| ShapiroWilkResult< T > | line::sim::sim_shapirowilk (const std::vector< T > &x, double alpha=0.05) |
| Shapiro-Wilk test for univariate normality. | |
Shapiro-Wilk test for univariate normality.
Port of matlab/src/api/sim/sim_shapirowilk.m, i.e. Royston's AS R94 algorithm, valid for 3 <= n <= 5000. The statistic is W = (sum_i a_i x_(i))^2 / sum_i (x_i - xbar)^2, where x_(i) are the order statistics and a is the antisymmetric weight vector obtained by correcting the normalized expected normal order statistics m_i = Phi^{-1}((i-3/8)/(n+1/4)) in their two extreme components. Small W means departure from normality, so the test is one-sided in W and the p-value is an upper normal tail after Royston's normalizing transform, which has three branches: n = 3 exact, 4 <= n <= 11, and n >= 12.
The weights are computed in double throughout. They are a function of n alone – Phi^{-1} at fixed plotting positions plus two polynomial corrections with published five-digit coefficients – so refining them past double would refine a constant that is only known to five digits anyway; the sample itself enters in T.
Reference: J. P. Royston, "Approximating the Shapiro-Wilk W-test for Non-normality", Statistics and Computing 2, 1992; J. P. Royston, "Remark AS R94", Applied Statistics 44(4), 1995. W and the p-value agree with scipy.stats.shapiro to 5e-10 and 1.5e-7 respectively over n up to 2000.
Definition in file sim_shapirowilk.h.