ShapiroWilkTest[data]
tests whether data is normally distributed using the Shapiro–Wilk test.
ShapiroWilkTest[data,"property"]
returns the value of "property".
ShapiroWilkTest
ShapiroWilkTest[data]
tests whether data is normally distributed using the Shapiro–Wilk test.
ShapiroWilkTest[data,"property"]
returns the value of "property".
Details and Options
- ShapiroWilkTest performs the Shapiro–Wilk goodness-of-fit test with null hypothesis
that data was drawn from a NormalDistribution and alternative hypothesis
that it was not. - By default, a probability value or
-value is returned. - A small
-value suggests that it is unlikely that the data is normally distributed. - The data can be univariate {x1,x2,…} or multivariate {{x1,y1,…},{x2,y2,…},…}.
- The Shapiro–Wilk test effectively compares the order statistics of data to the theoretical order statistics of a NormalDistribution.
- ShapiroWilkTest[data,dist,"HypothesisTestData"] returns a HypothesisTestData object htd that can be used to extract additional test results and properties using the form htd["property"].
- ShapiroWilkTest[data,dist,"property"] can be used to directly give the value of "property".
- Properties related to the reporting of test results include:
-
"PValue"
-value"PValueTable" formatted version of "PValue" "ShortTestConclusion" a short description of the conclusion of a test "TestConclusion" a description of the conclusion of a test "TestData" test statistic and
-value"TestDataTable" formatted version of "TestData" "TestStatistic" test statistic "TestStatisticTable" formatted "TestStatistic" - The following properties are independent of which test is being performed.
- Properties related to the data distribution include:
-
"FittedDistribution" fitted distribution of data "FittedDistributionParameters" distribution parameters of data - The following options can be given:
-
Method Automatic the method to use for computing
-valuesSignificanceLevel 0.05 cutoff for diagnostics and reporting - For a test for goodness of fit, a cutoff
is chosen such that
is rejected only if
. The value of
used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the SignificanceLevel option. By default,
is set to 0.05. - With the setting Method->"MonteCarlo",
datasets of the same length as the input
are generated under
using the fitted distribution. The EmpiricalDistribution from ShapiroWilkTest[si,"TestStatistic"] is then used to estimate the
-value.
Examples
open all close allBasic Examples (2)
Perform a Shapiro–Wilk test for normality:
data = RandomVariate[NormalDistribution[], 10^3];ShapiroWilkTest[data]Show[SmoothHistogram[data, PlotStyle -> Orange], Plot[PDF[NormalDistribution[], x], {x, -4, 4}], PlotRange -> {0, .4}]Perform a test for multivariate normality:
data = RandomVariate[MultinormalDistribution[{1, 2, 3}, IdentityMatrix[3]], 1000];ShapiroWilkTest[data, "TestDataTable"]The test statistic and
-value:
ShapiroWilkTest[data, "TestData"]Scope (6)
Testing (3)
Perform a Shapiro–Wilk test for normality:
data1 = RandomVariate[NormalDistribution[], 2500];
data2 = RandomVariate[StudentTDistribution[3], 2500];The
-value for the normal data is large compared to the
-value for the non-normal data:
ShapiroWilkTest[data1]ShapiroWilkTest[data2]Test for multivariate normality:
data1 = RandomVariate[BinormalDistribution[.5], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], {10^3, 2}];ShapiroWilkTest[data1]ShapiroWilkTest[data2]Create a HypothesisTestData object for repeated property extraction:
data = RandomVariate[NormalDistribution[], 10^3];ℋ = ShapiroWilkTest[data, "HypothesisTestData"]The properties available for extraction:
ℋ["Properties"]Reporting (3)
Tabulate the results of the Shapiro–Wilk test:
data = RandomVariate[NormalDistribution[], 100];ℋ = ShapiroWilkTest[data, "HypothesisTestData"];ℋ["TestDataTable"]ℋ["PValueTable"]ℋ["TestStatisticTable"]Retrieve the entries from a Shapiro–Wilk test table for custom reporting:
data1 = RandomVariate[NormalDistribution[], 100];
data2 = RandomVariate[NormalDistribution[], 100];ℋ1 = ShapiroWilkTest[data1, "TestData"]ℋ2 = ShapiroWilkTest[data2, "TestData"]BarChart[{Labeled[ℋ1, "Set 1"], Labeled[ℋ2, "Set 2"]}, ChartLabels -> {"SubscriptBox[D, n]", "p‐value"}]Report test conclusions using "ShortTestConclusion" and "TestConclusion":
data = BlockRandom[SeedRandom[1];RandomVariate[StudentTDistribution[3], 100]];ℋ = ShapiroWilkTest[data, "HypothesisTestData"];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormThe conclusion may differ at a different significance level:
ℋ = ShapiroWilkTest[data, "HypothesisTestData", SignificanceLevel -> .001];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormOptions (3)
Method (3)
Use Monte Carlo-based methods or a computation formula:
data = RandomVariate[NormalDistribution[], 100];ShapiroWilkTest[data, Method -> "MonteCarlo"]ShapiroWilkTest[data, Method -> Automatic]Set the number of samples to use for Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, ShapiroWilkTest[data, Method -> {"MonteCarlo", "MonteCarloSamples" -> i}]}, {i, Range[5, 1000, 50]}];The Monte Carlo estimate converges to the true
-value with increasing samples:
pval = ShapiroWilkTest[data];Show[ListLinePlot[pts, PlotRange -> {0, 1}, FrameLabel -> {"Samples", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {1000, pval}}]}]]Set the random seed used in Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, ShapiroWilkTest[data, Method -> {"MonteCarlo", "RandomSeed" -> i}]}, {i, Range[1, 10]}];The seed affects the state of the generator and has some effect on the resulting
-value:
pval = ShapiroWilkTest[data];Show[ListLinePlot[pts, PlotRange -> {Min[pts[[All, 2]]], Max[pts[[All, 2]]]}, FrameLabel -> {"Seed", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {100, pval}}]}]]Applications (2)
A power curve for the Shapiro–Wilk test:
data = Table[RandomVariate[CauchyDistribution[0, 1], {500, i}], {i, n = {10, 15, 20, 25, 30}}];ℋ = Table[ShapiroWilkTest[data[[i, j]]], {i, Length[data]}, {j, Length[data[[i]]]}];pC = Interpolation[Transpose[{n, Table[Probability[x ≤ 0.05, xi], {i, ℋ}]}], InterpolationOrder -> 1];Visualize the approximate power curve:
Plot[pC[x], {x, 10, 30}, PlotRange -> {0, 1}, Ticks -> {n, Automatic}, AxesOrigin -> {7, 0}]Estimate the power of the Shapiro–Wilk test when the underlying distribution is a CauchyDistribution[0,1], the test size is 0.05, and the sample size is 12:
pC[12.]The boiling point of water was measured at varying altitudes in the Alps. The barometric pressure was recorded for each boiling point. Determine if a linear model is appropriate for use in predicting boiling points given pressure:
ExampleData[{"Statistics", "BoilingAlps"}, "LongDescription"]data = Reverse /@ ExampleData[{"Statistics", "BoilingAlps"}];lm = LinearModelFit[data, x, x];A plot of the model and the data:
Show[ListPlot[data], Plot[lm[x], {x, 20, 31}, PlotStyle -> Dashed], Frame -> True]For the model to be appropriate, the residuals should be normally distributed:
ShapiroWilkTest[lm["FitResiduals"], "TestDataTable"]A QuantilePlot confirms that the linear model is not appropriate for this data:
QuantilePlot[lm["FitResiduals"]]Properties & Relations (3)
ShapiroWilkTest compares the order statistics of the data to their expectations under
:
n = 15;data = Standardize@Sort@RandomVariate[NormalDistribution[], n];𝒟 = OrderDistribution[{NormalDistribution[], n}, #]&;Expected values of the order statistics and an estimate of their covariance matrix:
m = Table[NExpectation[x, x𝒟[i]], {i, n}];v = Covariance[Map[Sort, RandomVariate[NormalDistribution[], {10 ^ 6, n}]]];These are used to compute weights:
vInv = Inverse[v];a = (m.vInv/(m.vInv.vInv.m)^1 / 2);The statistic using the estimated covariance matrix is slightly different from the reported value:
w = (Total[a * data]^2/Total[(Standardize[data])^2])ShapiroWilkTest[data, "TestStatistic"]For tests of multivariate normality, a transformation to univariate data is made:
n = 500;data = RandomVariate[NormalDistribution[], {n, 3}];swilkMV[data_] := Block[{r, m, rm, max, mrm}, r = Standardize[data, Mean, 1&];
m = Inverse[r.r];
rm = Diagonal[r.m.r];
max = Flatten[Position[rm, Max[rm]]][[1]];
mrm = m.r[[All, max]];
Sort[mrm.Transpose[data]]
]The data has been transformed to approximate univariate normal data:
SmoothHistogram[swilkMV[data], Ticks -> {{-(10./n), 0, (10./n)}, None}]Perform the test on the transformed data:
ShapiroWilkTest[swilkMV[data], "TestDataTable"]The result agrees with a test of the original data:
ShapiroWilkTest[data, "TestDataTable"]The Shapiro–Wilk test works with the values only when the input is a TimeSeries:
ts = TemporalData[TimeSeries, {{{1.224578634529677, 0.47929635789978015, 0.6572781300178168,
0.21496048742669355, 0.7299608014554928, -0.2495111111278263, -1.3286551762002712,
0.552725018274874, 0.19272112205837066, 1.1809144012420882, -1.1671 ... 40938613662046, 1.052394590214582, 0.9345044123980388, 0.38537803109557855,
-0.48660931166089394, -0.71203560340161}}, {{0, 100, 1}}, 1, {"Continuous", 1},
{"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];ShapiroWilkTest[ts]ShapiroWilkTest[ts["Values"]]Possible Issues (1)
Neat Examples (1)
Compute the statistic when the null hypothesis
is true:
data1 = RandomVariate[NormalDistribution[], {250, 100}];T1 = ShapiroWilkTest[#, "TestStatistic"]& /@ data1;The test statistic given a particular alternative:
data2 = RandomVariate[ChiSquareDistribution[50], {250, 100}];T2 = ShapiroWilkTest[#, "TestStatistic"]& /@ data2;Compare the distributions of the test statistics:
SmoothHistogram[{T1, T2}, Filling -> Axis, PlotLegends -> {"SubscriptBox[H, 0] is True", "SubscriptBox[H, 0] is False"}, PlotStyle -> Thick]Related Guides
History
Text
Wolfram Research (2010), ShapiroWilkTest, Wolfram Language function, https://reference.wolfram.com/language/ref/ShapiroWilkTest.html.
CMS
Wolfram Language. 2010. "ShapiroWilkTest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ShapiroWilkTest.html.
APA
Wolfram Language. (2010). ShapiroWilkTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ShapiroWilkTest.html
BibTeX
@misc{reference.wolfram_2026_shapirowilktest, author="Wolfram Research", title="{ShapiroWilkTest}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ShapiroWilkTest.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_shapirowilktest, organization={Wolfram Research}, title={ShapiroWilkTest}, year={2010}, url={https://reference.wolfram.com/language/ref/ShapiroWilkTest.html}, note=[Accessed: 13-June-2026]}