RangeRatioDistribution
Package: Libraries.Compute.Statistics.Distributions · Inherits from: Libraries.Language.Object, Libraries.Compute.Statistics.Distributions.NumberDistribution
The RangeRatioDistribution class is the distribution of the studentized range: the range of k independent standard normal values divided by an independent estimate of their standard deviation on f degrees of freedom. Tukey's test compares each pair of k group means with it. It follows Copenhaver and Holland (1988), "Computation of the distribution of the maximum studentized range statistic with application to multiple significance testing of simple effects", Journal of Statistical Computation and Simulation 30(1), 1-15. Their Q is the largest of r independent studentized ranges sharing one standard deviation estimate; r = 1 (the default) is Tukey's case, and Setup(means, df, groups) sets r: - P(Q <= q) is the integral over u of H(q sqrt(u))^r times the density of u = chi-squared(f) / f (their equation 1.3); - H, the distribution of the range of k standard normals, is Hartley's (1942) [2F(w/2) - 1]^k plus 2k / sqrt(2 pi) times the integral from w/2 of e^(-v^2/2) [F(v) - F(v - w)]^(k-1) (2.1-2.2), split at w/2, the points [(m - i)(w/2) + 8i] / m and 8 (m = 3 pieces for w <= 3, 2 above), each by 12-point Gauss-Legendre (2.3); - the integral over u is split into intervals of length L (1 up to 100 degrees of freedom, 1/2 to 800, 1/4 to 5000, 1/8 to 25000), each by 16-point Gauss-Legendre (2.6); above 25000 degrees of freedom, and for infinite degrees of freedom, H(q)^r. Like R's ptukey, which does the same, this is off by up to about 1.3e-5 just above 25000 degrees of freedom (0.9644430 for 0.9644300 at 30000, with 3.5 and 3 means), less as they grow. Where the paper leaves a choice, or where double precision allows more accuracy than its 6 decimal places, this class makes these (2026-11-28): - the intervals over u are half the paper's lengths (1/2, 1/4, 1/8 and 1/16): at the top of each of the paper's degrees of freedom ranges its lengths leave errors up to about 1e-6 (8.9e-7 at 100, 7e-9 at 800 and 5000, 5e-7 at 25000), and half lengths about 1e-12, for twice the work; - the sum over intervals stops once an interval, past the largest, adds less than STOPPING_FRACTION (1e-12) of the total; the paper says only that two to four intervals typically contribute; - the first interval, [0, L], is taken with u = L s^2, which removes the density's u^(f/2 - 1) singularity at 0 when f < 2 (the paper's table starts at 2 degrees of freedom), and in four pieces of s ([0, 1/8], [1/8, 1/4], [1/4, 1/2], [1/2, 1]), since for small degrees of freedom and large q, H(q sqrt(u)) rises from 0 to 1 close to u = 0: in one piece, P(Q <= 60) with 10 means and 2 df was 7.5e-5 low, in four about 1e-12; the other intervals are the paper's; - for w of 8 or more, H uses the 2-piece split too (the paper defines it for w < 8); - the inverse uses the secant method, as the paper does, from the initial estimate in FastRangeRatioDistribution (after Lund and Lund's AS 190), but stops when two iterates differ by less than INVERSE_TOLERANCE (1e-10), where the paper used 1e-4. Checked against R 4.6.2's ptukey and qtukey and SciPy 1.18.1's studentized_range (quorum-test: Science/Distributions/ RangeRatioDistributionTest): the cumulative values agree to about 1e-11, the inverse to about 1e-9. FastRangeRatioDistribution (Algorithm AS 190) is about 1e-4 low, but 25 to 100 times faster.
Example Code
use Libraries.Compute.Statistics.Distributions.RangeRatioDistribution
RangeRatioDistribution distribution
distribution:Setup(3, 20)
output distribution:CumulativeDistribution(3.5)
output distribution:InverseCumulativeDistribution(0.95)
Actions
CumulativeDistribution(number q)
This action returns P(Q <= q), the probability that the studentized range is at most q.
Parameters
qnumber: The studentized range.
Returns
number: The probability.
GetDegreesOfFreedom()
This action returns the degrees of freedom (f).
Returns
number
GetGroups()
This action returns the number of groups (r); 1 is the studentized range itself.
Returns
number
GetLowerBound()
The lower bound of the studentized range: 0.
Returns
number
GetMean()
The mean, which has no simple form: not a number, as in FastRangeRatioDistribution.
Returns
number
GetNumberOfMeans()
This action returns the number of means (k).
Returns
number
GetSolverAbsoluteAccuracy()
The inverse's tolerance: two iterates closer than this end the search.
Returns
number
GetUpperBound()
The upper bound of the studentized range: infinity.
Returns
number
GetVariance()
The variance, which has no simple form: not a number, as in FastRangeRatioDistribution.
Returns
number
InverseCumulativeDistribution(number p)
This action returns the studentized range q with P(Q <= q) = p, by the secant method.
Parameters
pnumber: The probability.
Returns
number: The studentized range.
IsSupportConnected()
The variance, which has no simple form: not a number, as in FastRangeRatioDistribution.
Returns
boolean
RangeDistribution(number w)
This action returns H(w), the probability that the range of k independent standard normal values is at most w (Hartley, 1942, as Copenhaver and Holland write it).
Parameters
wnumber: The range.
Returns
number: The probability.
Setup(number means, number df, number groupCount)
This action sets the parameters of the distribution of the largest of several studentized ranges, as in Copenhaver and Holland's tables for simple effects.
Parameters
meansnumber: The number of means in each group (their c), 2 or more.dfnumber: The degrees of freedom of the shared standard deviation's estimate (f), 1 or more; positive infinity for a known standard deviation.groupCountnumber: The number of groups (r), 1 or more; 1 is the studentized range itself.
Setup(number means, number df)
This action sets the distribution's parameters.
Parameters
meansnumber: The number of means compared (k), 2 or more.dfnumber: The degrees of freedom of the standard deviation's estimate (f), 1 or more.