Skip to main content

    Method document

    Sample size for a chi-square goodness-of-fit test

    How many participants are needed to show that one categorical variable does not follow a stated distribution, from the distribution expected under the null and the one expected in truth. Covers clustering and dropout.

    Engine version 1.0.0 · Reviewed 1 October 2026

    https://statwisely.com/methods/proportions-goodness-of-fit/

    When to use it

    • Testing whether categories occur in stated proportions: equal use of four clinics, or a population’s known distribution of blood groups.

    Not for

    • Two variables against each other. Use the test of independence.

    Notation

    NN
    Number of participants
    kk
    Number of categories
    ei, aie_i,\ a_i
    Category probabilities under the null and the alternative
    ww
    Cohen’s effect size
    α\alpha
    Significance level: the chance of a false positive
    1−β1-\beta
    Power: the chance of detecting the effect if it is real
    ρ\rho
    Intracluster correlation coefficient (ICC)
    mm
    Average number of participants per cluster
    CV\mathrm{CV}
    Coefficient of variation of cluster size
    CC
    Clusters per group
    ℓ\ell
    Expected loss of whole clusters
    qq
    Expected dropout

    Formulas

    Cohen’s w from the two distributions

    w=∑i=1k(ai−ei)2eiw = \sqrt{\sum_{i=1}^{k} \frac{(a_i - e_i)^{2}}{e_i}}

    The chi-square discrepancy per participant between the expected and true distributions [1].

    The smallest N with enough power

    Pr⁡ ⁣(χk−1,λ′2>χk−1, 1−α2)≥1−β,λ=Nw2\Pr\!\left(\chi'^{2}_{k-1,\lambda} > \chi^{2}_{k-1,\,1-\alpha}\right) \ge 1-\beta, \qquad \lambda = N w^{2}

    On k − 1 degrees of freedom. More categories at the same w need more participants.

    Clustering

    DE=1+[(CV2+1) m−1]ρ\mathrm{DE} = 1 + \left[(\mathrm{CV}^{2} + 1)\,m - 1\right]\rho

    When participants are recruited or randomised in clusters, observations within a cluster repeat information, and the sample is multiplied by the design effect. With equal clusters (CV = 0) this is 1 + (m − 1)ρ [2, 3].

    Few clusters

    Ft=(t2(C−1), 1−α/τ+t2(C−1), 1−βz1−α/τ+z1−β)2F_t = \left(\frac{t_{2(C-1),\,1-\alpha/\tau} + t_{2(C-1),\,1-\beta}}{z_{1-\alpha/\tau} + z_{1-\beta}}\right)^{2}

    Optional. A cluster trial is analysed on cluster-level summaries, so its critical values come from t on 2(C − 1) degrees of freedom rather than the normal distribution. With few clusters this costs participants; because C depends on the sample, it is iterated until it settles [4].

    All adjustments together

    nadj=⌈nDE  Ft⌉n_{\text{adj}} = \left\lceil n \mathrm{DE}\;F_t \right\rceil

    The adjustments multiply, in this order, and the result is rounded up once. Any adjustment not used contributes a factor of 1.

    Dropout

    nrecruit=⌈nadj1−q⌉n_{\text{recruit}} = \left\lceil \frac{n_{\text{adj}}}{1 - q} \right\rceil

    Applied last, to the participants actually recruited.

    Clusters to recruit

    C=⌈nrecruitm⌉,Crecruit=⌈C1−ℓ⌉C = \left\lceil \frac{n_{\text{recruit}}}{m} \right\rceil, \qquad C_{\text{recruit}} = \left\lceil \frac{C}{1 - \ell} \right\rceil

    Per group. Losing a whole cluster loses every participant in it, so an expected loss of clusters inflates the clusters recruited rather than the participants.

    Parameters

    Expected distributione1,…,eke_1, \dots, e_k

    Values: One probability per category, each above 0, adding to 1

    The distribution the test is against: the null hypothesis.

    True distribution to detecta1,…,aka_1, \dots, a_k

    Values: One probability per category, each above 0, adding to 1

    The smallest departure from the expected distribution that would matter.

    Significance levelα\alpha

    Values: Between 0 and 1; usually 0.05

    The false-positive rate you accept. A smaller α, for example to allow for several primary outcomes, needs a larger sample.

    Power1−β1-\beta

    Values: Between 0 and 1; usually 0.80 or 0.90

    The chance of a significant result if the assumed effect is real. Funders and ethics committees commonly expect at least 0.80.

    Expected dropoutqqOptional

    Values: 0% up to, but not including, 100%

    The share of participants expected to provide no outcome, from comparable studies. Recruiting more restores the numbers, not the comparability of the groups: if dropout is related to the outcome, the estimate can still be biased.

    Intracluster correlation (ICC)ρ\rhoOptional

    Values: From 0 to 1

    For clustered designs only. Published ICCs for health outcomes in primary-care and community clusters are mostly small, often below 0.05 [5]; prefer an estimate from a comparable trial.

    Average cluster sizemmOptional

    Values: At least 1

    The average number of participants per cluster. Given with the ICC.

    Variation in cluster sizeCV\mathrm{CV}Optional

    Values: 0 or more; 0 for equal clusters

    The SD of cluster sizes divided by their mean. Unequal clusters cost power on their own account [3].

    Expected loss of whole clustersℓ\ellOptional

    Values: 0% up to, but not including, 100%

    Clusters, such as practices or schools, expected to withdraw entirely.

    Correction for few clustersFtF_tOptional

    Values: On or off

    Worth applying when there are few clusters per group, roughly fewer than 15–20.

    Assumptions

    • Participants are independent apart from any clustering specified, each in exactly one category.
    • Every category expects at least 5 participants, so the chi-square approximation holds.
    • With clustering: clusters are independent, with the same ICC throughout, and the analysis accounts for the clustering, for example with a mixed model or cluster-level summaries [2].
    • Dropout is unrelated to the outcome; recruiting more participants restores the numbers but cannot remove bias.

    Worked examples

    Four categories

    Expected 25% in each of four categories; true 35%, 25%, 25% and 15%: w = √(0.04 + 0.04) = 0.283 on 3 degrees of freedom; α = 0.05, 80% power: N = 137.

    Sample size: 137

    Protocol statement

    To detect a departure from the expected distribution of w = 0.283 with 80% power at a significance level of 0.05, using a chi-square goodness-of-fit test across 4 categories, the required sample size is 137 participants. Calculated with StatWisely (statwisely.com) using: N: solve the noncentral chi-square power at λ=Nw² on k-1 df. These are planning estimates; confirm the final design with a qualified statistician.

    Open this example in the calculator

    Allowing for dropout

    Expecting 10% to provide no outcome: 137 / 0.9 = 152.2, so 153 are recruited.

    Needed for analysis: 137 · To recruit: 153

    Protocol statement

    To detect a departure from the expected distribution of w = 0.283 with 80% power at a significance level of 0.05, using a chi-square goodness-of-fit test across 4 categories, the required sample size is 137 participants. Allowing for 10% dropout, 153 participants should be recruited. Calculated with StatWisely (statwisely.com) using: N: solve the noncentral chi-square power at λ=Nw² on k-1 df. These are planning estimates; confirm the final design with a qualified statistician.

    Open this example in the calculator

    Validation

    • Every worked example on this page is recomputed by the StatWisely engine whenever the software is built. If a number or formula here stopped matching the calculator, the release would be stopped until this document was corrected.
    • An independent implementation in R recomputes this test every night and before each production release, and the results are compared with the engine’s.

    How to cite

    StatWisely. Sample size for a chi-square goodness-of-fit test. Method document, engine version 1.0.0, reviewed 2026-10-01. https://statwisely.com/methods/proportions-goodness-of-fit/

    Cite the original references for the formulas your design uses as well.

    References

    1. 1.Cohen J. Statistical Power Analysis for the Behavioral Sciences. 2nd ed. Hillsdale, NJ: Lawrence Erlbaum Associates; 1988.
    2. 2.Donner A, Klar N. Design and Analysis of Cluster Randomization Trials in Health Research. London: Arnold; 2000.
    3. 3.Eldridge SM, Ashby D, Kerry S. Sample size for cluster randomized trials: effect of coefficient of variation of cluster size and analysis method. International Journal of Epidemiology. 2006;35(5):1292–1300. doi:10.1093/ije/dyl129
    4. 4.Hayes RJ, Moulton LH. Cluster Randomised Trials. 2nd ed. Boca Raton: CRC Press; 2017.
    5. 5.Adams G, Gulliford MC, Ukoumunne OC, Eldridge S, Chinn S, Campbell MJ. Patterns of intra-cluster correlation from primary care research to inform study design and analysis. Journal of Clinical Epidemiology. 2004;57(8):785–794. doi:10.1016/j.jclinepi.2003.12.013