hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_univar_robust_2var_ci (g07eb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

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

Syntax

[theta, thetal, thetau, estcl, ulower, uupper, ifail] = g07eb(method, x, y, clevel, 'n', n, 'm', m)
[theta, thetal, thetau, estcl, ulower, uupper, ifail] = nag_univar_robust_2var_ci(method, x, y, clevel, 'n', n, 'm', m)

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,,xnT, have distribution Fx and the random sample, y=y1,y2,,ymT, have distribution Fx-θ.
nag_univar_robust_2var_ci (g07eb) 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.

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

Parameters

Compulsory Input Parameters

1:     method – string (length ≥ 1)
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:     xn – double array
The observations of the first sample, xi, for i=1,2,,n.
3:     ym – double array
The observations of the second sample, yj, for j=1,2,,m.
4:     clevel – double scalar
The confidence interval required, 1-α; e.g., for a 95% confidence interval set clevel=0.95.
Constraint: 0.0<clevel<1.0.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array x.
n, the size of the first sample.
Constraint: n1.
2:     m int64int32nag_int scalar
Default: the dimension of the array y.
m, the size of the second sample.
Constraint: m1.

Output Parameters

1:     theta – double scalar
The estimate of the difference in the location of the two populations, θ^.
2:     thetal – double scalar
The estimate of the lower limit of the confidence interval, θl.
3:     thetau – double scalar
The estimate of the upper limit of the confidence interval, θu.
4:     estcl – double scalar
An estimate of the actual percentage confidence of the interval found, as a proportion between 0.0,1.0.
5:     ulower – double scalar
The value of the Mann–Whitney U statistic corresponding to the lower confidence limit, Ul.
6:     uupper – double scalar
The value of the Mann–Whitney U statistic corresponding to the upper confidence limit, Uu.
7:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=1
On entry,method'E' or 'A',
orn<1,
orm<1,
orclevel0.0,
orclevel1.0.
W  ifail=2
Each sample consists of identical values. All estimates are set to the common difference between the samples.
W  ifail=3
For at least one of the estimates θ^, θl and θu, the underlying iterative algorithm (when method='A') failed to converge. 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.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

nag_univar_robust_2var_ci (g07eb) 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.

Further Comments

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

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.
function g07eb_example


fprintf('g07eb example results\n\n');

x = [-0.582;  0.157; -0.523; -0.769;  2.338;  1.664; -0.981;  1.549;
      1.131; -0.460; -0.484;  1.932;  0.306; -0.602; -0.979;  0.132;
      0.256; -0.094;  1.065; -1.084; -0.969; -0.524;  0.239;  1.512;
     -0.782; -0.252; -1.163;  1.376;  1.674;  0.831;  1.478; -1.486;
     -0.808; -0.429; -2.002;  0.482; -1.584; -0.105;  0.429;  0.568;
      0.944;  2.558; -1.801;  0.242;  0.763; -0.461; -1.497; -1.353;
      0.301;  1.941];
y = [ 1.995;  0.007;  0.997;  1.089;  2.004;  0.171;  0.294;  2.448;
      0.214;  0.773;  2.960;  0.025;  0.638;  0.937; -0.568; -0.711;
      0.931;  2.601;  1.121; -0.251; -0.050;  1.341;  2.282;  0.745;
      1.633;  0.944;  2.370;  0.293;  0.895;  0.938;  0.199;  0.812;
      1.253;  0.590;  1.522; -0.685;  1.259;  0.571;  1.579;  0.568;
      0.381;  0.829;  0.277;  0.656;  2.497;  1.779;  1.922; -0.174;
      2.132;  2.793;  0.102;  1.569;  1.267;  0.490;  0.077;  1.366;
      0.056;  0.605;  0.628;  1.650;  0.104;  2.194;  2.869; -0.171;
     -0.598;  2.134;  0.917;  0.630;  0.209;  1.328;  0.368;  0.756;
      2.645;  1.161;  0.347;  0.920;  1.256; -0.052;  1.474;  0.510;
      1.386;  3.550;  1.392; -0.358;  1.938;  1.727; -0.372;  0.911;
      0.499;  0.066;  1.467;  1.898;  1.145;  0.501;  2.230;  0.212;
      0.536;  1.690;  1.086;  0.494];

method = 'Approx';
clevel = 0.95;

[theta, thetal, thetau, estcl, ulower, uupper, ifail] = ...
  g07eb(method, x, y, clevel);

fprintf(' Location estimator     Confidence Interval\n\n');
fprintf('%13.4f%12s%7.4f,%7.4f )\n\n', theta, '(', thetal, thetau);
fprintf(' Corresponding Mann-Whitney statistics\n\n');
fprintf('  Lower : %8.2f\n', ulower);
fprintf('  Upper : %8.2f\n', uupper);



g07eb example results

 Location estimator     Confidence Interval

       0.9505           ( 0.5650, 1.3050 )

 Corresponding Mann-Whitney statistics

  Lower :  2007.00
  Upper :  2993.00

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015