UK-based online statistics and data analysis support for USA, UK, and international clients. No exams, no impersonation, no fabricated data.
Nonparametric Tests

Ansari–Bradley Test: Formula, Assumptions, Worked Example, Python, R, SPSS, SAS and Excel Guide

Nonparametric two-sample scale analysis with tied-data verification Ansari–Bradley Test: Formula, Assumptions, Worked Example, Python, R, SPSS, SAS and Excel Guide The Ansari–Bradley test compares the scale...

Statistics guide Ethical learning support SPSS/R/Python/Excel friendly

Nonparametric two-sample scale analysis with tied-data verification

Ansari–Bradley Test: Formula, Assumptions, Worked Example, Python, R, SPSS, SAS and Excel Guide

The Ansari–Bradley test compares the scale or dispersion of two independent populations without requiring normality. This evidence-first guide analyses G3 final grades for 649 students by family educational support, audits the equal-location condition, reconstructs the symmetric-score statistic, reconciles asymptotic and deterministic permutation results, and verifies the analysis across Python, R, SPSS, SAS and Excel.

649 complete cases
251 without support
398 with support
Both medians = 12
A = 40,094.5
p = .5183

Ansari–Bradley Test Model Overview

The Ansari–Bradley test is a rank-based procedure for comparing the scale parameters of two independent groups. In practical terms, scale describes how tightly observations cluster around a common location. The method does not compare the group means, does not test whether the medians differ, and does not ask whether every feature of the two distributions is identical. It asks a narrower question: after the groups have a defensible common location, is one population systematically more dispersed than the other?

The worked analysis compares final grade G3 between students whose family educational support variable famsup is coded no and yes. The group medians are both 12 and the interquartile ranges are both 4, providing a favourable starting point for a scale-focused test. Nevertheless, the unsupported group has a larger standard deviation, 3.6022 versus 2.9674, and a larger variance, 12.9756 versus 8.8052. The formal analysis determines whether that descriptive difference is large relative to the sampling variation in the Ansari–Bradley score sum.

Layer 1DesignTwo independent groups and one numeric outcome.
Layer 2ValidityCommon median, comparable shape and tied-data handling.
Layer 3StatisticSymmetric pooled scores summed for the focal group.
Layer 4VerificationAsymptotic and deterministic permutation evidence agree.
Worked-result preview: A = 40,094.500, E(A) = 40,850.3467, tie-adjusted SE = 1,169.9850, z = 0.646031, asymptotic p = 0.518259 and deterministic permutation p = 0.510849. At α = .05, the analysis does not provide sufficient evidence that the G3 scale differs between the two family-support groups.
Critical interpretation boundary: the result is not evidence that the two variances are exactly equal. It means the observed symmetric-score difference is not sufficiently extreme to reject the equal-scale model with these data and this test.
AdvertisementGoogle AdSense top placement reserved here

Quick Answer: Ansari–Bradley Test Result

Sample X: famsup = no25138.67% of sample
Sample Y: famsup = yes39861.33% of sample
A statistic40,094.5symmetric-score sum
Z statistic0.6460workbook sign convention
Asymptotic p0.5183tie-adjusted normal result
Permutation p0.510810,000 deterministic reallocations

Statistical Decision

  • Null hypothesis: the population scale ratio equals 1.
  • Alternative: the scale ratio differs from 1.
  • Alpha: .05.
  • Decision: fail to reject H0.
  • Evidence: asymptotic and permutation results agree.

Substantive Meaning

  • Both group medians are 12.
  • Both group IQRs are 4.
  • The no-support SD is descriptively 21.39% larger.
  • The variance ratio is 1.4736.
  • The formal scale evidence remains weak, |z|/√N = 0.0254.
Plain-language conclusion: the G3 scores of students without family educational support look somewhat more variable because that group contains more very low grades, especially zeros. However, the Ansari–Bradley statistic and permutation check do not establish a statistically significant population-scale difference.

Table of Contents

  1. Research question and hypotheses
  2. When to use the test
  3. Assumption and validity gate
  4. Variables and analysis design
  5. Descriptive data audit
  6. Distribution forensics
  7. How symmetric scores work
  8. Formula and manual calculation
  9. Ties, exact and permutation inference
  10. Complete results
  11. Data discussion and interpretation
  12. Robustness and sensitivity
  13. Python chart stories
  14. R verification gallery
  15. Software workflows
  16. Expandable code
  17. Cross-software reconciliation
  18. Related-test comparison
  19. APA reporting
  20. Common mistakes
  21. Practice questions
  22. Downloads
  23. Related guides
  24. Frequently asked questions
  25. Conclusion

Research Question, Hypotheses and Direction

OutcomeG3 final grade, recorded from 0 to 19 in the analysed data.
Grouping variableFamily educational support: no versus yes.
Target parameterRelative scale or dispersion, not a difference in means or medians.

Research Question

Do the population distributions of G3 have different scale parameters for students without and with family educational support, given a defensible common location?

ComponentFormal statementInterpretation
Null hypothesisH0: s = 1The two populations have the same scale parameter.
Two-sided alternativeH1: s ≠ 1The population scales differ in either direction.
Directional conventionSmaller A for sample XMore sample-X observations occupy the pooled extremes, consistent with larger X scale.
Current focal sampleX = famsup noThe reported A statistic sums symmetric scores for the no-support group.

The two-sided alternative was prespecified. A one-sided conclusion should not be selected after seeing that the unsupported group has the larger sample standard deviation. Directional testing requires a defensible prior scientific hypothesis.

For the wider logic of formal decisions, review hypothesis testing, null and alternative hypotheses and the interpretation of a p-value.

When to Use the Ansari–Bradley Test

Step 1Two independent groups?

If observations are paired or repeated, choose a paired procedure instead.

Step 2Scale is the question?

If the scientific question is location, do not substitute a scale test.

Step 3Common location plausible?

Inspect medians and distribution shapes before interpreting the result as scale.

Strong Use Case

  • Two independent samples.
  • Numeric or meaningfully ordered outcome.
  • Non-normality, outliers or heavy tails make a normal-theory variance test unattractive.
  • A common median or aligned location is scientifically defensible.
  • The primary question concerns dispersion.

Choose Another Method When

  • Three or more groups require a k-sample scale test.
  • Medians differ materially.
  • The research question concerns general distribution equality.
  • Observations are clustered or weighted.
  • The outcome contains only a few unordered categories.

Research Question to Method Map

QuestionPreferred starting methodWhy
Two independent groups: central tendencyMann–Whitney, Brunner–Munzel or a robust location modelTargets location or stochastic ordering rather than scale.
Two independent groups: scale onlyAnsari–Bradley, Mood or Siegel–TukeyUses rank scores designed for dispersion differences.
Three or more groups: robust spreadFligner–Killeen or Brown–ForsytheExtends scale comparison beyond two groups.
Normal two-group variance comparisonF testDirectly targets a variance ratio under normality.
Simultaneous location and scaleLepage-type procedure or separate prespecified testsA single scale test cannot identify both components.

The selection step is essential. Calling every rank-based procedure “a nonparametric alternative to the t test” is incorrect. The Ansari–Bradley score pattern is intentionally sensitive to observations at the pooled extremes.

Assumption and Validity Gate

A nonparametric label does not mean assumption-free. The result is meaningful only when the study design and distributional conditions support a scale interpretation.

Independent Observations — Pass

Each of the 649 students contributes one G3 value to one family-support group. The analysis does not reuse students across groups.

Exactly Two Groups — Pass

famsup contains the two analysed levels, no and yes, with n = 251 and n = 398.

Common Median — Supported

Both sample medians equal 12. The central 50% also spans 10 to 14 in both groups.

Comparable Shape — Review

The unsupported group is more negatively skewed and has more zero grades. The ECDF and frequency tables therefore belong in the interpretation.

Ties — Explicitly Corrected

G3 is integer-valued, creating many tied ranks. The asymptotic variance is tie-adjusted and the result is checked by permutation.

Sampling and Causality — Limited

The observed association does not show that family support causes a change in dispersion. Generalisation depends on the sampling design.

Assumption Audit Table

ConditionObserved evidenceJudgmentReporting implication
IndependenceOne row per student; mutually exclusive groupsReasonableUse a two-sample procedure.
Common locationMedian 12 in both groups; Q1 = 10 and Q3 = 14 in bothSupported descriptivelyScale interpretation is defensible.
Similar distribution familyBoth concentrate around 10–14, but tail weights differApproximate, not perfectDiscuss tails and skewness rather than claiming pure rescaling.
ContinuityG3 is discrete integer data with extensive tiesNot met literallyUse tie correction and permutation verification.
Random samplingNot established by the statistical outputUnknownAvoid causal or population-wide claims.
Do not skip the common-location check: if the two groups have different medians, extreme-versus-central scores can react to location as well as scale. A significant result might then be misleading as a pure dispersion test.

Variables, Coding and Analysis Specification

VariableRoleCodingValid NPurpose
student_idRecord identifier1–649649Confirms one row per student.
G3Numeric outcomeObserved 0–19649Final grade whose scale is compared.
famsupGrouping variableno / yes649Defines the two independent samples.
Sample XFocal score-sum groupfamsup = no251Its symmetric scores are summed to form A.
Sample YComparison groupfamsup = yes398Completes the pooled reference distribution.
AlternativeTwo-sided scale difference
Alpha0.05
Missing observations0 in the analysis variables

Reproducible Analysis Statement

G3 was analysed as a numeric outcome and family educational support (famsup) as a two-level independent grouping variable. The no-support group was designated sample X. The analysis used a two-sided Ansari–Bradley test, midranks for tied G3 values, a tie-adjusted asymptotic variance and a deterministic 10,000-permutation robustness check.

Descriptive Data Audit Before the Test

The formal statistic should never be interpreted without first locating the descriptive difference. Here the centre of the two groups is nearly identical, while the tail behaviour differs more than the middle 50%.

Statisticfamsup = nofamsup = yesNo − yesAnalytical meaning
N251398−147The groups are unbalanced but both are large.
Mean11.665312.0578-0.3925Location is close; the test is not about this difference.
5% trimmed mean11.947112.1139-0.1668Removing tail observations narrows the mean difference.
Median12.000012.00000Supports the common-location requirement.
Q110.000010.00000Lower quartiles match.
Q314.000014.00000Upper quartiles match.
IQR4.00004.00000Central dispersion is identical descriptively.
Standard deviation3.60222.96740.6348The unsupported group looks more dispersed.
Variance12.97568.80524.1703Descriptive variance ratio = {variance_ratio:.4f}.
Skewness-1.188-0.519-0.669The no-support distribution has a heavier lower tail.
Excess kurtosis2.7761.9260.850Tail concentration differs descriptively.
SD ratio: no / yes1.2139descriptive only
Variance ratio: no / yes1.4736descriptive only
Zero grades: no11 (4.38%)more lower-tail mass
Zero grades: yes4 (1.01%)smaller lower tail
Grades below 8: no17 (6.77%)includes zeros
Grades below 8: yes13 (3.27%)smaller percentage
Key data insight: the larger standard deviation in the no-support group is not accompanied by a larger IQR. The difference is concentrated mainly in the lower tail, where 4.38% of the no-support group has G3 = 0 compared with 1.01% of the support group.

For interpretation of these summaries, see descriptive statistics, standard deviation, variance and the interquartile range.

Distribution Forensics: Where the Apparent Spread Difference Comes From

The complete frequency table shows that both groups concentrate between G3 = 10 and G3 = 14. The main imbalance appears at the lower extreme rather than throughout the entire distribution.

G3No countNo %Yes countYes %Total
0114.38%41.01%15
100.00%10.25%1
200.00%00.00%0
300.00%00.00%0
400.00%00.00%0
510.40%00.00%1
610.40%20.50%3
741.59%61.51%10
883.19%276.78%35
9187.17%174.27%35
103915.54%5814.57%97
113815.14%6616.58%104
122811.16%4411.06%72
132610.36%5614.07%82
142710.76%369.05%63
15218.37%287.04%49
16124.78%246.03%36
17114.38%184.52%29
1851.99%102.51%15
1910.40%10.25%2
2000.00%00.00%0

Tail and Centre Audit

RegionNo groupYes groupInterpretation
G3 = 011 / 251 = 4.38%4 / 398 = 1.01%The unsupported group contributes most of the extreme lower tail.
G3 < 817 / 251 = 6.77%13 / 398 = 3.27%Low grades are proportionally more common without support.
G3 = 10–14158 / 251 = 62.95%260 / 398 = 65.33%The central grade region is very similar.
G3 ≥ 1717 / 251 = 6.77%29 / 398 = 7.29%The upper tail is proportionally similar.
Q1 to Q310 to 1410 to 14The middle half has the same observed width.

Why the SDs Differ

Standard deviation gives substantial weight to observations far from the mean. The eleven zeros in the no-support group increase its variance even though both groups have the same median and IQR.

Why the Test Is Still Nonsignificant

The Ansari–Bradley statistic evaluates the complete pooled pattern of central and extreme ranks. The observed excess of extremes is modest relative to the tie-adjusted null variability.

The histograms, boxplot and ECDF should therefore be read together. A boxplot emphasizes the shared central spread, while the histograms and ECDF reveal the lower-tail difference. Review frequency distributions and box-plot interpretation for the descriptive background.

How Ansari–Bradley Symmetric Scores Work

The two samples are pooled and sorted. Scores are assigned from both extremes toward the centre. Extreme pooled observations receive small scores, and observations near the pooled centre receive large scores. The statistic A is the sum of the symmetric scores attached to sample X.

PoolCombine the samples

Ignore group labels temporarily and sort all G3 values together.

ScoreRank from both ends

The lowest and highest positions receive the smallest scores.

SumRestore group labels

Add the scores belonging to the focal no-support group.

Small Conceptual Example

Pooled position12345678
Symmetric score12344321
Interpretationextremeouterinnercentrecentreinnerouterextreme

A group with many observations at both pooled extremes tends to receive a smaller score sum. A group concentrated near the pooled centre tends to receive a larger score sum. This is why the direction of A must be interpreted relative to its expected value and the selected focal group.

Observed Score Assignment by G3 Value

G3No countYes countPooled countAverage rankSymmetric scoreNo contribution to A
0114158.08.088.0
101116.016.00.0
510117.017.017.0
612319.019.019.0
7461025.525.5102.0
88273548.048.0384.0
918173583.083.01494.0
10395897149.0149.05811.0
113866104249.5249.59481.0
12284472337.5312.58750.0
13265682414.5235.56123.0
14273663487.0163.04401.0
15212849543.0107.02247.0
16122436585.564.5774.0
17111829618.032.0352.0
1851015640.010.050.0
19112648.51.51.5
Reading the contribution table: G3 = 10 and G3 = 11 contribute heavily to A because they are common and relatively central. G3 = 0 and G3 = 19 receive very small symmetric scores because they occupy the pooled extremes.

Ansari–Bradley Formula and Full Manual Calculation

Step 1: Define the Statistic

A = Σ a(Ri) for observations belonging to sample Xa(Ri) is the symmetric score associated with the pooled rank.

For the 251 students in the no-support group, the summed score is:

A = 40,094.500

Step 2: Expected A for an Odd Total Sample Size

E(A) = nX(N + 1)2 / (4N)
E(A) = 251(650)2 / [4(649)] = 40,850.346687

Step 3: Tie-Adjusted Variance

Because G3 contains repeated integers, the calculation uses midranks and the sum of squared symmetric scores. For odd N, the workbook applies:

Var(A) = nXnY[16NΣai2 − (N + 1)4] / [16N2(N − 1)]
ComponentValue
nX251
nY398
N649
Σai222,953,176.5
Tie-adjusted variance1,368,865.001712
Standard error1,169.985043

Step 4: Standardize the Score Sum

The validated workbook and transcripts use the direction E(A) − A. Other software may reverse the sign. For a two-sided test, reversing the sign does not change the p-value.

z = [E(A) − A] / SE(A) = [40,850.346687 − 40,094.500] / 1,169.985043 = 0.646031

Step 5: Two-Sided Probability

p = 2[1 − Φ(|z|)] = 0.518259
Calculation audit: the observed A is 755.8467 points below expectation, but this is only 0.646 standard errors from the null centre. The observed deviation is therefore ordinary under the equal-scale model.

Ties, Exact Inference, Asymptotic Inference and Permutation Verification

G3 takes integer values and contains large tie blocks. This affects both the available reference distribution and the variance calculation. A strong analysis should state the inference method explicitly rather than reporting a p-value without its computational basis.

MethodWhen it is appropriateTie handlingCurrent result
Exact distributionSmall samples without tiesStandard exact calculation generally assumes no tiesNot the primary method for this dataset.
Tie-adjusted asymptoticLarge samples or tied observationsCorrects the normal-approximation variancep = 0.518259.
Permutation / Monte CarloRobustness check when exact enumeration is impracticalPreserves observed values and reallocates group labelsp = 0.510849 from 10,000 deterministic permutations.
Agreement criterionCompare methods, not only thresholdsClose p-values increase confidence in the decisionBoth methods fail to reject.

Why Exact Enumeration Is Not Used

There are 649 observations and extensive ties. The number of possible reallocations is enormous, and a no-tie exact distribution is not an appropriate representation of this data structure.

Why the Permutation Check Matters

The permutation distribution directly asks how often a random reassignment of the fixed G3 values produces an A statistic at least as far from its null expectation as the observed statistic.

Result agreement: the absolute difference between the asymptotic and permutation p-values is only 0.007410. The scientific decision is not sensitive to the chosen large-sample reference method.

Complete Ansari–Bradley Test Results

Observed A40,094.500no-support score sum
Expected A40,850.3467under equal scale
Difference A − E(A)-755.8467negative direction
Tie-adjusted SE1,169.9850null standard deviation
Z statistic0.646031reported sign
Two-sided p0.518259fail to reject
AnalysisStatisticReference methodP-valueDecision
Primary Ansari–Bradley testA = 40,094.500; z = 0.646031Tie-adjusted asymptotic normal0.518259Fail to reject H0
Robustness verification10,000 deterministic reallocationsPermutation distribution0.510849Fail to reject H0

Descriptive and Inferential Evidence Side by Side

Evidence typeObserved valueWhat it supportsWhat it does not support
Median comparison12 versus 12A common central location is plausible.It does not prove identical distributions.
IQR comparison4 versus 4The middle 50% has the same sample width.It does not describe the extreme tails.
SD comparison3.6022 versus 2.9674The no-support sample is descriptively more variable.It does not establish a population scale difference.
Variance ratio1.4736The sample variance is 47.36% larger without support.It is not the Ansari–Bradley test statistic.
Ansari–Bradley p0.5183The observed scale-score difference is not unusual under H0.It does not prove that the scale ratio is exactly 1.
Formal conclusion: at α = .05, fail to reject the null hypothesis of equal scale. The data do not provide statistically significant evidence that the dispersion of G3 differs between students without and with family educational support.
AdvertisementGoogle AdSense placement reserved after the Results section

Data Discussion: Why a 47% Variance Ratio Can Still Be Nonsignificant

The sample variance ratio of 1.4736 looks substantial in isolation, but variance is highly responsive to extreme observations. The no-support group contains eleven zero grades, compared with four in the larger support group. This lower-tail concentration inflates the variance while leaving the median and interquartile range unchanged.

The Ansari–Bradley test does not compare the two sample variances directly. It converts all 649 observations to symmetric pooled scores and evaluates the score allocation between groups. The no-support score sum is below its null expectation, a direction consistent with more extreme observations in sample X. However, the standardized displacement is only 0.646, far inside the ordinary central region of a standard normal reference distribution.

ObservedMore lower-tail gradesZeros are proportionally more common without family support.
DescriptiveLarger SD and variance3.6022 versus 2.9674; ratio 1.4736.
Rank evidenceA below expectationDirection suggests broader sample-X spread.
InferenceWeak standardized signalz = 0.6460 and p = .5183.

What the Result Says

  • The observed data are compatible with an equal-scale population model.
  • The two inference methods give nearly identical decisions.
  • The centre and middle 50% are extremely similar.
  • The apparent descriptive difference is driven more by the lower tail than by a general widening of the distribution.

What the Result Does Not Say

  • It does not prove that family support has no relationship with grades.
  • It does not show that every measure of variability is equal.
  • It does not establish equivalence within a prespecified practical margin.
  • It does not convert an observational comparison into a causal effect.
Better wording: write “no statistically significant scale difference was detected,” not “the groups have equal variance.”

Robustness, Sensitivity and Reporting Checks

Reference-distribution check

Asymptotic p = .5183 and permutation p = .5108 agree.

Common-location check

Both medians equal 12; trimmed means differ by only 0.167.

Central-spread check

Both IQRs equal 4 and both quartile ranges are 10–14.

Tail check

The no-support group has more zeros and stronger negative skew.

Direction check

A below E(A) is consistent with more no-group extremes.

Effect signal check

|z|/√N = 0.0254, a very small standardized departure.

One-Sided Sensitivity

A directional alternative such as “the no-support group has larger scale” would require an a priori hypothesis. Using the observed z magnitude, a one-sided normal probability would still be far above .05. The result is therefore not close to significance in either a defensible two-sided analysis or a postulated directional analysis.

Equivalence Is a Different Question

Failing to reject equal scale is not an equivalence test. To claim practically equivalent dispersion, analysts must specify an acceptable scale-ratio margin before analysis and use a method designed to test whether the entire confidence interval lies inside that margin.

Python Visual Evidence: Seven Chart Stories

Each chart answers a different part of the analysis. The narrative emphasizes exact values, statistical meaning and limitations instead of using images as decoration.

Python Output Summary

Python

Python Ansari–Bradley V4 report summary with group descriptives and test results.
Python Ansari–Bradley V4 report summary with group descriptives and test results.
Exact evidence

The report records n = 251 and 398, both medians = 12, A = 40,094.5, z = 0.646031, asymptotic p = 0.518259 and permutation p = 0.510849.

Statistical meaning

The summary reconciles the entire calculation in one place and confirms that the formal result concerns scale, not mean G3.

Do not overread it: A screenshot is evidence of output, but HTML tables remain necessary for accessibility, mobile reading and search indexing.
Next analytical step: Use the following charts to identify where the descriptive spread difference occurs.

Group Distributions

Python

Python histograms of G3 for famsup no and yes.
Python histograms of G3 for famsup no and yes.
Exact evidence

The no-support group peaks at G3 = 10–11 and contains 11 zeros; the support group peaks at G3 = 10–13 and contains 4 zeros.

Statistical meaning

Both distributions have similar central concentration, but the unsupported group has a visibly heavier lower extreme.

Do not overread it: Different vertical frequencies partly reflect unequal group sizes, so compare percentages and shapes rather than raw bar heights alone.
Next analytical step: Inspect the boxplot and ECDF to separate central spread from tail behaviour.

Boxplot by Family Educational Support

Python

Python boxplot of G3 by family educational support.
Python boxplot of G3 by family educational support.
Exact evidence

Both boxes extend from Q1 = 10 to Q3 = 14 with median = 12. The no group shows zero-grade outliers; the yes group shows zero and one-grade outliers.

Statistical meaning

The central 50% is identical, while the lower extremes account for much of the SD difference.

Do not overread it: A boxplot compresses the frequency pattern and cannot show how many observations occur at each integer value.
Next analytical step: Use the ECDF to compare the full cumulative distributions.

Empirical Cumulative Distributions

Python

Python ECDF curves for G3 by family educational support.
Python ECDF curves for G3 by family educational support.
Exact evidence

The curves are close through most of the grade range. The largest visible separation is in the low-grade region where the no-support cumulative proportion rises earlier.

Statistical meaning

Close ECDFs support the conclusion that there is no broad, dramatic scale separation.

Do not overread it: The Ansari–Bradley test does not directly test the maximum ECDF gap; it uses symmetric rank scores.
Next analytical step: Compare the SD and IQR panel to quantify central and overall dispersion.

Descriptive Dispersion Comparison

Python

Python chart comparing standard deviation and IQR by group.
Python chart comparing standard deviation and IQR by group.
Exact evidence

SD is 3.6022 versus 2.9674, while both IQRs equal 4.

Statistical meaning

The split between SD and IQR tells an important story: tail observations differ more than the central half.

Do not overread it: A bar chart of descriptive measures does not attach inferential uncertainty to the difference.
Next analytical step: Inspect the score chart to see how pooled positions translate into the test statistic.

Average Symmetric Score by G3

Python

Python line chart of average symmetric Ansari–Bradley score by observed G3.
Python line chart of average symmetric Ansari–Bradley score by observed G3.
Exact evidence

Scores rise from the extremes toward the pooled centre and peak around G3 = 12, then decline toward the upper extreme.

Statistical meaning

This shape explains the test: central grades contribute large scores, while very low and very high grades contribute small scores.

Do not overread it: The score curve depends on the pooled empirical distribution and tie structure; it is not a universal score for each grade.
Next analytical step: Use the permutation distribution to judge whether the observed group score sum is unusual.

Deterministic Permutation Distribution

Python

Python permutation distribution of the Ansari–Bradley A statistic.
Python permutation distribution of the Ansari–Bradley A statistic.
Exact evidence

The observed A = 40,094.5 lies left of E(A) = 40,850.3, but remains well inside the main permutation mass. The two-sided permutation p-value is 0.510849.

Statistical meaning

The observed direction is compatible with somewhat greater no-group dispersion, but the distance from the null centre is not exceptional.

Do not overread it: A 10,000-permutation p-value has Monte Carlo granularity and should be reported as a robustness estimate, not an exact enumeration.
Next analytical step: Reconcile it with the tie-adjusted asymptotic p-value and the R output.
AdvertisementGoogle AdSense placement reserved after the Python evidence

R Verification Gallery: Paired Charts and Independent Checks

The R section is arranged in paired horizontal rows on desktop and collapses cleanly on mobile. It verifies reproducibility without repeating the Python prose word for word.

R evidence pair 1

R colour V4 report for the Ansari-Bradley analysis.
R report snapshot with the verified test values.
R G3 distributions by family educational support.
R distribution comparison for the two support groups.
R verification 1

Output report

The R transcript reproduces the group sizes, descriptives, A statistic and two p-values. It serves as an independent implementation check rather than a second substantive analysis.

Expected agreement: A = 40,094.5 and p ≈ .5183.
R verification 2

Distribution profile

The R histograms should reproduce the same 0–19 frequency structure as Python. Unequal sample sizes make shape and proportions more informative than absolute heights.

Check the larger lower tail for famsup = no.

R evidence pair 2

R boxplot of G3 by family educational support.
R boxplot confirming equal medians and IQRs.
R ECDF comparison of G3 by family educational support.
R empirical cumulative distribution comparison.
R verification 3

Central spread

The boxplot confirms median 12 and IQR 4 in both groups, with the descriptive difference concentrated outside the boxes.

Quartile agreement supports the common-location gate.
R verification 4

Cumulative pattern

The R ECDF reproduces the close cumulative trajectories and the low-grade separation visible in Python.

The curves do not show a large global distribution split.

R evidence pair 3

R colour chart comparing standard deviation and IQR.
R descriptive dispersion comparison.
R Ansari-Bradley symmetric score curve.
R symmetric-score assignment by observed G3.
R verification 5

SD versus IQR

The R panel highlights the same contrast: unequal SDs but identical IQRs. This prevents a simplistic claim that every aspect of spread differs.

SD ratio ≈ 1.2139; IQR ratio = 1.
R verification 6

Score mechanics

The central grades receive high scores and pooled extremes receive low scores. This is the mechanism that turns the raw distributions into A.

The score pattern should peak near the pooled centre.

R evidence pair 4

R deterministic permutation distribution of A.
R permutation reference distribution.
R colour V4 Ansari-Bradley summary chart.
R summary of descriptives and test result.
R verification 7

Permutation evidence

The R permutation plot places the observed statistic within the central null mass, consistent with p = .510849.

The decision must match the Python permutation result.
R verification 8

Final result summary

The final R summary consolidates the evidence and should not introduce a competing result or alternative grouping variable.

No Brunner–Munzel or gender-based assets belong here.

Python, R, SPSS, SAS and Excel Workflows

Python

  • Use scipy.stats.ansari with a two-sided alternative.
  • For this tied large sample, request the asymptotic method or a configured permutation method.
  • Recreate frequency, ECDF, score and permutation visuals.

R

  • Use ansari.test(G3 ~ famsup, data = dat, exact = FALSE).
  • Request a scale-ratio estimate only when its assumptions and tie method are clearly explained.
  • Keep the group order fixed so the direction remains interpretable.

SPSS

  • Use native SPSS output for descriptives, histograms and boxplots.
  • The supplied corrected report includes the separately validated Ansari–Bradley calculation.
  • Do not imply that an ordinary EXAMINE command alone produces A.

SAS

  • Use PROC NPAR1WAY AB for Ansari–Bradley scores.
  • The EXACT AB / MC workflow can estimate an exact-reference p-value by Monte Carlo for large problems.
  • Preserve the two-level class variable and numeric response.

Excel

  • Pool and rank G3 with RANK.AVG.
  • Convert each pooled rank to a symmetric score.
  • Sum sample-X contributions and calculate expectation, tie-adjusted variance, z and p.

Cross-Software Rule

  • Group order, tie handling and p-value method must be documented.
  • Two-sided p-values should agree to displayed precision.
  • A reversed z sign is acceptable only when the direction convention is stated.

Expandable Reproducible Code

Python: SciPy asymptotic and permutation workflows
from scipy import stats
from scipy.stats import PermutationMethod

x = df.loc[df["famsup"].eq("no"), "G3"].dropna().to_numpy()
y = df.loc[df["famsup"].eq("yes"), "G3"].dropna().to_numpy()

asym = stats.ansari(x, y, alternative="two-sided", method="asymptotic")
perm = stats.ansari(
    x, y,
    alternative="two-sided",
    method=PermutationMethod(n_resamples=10_000, random_state=12345)
)

print(asym.statistic, asym.pvalue)
print(perm.statistic, perm.pvalue)
R: ansari.test and descriptive audit
dat$famsup <- factor(dat$famsup, levels = c("no", "yes"))
fit <- ansari.test(
  G3 ~ famsup,
  data = dat,
  alternative = "two.sided",
  exact = FALSE
)
print(fit)

# Descriptive audit
aggregate(G3 ~ famsup, dat, function(x)
  c(n = length(x), mean = mean(x), median = median(x),
    sd = sd(x), variance = var(x), IQR = IQR(x)))
SPSS: native descriptives and corrected integrated result
* Native descriptive and visual audit.
EXAMINE VARIABLES=G3 BY famsup
 /PLOT=BOXPLOT HISTOGRAM
 /COMPARE=GROUP
 /STATISTICS=DESCRIPTIVES
 /CINTERVAL=95
 /MISSING=LISTWISE.

* The supplied corrected report then integrates the
* separately validated Ansari-Bradley A, tie-adjusted
* variance, z, asymptotic p, and permutation p.
SAS: PROC NPAR1WAY with Ansari–Bradley scores
proc npar1way data=student_data ab;
  class famsup;
  var G3;
  exact ab / mc n=10000 seed=12345;
run;
Excel: key workbook formulas
Pooled rank:
=RANK.AVG(C4,$C$4:$C$652,1)

Symmetric score:
=MIN(D4,COUNT($C$4:$C$652)-D4+1)

Sample-X contribution:
=IF(B4=Results!$B$7,E4,0)

Observed A:
=SUM(AB_Calculation!$F$4:$F$652)

Expected A for odd N:
=nX*(N+1)^2/(4*N)

Two-sided p:
=2*(1-NORM.S.DIST(ABS(z),TRUE))

Cross-Software Reconciliation

OutputPythonRSPSS corrected reportExcel V4Status
Sample sizes251 / 398251 / 398251 / 398251 / 398Match
Medians12 / 1212 / 1212 / 1212 / 12Match
Standard deviations3.6022 / 2.96743.6022 / 2.96743.602 / 2.9673.6022 / 2.9674Match
A statistic40,094.540,094.540,094.540,094.5Match
Z statistic0.646031 or sign-reversed by convention0.646031 or sign-reversed by convention0.6460310.646031Magnitude matches
Asymptotic p0.5182590.5182590.5182590.518259Match
Permutation p0.5108490.5108490.5108490.510849Match
Reconciliation verdict: the reported results are numerically consistent. The only permissible presentation difference is the sign of z when software standardizes A − E(A) rather than E(A) − A; the two-sided p-value remains unchanged.

Ansari–Bradley Test Compared with Related Methods

MethodPrimary targetGroupsDistribution requirementImportant distinction
Ansari–BradleyScale parameter2Common location; rank-score modelCurrent method; symmetric extreme-to-centre scores.
Mood scale testScale parameter2Rank-basedAlternative two-sample scale score system.
Siegel–TukeyScale parameter2Rank-based; common locationAlternating extreme-rank scoring.
Fligner–KilleenHomogeneity of spread2 or moreRobust and rank-basedNatural extension for multiple groups.
Levene testVariance homogeneity2 or moreReasonably robust, depending on centre choiceUses absolute deviations from a group centre.
Brown–ForsytheVariance homogeneity2 or moreRobust median-centred version of LeveneUseful when skewness and outliers are present.
Bartlett testVariance homogeneity2 or moreSensitive to non-normalityPowerful under normality but fragile otherwise.
Two-sample F testVariance ratio2Normal populationsDirect parametric variance-ratio test.
Mann–Whitney ULocation / stochastic ordering2Independent groupsNot a substitute for a scale question.
Brunner–MunzelRelative stochastic effect2Allows unequal variancesTargets ordering, not scale equality.
Lepage testJoint location and scale2Rank-based combined frameworkUseful when both components are scientifically relevant.

APA-Style Reporting and Research Write-Up

Concise Result

An Ansari–Bradley test found no statistically significant difference in G3 scale between students without family educational support (n = 251) and students with support (n = 398), A = 40,094.50, z = 0.65, p = .518.

Full Result with Verification

An Ansari–Bradley test was used to compare the dispersion of G3 scores between students without family educational support (n = 251) and those with support (n = 398). Both groups had a median of 12 and an interquartile range of 4. The scale difference was not statistically significant, A = 40,094.50, z = 0.65, p = .518. A deterministic 10,000-permutation analysis produced a consistent result, p = .511. Although the no-support group had a larger sample standard deviation, 3.60 versus 2.97, the analysis did not provide sufficient evidence of different population scale.

Reusable Reporting Template

Method

An Ansari–Bradley test compared the scale of outcome between group X and group Y.

Validity

The group medians were median X and median Y, supporting / questioning the common-location condition.

Result

The result was A = value, z = value, p = value.

Verification

A permutation or exact-reference analysis gave p = value.

Conclusion

The analysis did / did not provide evidence of a population-scale difference.

Reporting rule: include group sizes, medians, the A statistic, p-value method and a clear scale-focused conclusion. A variance ratio can be added descriptively, but it must not replace the rank-test result.

Common Ansari–Bradley Test Mistakes

Calling it a median test

The procedure targets scale under a common-location model.

Ignoring unequal medians

Location differences can contaminate the scale interpretation.

Claiming equal variance

A nonsignificant test does not prove equality.

Using uncorrected exact inference with ties

Large tied samples require an appropriate asymptotic or permutation method.

Interpreting SD bars as a hypothesis test

Descriptive ratios do not supply a p-value.

Confusing scale and variance ratios

A scale ratio s corresponds to a variance ratio s² when variances exist.

Mixing unrelated charts

Brunner–Munzel gender charts do not belong in this family-support scale analysis.

Changing group order silently

The A statistic and directional interpretation depend on the focal sample.

Using it for three groups

Select a k-sample scale procedure instead.

Practice Questions with Answers

Question 1: What parameter does the Ansari–Bradley test target?

Answer: The relative scale or dispersion of two independent populations under a common-location model.

Question 2: Why is the equal-median check important?

Answer: A material location shift can change which observations appear central or extreme, weakening a pure scale interpretation.

Question 3: Both groups have IQR = 4, but their SDs differ. Is this contradictory?

Answer: No. IQR describes the middle 50%, whereas SD is sensitive to tail observations such as zero grades.

Question 4: What does A = 40,094.5 represent?

Answer: It is the sum of the symmetric pooled scores for the focal no-support group.

Question 5: What is the null expectation of A in this analysis?

Answer: 40,850.3467.

Question 6: Why can different software report z with opposite signs?

Answer: One implementation may standardize A − E(A), while another uses E(A) − A. The two-sided p-value is unchanged.

Question 7: Why is the permutation p-value useful here?

Answer: It verifies the decision without relying only on the large-sample normal reference in a heavily tied dataset.

Question 8: Can p = .518 prove equal dispersion?

Answer: No. It indicates insufficient evidence to reject equal scale; it is not an equivalence result.

Question 9: Which group is descriptively more variable?

Answer: The no-support group, with SD 3.6022 versus 2.9674 and variance ratio 1.4736.

Question 10: Where is the descriptive difference concentrated?

Answer: Mainly in the lower tail, especially the higher proportion of G3 = 0 in the no-support group.

Question 11: Which test is a better starting point for three groups?

Answer: Fligner–Killeen or another justified k-sample spread test.

Question 12: Should the Z Test for Proportions be linked as a primary related method?

Answer: No. It addresses binary proportions, not a two-sample scale parameter.

Verified Ansari–Bradley Downloads

Asset control: duplicate URLs are omitted. Brunner–Munzel report and gender-based charts are intentionally excluded because they analyse a different test, grouping variable and hypothesis.

Frequently Asked Questions

What is the Ansari–Bradley test?

It is a nonparametric two-sample test for a difference in scale parameters. It uses symmetric scores assigned to pooled ranks from the extremes toward the centre.

Is the Ansari–Bradley test a test of equal medians?

No. Equal or aligned location is a condition supporting the scale interpretation; the statistic itself targets dispersion.

What does a smaller A statistic mean?

For the focal sample, a smaller-than-expected A generally indicates more observations at the pooled extremes and therefore a direction consistent with larger scale.

Why are ties important in this dataset?

G3 is an integer grade, so many students share the same value. Midranks and a tie-adjusted variance are required, and a permutation check strengthens the inference.

What is the result for family educational support?

A = 40,094.5, z = 0.6460, asymptotic p = .5183 and permutation p = .5108. The equal-scale null is not rejected.

Why is the no-support standard deviation larger?

That group contains a higher proportion of very low scores, especially zeros, which increase squared deviations from the mean.

Can I conclude the populations have the same variance?

No. A nonsignificant result means the data do not provide sufficient evidence of a scale difference. Formal equivalence requires a separate design and margin.

What is the difference between a scale ratio and a variance ratio?

When variances exist, a scale ratio s corresponds to a variance ratio s squared. They should not be reported as though they are the same quantity.

Can the test be used with more than two groups?

The classic Ansari–Bradley test is a two-sample procedure. A k-sample method such as Fligner–Killeen is more appropriate for multiple groups.

What should be reported?

Report group sizes, medians or location audit, A, the inference method, p-value, decision and a careful scale-focused interpretation.

Conclusion

The Ansari–Bradley test provides a focused nonparametric comparison of scale for two independent populations. In the worked G3 analysis, the data satisfy the most important descriptive location check: both family-support groups have a median of 12 and an IQR of 4. The group without support nevertheless has a larger sample SD and variance, driven primarily by a heavier lower tail.

The formal rank-score evidence does not confirm a population-scale difference. The observed A statistic of 40,094.5 is only 0.646 standard errors from its equal-scale expectation. The tie-adjusted asymptotic p-value of .5183 and deterministic permutation p-value of .5108 agree closely. The correct conclusion is therefore that no statistically significant difference in G3 scale was detected—not that the two populations have been proven identical.

Final reporting sentence: “The G3 distributions had similar central location and no statistically significant scale difference, A = 40,094.50, z = 0.65, p = .518; a 10,000-permutation analysis confirmed the decision, p = .511.”

Back to top

Need help applying this to your own data?

Salar Cafe can help interpret output, clean datasets, review assumptions, build dashboards and explain statistical results ethically.

Need help interpreting your data analysis results?

Contact Salar Cafe
Engr. Muhammad Yar Saqib author profile photo

Engr. Muhammad Yar Saqib

WhatsApp Get Data Analysis Help