def shapiro(x,a=None,reta=False): """ Perform the Shapiro-Wilk test for normality. The Shapiro-Wilk test tests the null hypothesis that the data was drawn from a normal distribution. Parameters ---------- x : array_like Array of sample data. a : array_like, optional Array of internal parameters used in the calculation. If these are not given, they will be computed internally. If x has length n, then a must have length n/2. reta : bool, optional Whether or not to return the internally computed a values. The default is False. Returns ------- W : float The test statistic. p-value : float The p-value for the hypothesis test. a : array_like, optional If `reta` is True, then these are the internally computed "a" values that may be passed into this function on future calls. See Also -------- anderson : The Anderson-Darling test for normality References ---------- .. [1] http://www.itl.nist.gov/div898/handbook/prc/section2/prc213.htm """ N = len(x) if N < 3: raise ValueError("Data must be at least length 3.") if a is None: a = zeros(N,'f') init = 0 else: if len(a) != N//2: raise ValueError("len(a) must equal len(x)/2") init = 1 y = sort(x) a, w, pw, ifault = statlib.swilk(y, a[:N//2], init) if not ifault in [0,2]: warnings.warn(str(ifault)) if N > 5000: warnings.warn("p-value may not be accurate for N > 5000.") if reta: return w, pw, a else: return w, pw
def shapiro(x,a=None,reta=0): """Shapiro and Wilk test for normality. Given random variates x, compute the W statistic and its p-value for a normality test. If p-value is high, one cannot reject the null hypothesis of normality with this test. P-value is probability that the W statistic is as low as it is if the samples are actually from a normal distribution. Output: W statistic and its p-value if reta is nonzero then also return the computed "a" values as the third output. If these are known for a given size they can be given as input instead of computed internally. """ N = len(x) if N < 3: raise ValueError, "Data must be at least length 3." if a is None: a = zeros(N,'f') init = 0 else: assert(len(a) == N/2), "a must be == len(x)/2" init = 1 y = sort(x) a,w,pw,ifault = statlib.swilk(y,a[:N/2],init) if not ifault in [0,2]: print ifault if N > 5000: print "p-value may not be accurate for N > 5000." if reta: return w, pw, a else: return w, pw
def shapiro(x,a=None,reta=0): """Shapiro and Wilk test for normality. Given random variates x, compute the W statistic and its p-value for a normality test. If p-value is high, one cannot reject the null hypothesis of normality with this test. P-value is probability that the W statistic is as low as it is if the samples are actually from a normal distribution. Output: W statistic and its p-value if reta is nonzero then also return the computed "a" values as the third output. If these are known for a given size they can be given as input instead of computed internally. """ N = len(x) if N < 3: raise ValueError, "Data must be at least length 3." if a is None: a = zeros(N,'f') init = 0 else: assert(len(a) == N/2), "a must be == len(x)/2" init = 1 y = sort(x) a,w,pw,ifault = statlib.swilk(y,a[:N/2],init) if not ifault in [0,2]: warnings.warn(str(ifault)) if N > 5000: warnings.warn("p-value may not be accurate for N > 5000.") if reta: return w, pw, a else: return w, pw