Sample size

Sample size calculator for the Shapiro–Wilk test

Estimate the number of observations needed to detect deviations from normality with the Shapiro–Wilk test using the Jarque–Bera approximation.

Estimate the number of observations needed for the Shapiro–Wilk test to detect deviations from normality with the target power, using the Jarque–Bera approximation.

Parameters

Enter the skewness and excess kurtosis of the alternative distribution, the significance level and the desired power.

Result pending…

Power curve by sample size

Check the parameters: the chart will appear once they are valid.

Notes: (a) This calculation is only indicative: it relies on the asymptotic Jarque–Bera approximation, which with small samples can be very optimistic against skewed or heavy-tailed alternatives (it underestimates the required n) and pessimistic against light-tailed alternatives such as the uniform. If the sample size matters, verify it by simulation. (b) The Shapiro–Wilk test is valid for 3 ≤ n ≤ 5000; n ≥ 8 is recommended for reasonable power.

Explanation

The Shapiro–Wilk test contrasts the null hypothesis that a sample comes from a normal distribution. Its power depends on how much the real (alternative) distribution differs from the normal, and that difference is mainly quantified by the skewness (\(\gamma_1\)) and excess kurtosis (\(\gamma_2\)) of the alternative distribution. For the normal distribution, \(\gamma_1 = 0\) and \(\gamma_2 = 0\).

Since the Shapiro–Wilk test has no analytical power formula as a function of \(n\), this calculator uses the Jarque–Bera approximation, which combines skewness and kurtosis into an omnibus statistic whose distribution under \(H_0\) is asymptotically \(\chi^2(2)\). The result is approximate in two ways: it replaces the Shapiro–Wilk test with the Jarque–Bera test and, in addition, it assumes that the JB statistic follows a noncentral chi-square distribution, which with small samples can be far from reality. The estimate is therefore not conservative: as the reference table shows, against skewed or heavy-tailed alternatives the \(n\) that Shapiro–Wilk actually needs can be several times larger than the computed one, while against light-tailed alternatives (uniform) it can be smaller.

Power formula (Jarque–Bera approximation)

Under the alternative with shape parameters \(\gamma_1\) and \(\gamma_2\), the noncentrality parameter of the Jarque–Bera statistic for a sample of size \(n\) is:

\( \lambda(n) = n \left(\frac{\gamma_1^2}{6} + \frac{\gamma_2^2}{24}\right) \)

Under \(H_1\), the JB statistic approximately follows a noncentral chi-square distribution with 2 degrees of freedom and noncentrality parameter \(\lambda(n)\). The power of the test at level \(\alpha\) is:

\( 1 - \beta = 1 - F_{\chi^2(2,\,\lambda(n))}\!\left(\chi^2_{1-\alpha,\,2}\right) \)

The noncentral chi-square distribution is evaluated using the Poisson mixture of central chi-squares:

\( F_{\chi^2(df,\lambda)}(x) = \sum_{k=0}^{\infty} \frac{e^{-\lambda/2}(\lambda/2)^k}{k!} \cdot F_{\chi^2(df+2k)}(x) \)

The calculator searches for the minimum integer \(n \geq 3\) for which the computed power exceeds the target.

Reference distributions

The table below shows the moments of several distributions, the sample size returned by this calculator (JB approximation) and the one the Shapiro–Wilk test actually needs according to simulation, in both cases for 80% power with \(\alpha = 0.05\).

Distribution γ₁ (skewness) γ₂ (excess kurtosis) n from JB approximation Actual n with Shapiro–Wilk (simulation)
Exponential 2 6 5 ≈ 19
Log-normal (σ = 0.5) 1.75 5.9 5 ≈ 36
Chi-square (2 df) 2 6 5 ≈ 19
Laplace (double exponential) 0 3 26 ≈ 100
Student's t (5 df) 0 6 7 ≈ 195
Uniform 0 −1.2 161 ≈ 54

The last column is the smallest \(n\) for which the Shapiro–Wilk test reaches 80% power (\(\alpha = 0.05\)) in Monte Carlo simulations with 10,000-20,000 replicates per value of \(n\); the figures are approximate. The comparison shows that the JB approximation can be far off, in both directions.

Quick setup

  • Unknown alternative distribution: if you have no information about γ₁ and γ₂, use the values for the closest distribution in the table above or apply one of the presets.
  • Kurtosis only (symmetric distributions): set γ₁ = 0 and enter the expected γ₂. Keep in mind that detecting kurtosis without skewness requires considerably larger samples.
  • Skewness only: set γ₂ = 0 and enter γ₁. Highly skewed distributions (|γ₁| > 1.5) can be detected with small samples.
  • Alpha: 0.05 is the standard. In confirmatory studies where normality is a critical assumption, consider α = 0.10 to gain power.
  • Power: 0.80 is the usual minimum. For studies where failing to meet normality has serious consequences, use 0.90.

Worked example

A researcher expects response times in an experiment to follow an exponential distribution (\(\gamma_1 = 2\), \(\gamma_2 = 6\)). They want to plan the study so that, if the data really do come from an exponential distribution, the Shapiro–Wilk test rejects normality at least 80% of the time with \(\alpha = 0.05\).

Step 1 — Noncentrality parameter:

\( \lambda(n) = n\!\left(\frac{2^2}{6} + \frac{6^2}{24}\right) = n\!\left(\frac{4}{6} + \frac{36}{24}\right) = n\!\left(0.6\overline{6} + 1.5\right) = n \cdot 2.1\overline{6} \)

Step 2 — Critical value: \(\chi^2_{0.95,\,2} \approx 5.991\).

Step 3 — Approximate power for n = 4 and n = 5:

\( \lambda(4) \approx 8.67 \;\Rightarrow\; 1 - \beta \approx 1 - F_{\chi^2(2,\,8.67)}(5.991) \approx 0.75 < 0.80 \)

\( \lambda(5) \approx 10.83 \;\Rightarrow\; 1 - \beta \approx 1 - F_{\chi^2(2,\,10.83)}(5.991) \approx 0.85 \geq 0.80 \checkmark \)

According to the JB approximation, n = 5 observations would suffice, which is what the calculator returns with the "Exponential" preset. However, in simulation the actual power of the Shapiro–Wilk test against an exponential is only about 16% with \(n = 5\) and 44% with \(n = 10\); about 19 observations are needed to reach 80%. The example shows why the result should be treated as indicative and checked by simulation when the sample size matters.

Model assumptions

  • Random sample of independent observations of a single continuous variable.
  • The null hypothesis of normality is tested against an alternative with given skewness and/or kurtosis.
  • Power is approximated using the Jarque–Bera statistic.
  • The approximation is asymptotic, so it is least reliable precisely with small samples.

Zero skewness and zero excess kurtosis do not characterize the normal distribution. The JB approximation cannot distinguish alternatives sharing these moments; their Shapiro–Wilk power needs a specified alternative and simulation.

How to interpret the result

The value \(n\) is an indicative estimate of the sample size for the Shapiro-Wilk (SW) test to detect the specified deviation from normality with the desired power. The formula relies on the asymptotic Jarque-Bera approximation, which is not conservative: against skewed or heavy-tailed alternatives it can underestimate the required \(n\) several times over (see the reference table), so it should be verified by simulation. Always round up. If you anticipate data loss, divide \(n\) by \((1 - \text{dropout rate})\) to obtain the required recruitment. Keep in mind that SW is only designed for \(3 \leq n \leq 5000\); for \(n > 5000\) it is not directly applicable.

The power of SW to detect non-normality depends on the type of deviation and on \(n\): clearly skewed alternatives are detected with relatively small samples, while symmetric ones require many more observations, especially if they have heavy tails (see the reference table). For \(n < 8\), the power of SW is very low regardless of the effect; if your sample is very small, normality tests have limited practical value and it is preferable to rely on the study design and graphical tools (histogram, Q-Q plot). Perform a sensitivity analysis by varying the target skewness or kurtosis parameter to see how much the required \(n\) changes.

Development and additional details

If the computed \(n\) exceeds 5000, the SW test is not applicable and you should use alternatives such as Kolmogorov-Smirnov (with the Lilliefors correction for estimated parameters), Anderson-Darling, or simply assess normality using graphical methods (Q-Q plot, histogram). With large samples, remember that the p-value of a normality test becomes very sensitive to trivial deviations; in that context, the relevant question is not "are the data exactly normal?" but "do they deviate enough from normality to compromise the statistical procedure?". Once you have collected the data, run the normality test with the Shapiro-Wilk calculator and interpret the result together with the Q-Q plot.

References

  • Razali, N. M. & Wah, Y. B. (2011). Power comparisons of Shapiro–Wilk, Kolmogorov–Smirnov, Lilliefors and Anderson–Darling tests. Journal of Statistical Modeling and Analytics, 2(1), 21–33.
  • D'Agostino, R. B. (1990). A suggestion for using powerful and informative tests of normality. The American Statistician, 44(4), 316–321.
  • Jarque, C. M. & Bera, A. K. (1987). A test for normality of observations and regression residuals. International Statistical Review, 55(2), 163–172.
  • Shapiro, S. S. & Wilk, M. B. (1965). An analysis of variance test for normality (complete samples). Biometrika, 52(3–4), 591–611.

Frequently asked questions

  • What is skewness (γ₁) and excess kurtosis (γ₂)? Skewness measures the degree of tilt in the distribution (\(\gamma_1 = 0\) for symmetric distributions). Excess kurtosis measures the heaviness of the tails relative to the normal (\(\gamma_2 = 0\) for the normal, positive for heavier tails). Any deviation from these zero values indicates non-normality.
  • Why use the Jarque–Bera approximation? Because it provides an analytical power formula based on the noncentral chi-square distribution, allowing the sample size to be computed without simulation. In exchange, the estimate is only indicative and not conservative: against skewed or heavy-tailed alternatives, SW may need considerably more observations than indicated.
  • What sample sizes is the Shapiro–Wilk test valid for? For 3 ≤ n ≤ 5000. For n < 8 power is very low. For n > 5000, the test is excessively sensitive; it is recommended to combine it with graphical analysis (Q-Q plot).
  • Is this calculator valid for detecting kurtosis without skewness? It can be used, but with great caution. With γ₁ = 0, the noncentrality parameter reduces to λ(n) = n·γ₂²/24, but with heavy tails the approximation is especially optimistic: for Student's t with 5 df it gives n = 7, whereas in simulation SW needs about 195 observations. Symmetric distributions with high kurtosis (Student's t, Laplace) require much larger samples than skewed ones.