NAG FL Interface
g07ebf (robust_​2var_​ci)

1 Purpose

g07ebf calculates a rank based (nonparametric) estimate and confidence interval for the difference in location between two independent populations.

2 Specification

Fortran Interface
Subroutine g07ebf ( method, n, x, m, y, clevel, theta, thetal, thetau, estcl, ulower, uupper, wrk, iwrk, ifail)
Integer, Intent (In) :: n, m
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: iwrk(3*n)
Real (Kind=nag_wp), Intent (In) :: x(n), y(m), clevel
Real (Kind=nag_wp), Intent (Out) :: theta, thetal, thetau, estcl, ulower, uupper, wrk(3*(m+n))
Character (1), Intent (In) :: method
C Header Interface
#include <nag.h>
void  g07ebf_ (const char *method, const Integer *n, const double x[], const Integer *m, const double y[], const double *clevel, double *theta, double *thetal, double *thetau, double *estcl, double *ulower, double *uupper, double wrk[], Integer iwrk[], Integer *ifail, const Charlen length_method)
The routine may be called by the names g07ebf or nagf_univar_robust_2var_ci.

3 Description

Consider two random samples from two populations which have the same continuous distribution except for a shift in the location. Let the random sample, x= x1,x2,,xn T, have distribution Fx and the random sample, y= y1,y2,,ym T, have distribution Fx-θ.
g07ebf finds a point estimate, θ^, of the difference in location θ together with an associated confidence interval. The estimates are based on the ordered differences yj-xi. The estimate θ^ is defined by
θ^ = median yj-xi ,   i=1,2,,n ; j=1,2,,m .  
Let dk, for k=1,2,,nm, denote the nm (ascendingly) ordered differences yj-xi, for i=1,2,,n and j=1,2,,m. Then
This estimator arises from inverting the two sample Mann–Whitney rank test statistic, Uθ0, for testing the hypothesis that θ=θ0. Thus Uθ0 is the value of the Mann–Whitney U statistic for the two independent samples xi + θ0 , for ​ i=1,2,,n and yj , for ​ j=1,2,,m . Effectively Uθ0 is a monotonically increasing step function of θ0 with
mean ​U=μ= nm2, varU=σ2 nmn+m+112.  
The estimate θ^ is the solution to the equation Uθ^=μ; two methods are available for solving this equation. These methods avoid the computation of all the ordered differences dk; this is because for large n and m both the storage requirements and the computation time would be high.
The first is an exact method based on a set partitioning procedure on the set of all differences yj-xi, for i=1,2,,n and j=1,2,,m. This is adapted from the algorithm proposed by Monahan (1984) for the computation of the Hodges–Lehmann estimator for a single population.
The second is an iterative algorithm, based on the Illinois method which is a modification of the regula falsi method, see McKean and Ryan (1977). This algorithm has proved suitable for the function Uθ0 which is asymptotically linear as a function of θ0.
The confidence interval limits are also based on the inversion of the Mann–Whitney test statistic.
Given a desired percentage for the confidence interval, 1-α, expressed as a proportion between 0.0 and 1.0 initial estimates of the upper and lower confidence limits for the Mann–Whitney U statistic are found;
Ul=μ-0.5+σ×Φ-1α/2 Uu=μ+0.5+σ×Φ-11-α/2  
where Φ-1 is the inverse cumulative Normal distribution function.
Ul and Uu are rounded to the nearest integer values. These estimates are refined using an exact method, without taking ties into account, if n+m40 and maxn,m30 and a Normal approximation otherwise, to find Ul and Uu satisfying
PUUlα/2 PUUl+1>α/2  
and
PUUuα /2 PUUu- 1>α /2.  
The function Uθ0 is a monotonically increasing step function. It is the number of times a score in the second sample, yj, precedes a score in the first sample, xi+θ, where we only count a half if a score in the second sample actually equals a score in the first.
Let Ul=k; then θl=dk+1. This is the largest value θl such that Uθl=Ul.
Let Uu=nm-k; then θu=dnm-k. This is the smallest value θu such that Uθu=Uu.
As in the case of θ^, these equations may be solved using either the exact or iterative methods to find the values θl and θu.
Then θl,θu is the confidence interval for θ. The confidence interval is thus defined by those values of θ0 such that the null hypothesis, θ=θ0, is not rejected by the Mann–Whitney two sample rank test at the 100×α% level.

4 References

Lehmann E L (1975) Nonparametrics: Statistical Methods Based on Ranks Holden–Day
McKean J W and Ryan T A (1977) Algorithm 516: An algorithm for obtaining confidence intervals and point estimates based on ranks in the two-sample location problem ACM Trans. Math. Software 10 183–185
Monahan J F (1984) Algorithm 616: Fast computation of the Hodges–Lehman location estimator ACM Trans. Math. Software 10 265–270

5 Arguments

1: method Character(1) Input
On entry: specifies the method to be used.
method='E'
The exact algorithm is used.
method='A'
The iterative algorithm is used.
Constraint: method='E' or 'A'.
2: n Integer Input
On entry: n, the size of the first sample.
Constraint: n1.
3: xn Real (Kind=nag_wp) array Input
On entry: the observations of the first sample, xi, for i=1,2,,n.
4: m Integer Input
On entry: m, the size of the second sample.
Constraint: m1.
5: ym Real (Kind=nag_wp) array Input
On entry: the observations of the second sample, yj, for j=1,2,,m.
6: clevel Real (Kind=nag_wp) Input
On entry: the confidence interval required, 1-α; e.g., for a 95% confidence interval set clevel=0.95.
Constraint: 0.0<clevel<1.0.
7: theta Real (Kind=nag_wp) Output
On exit: the estimate of the difference in the location of the two populations, θ^.
8: thetal Real (Kind=nag_wp) Output
On exit: the estimate of the lower limit of the confidence interval, θl.
9: thetau Real (Kind=nag_wp) Output
On exit: the estimate of the upper limit of the confidence interval, θu.
10: estcl Real (Kind=nag_wp) Output
On exit: an estimate of the actual percentage confidence of the interval found, as a proportion between 0.0,1.0.
11: ulower Real (Kind=nag_wp) Output
On exit: the value of the Mann–Whitney U statistic corresponding to the lower confidence limit, Ul.
12: uupper Real (Kind=nag_wp) Output
On exit: the value of the Mann–Whitney U statistic corresponding to the upper confidence limit, Uu.
13: wrk3×m+n Real (Kind=nag_wp) array Workspace
14: iwrk3×n Integer array Workspace
15: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, clevel=value.
Constraint: 0.0<clevel<1.0.
On entry, m=value.
Constraint: m1.
On entry, method=value.
Constraint: method='E' or 'A'.
On entry, n=value.
Constraint: n1.
ifail=2
Not enough information to compute an interval estimate since each sample has identical values. The common difference is returned in theta, thetal and thetau.
ifail=3
The iterative procedure used to estimate, θl, the lower confidence limit has not converged. This is an unlikely exit but the estimate should still be a reasonable approximation.
The iterative procedure used to estimate, θu, the upper confidence limit has not converged. This is an unlikely exit but the estimate should still be a reasonable approximation.
The iterative procedure used to estimate θ has not converged. This is an unlikely exit but the estimate should still be a reasonable approximation.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

g07ebf should return results accurate to five significant figures in the width of the confidence interval, that is the error for any one of the three estimates should be less than 0.00001×thetau-thetal.

8 Parallelism and Performance

g07ebf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g07ebf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The time taken increases with the sample sizes n and m.

10 Example

The following program calculates a 95% confidence interval for the difference in location between the two populations from which the two samples of sizes 50 and 100 are drawn respectively.

10.1 Program Text

Program Text (g07ebfe.f90)

10.2 Program Data

Program Data (g07ebfe.d)

10.3 Program Results

Program Results (g07ebfe.r)