NAG Library Function Document

nag_rank_ci_1var (g07eac)


    1  Purpose
    7  Accuracy


nag_rank_ci_1var (g07eac) computes a rank based (nonparametric) estimate and confidence interval for the location argument of a single population.


#include <nag.h>
#include <nagg07.h>
void  nag_rank_ci_1var (Nag_RCIMethod method, Integer n, const double x[], double clevel, double *theta, double *thetal, double *thetau, double *estcl, double *wlower, double *wupper, NagError *fail)


Consider a vector of independent observations, x=x1,x2,,xnT with unknown common symmetric density fxi-θ. nag_rank_ci_1var (g07eac) computes the Hodges–Lehmann location estimator (see Lehmann (1975)) of the centre of symmetry θ, together with an associated confidence interval. The Hodges–Lehmann estimate is defined as
θ^=median xi+xj2,1ijn .  
Let m=nn+1/2 and let ak, for k=1,2,,m denote the m ordered averages xi+xj/2 for 1ijn. Then
This estimator arises from inverting the one-sample Wilcoxon signed-rank test statistic, Wx-θ0, for testing the hypothesis that θ=θ0. Effectively Wx-θ0 is a monotonically decreasing step function of θ0 with
mean ​W=μ= nn+14, varW=σ2= nn+12n+124.  
The estimate θ^ is the solution to the equation Wx-θ^=μ; two methods are available for solving this equation. These methods avoid the computation of all the ordered averages ak; this is because for large n both the storage requirements and the computation time would be excessive.
The first is an exact method based on a set partitioning procedure on the set of all ordered averages xi+xj/2 for ij. This is based on the algorithm proposed by Monahan (1984).
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 Wx-θ0 which is asymptotically linear as a function of θ0.
The confidence interval limits are also based on the inversion of the Wilcoxon test statistic.
Given a desired percentage for the confidence interval, 1-α, expressed as a proportion between 0 and 1, initial estimates for the lower and upper confidence limits of the Wilcoxon statistic are found from
Wu=μ+ 0.5+σ Φ-11-α /2,  
where Φ-1 is the inverse cumulative Normal distribution function.
Wl and Wu are rounded to the nearest integer values. These estimates are then refined using an exact method if n80, and a Normal approximation otherwise, to find Wl and Wu satisfying
PWWlα/2 PWWl+1>α/2  
PWWuα /2 PWWu- 1>α /2.  
Let Wu=m-k; then θl=ak+1. This is the largest value θl such that Wx-θl=Wu.
Let Wl=k; then θu=am-k. This is the smallest value θu such that Wx-θu=Wl.
As in the case of θ^, these equations may be solved using either the exact or the 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 Wilcoxon signed-rank test at the 100×α% level.


Lehmann E L (1975) Nonparametrics: Statistical Methods Based on Ranks Holden–Day
Marazzi A (1987) Subroutines for robust estimation of location and scale in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 1 Institut Universitaire de Médecine Sociale et Préventive, Lausanne
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


1:     method Nag_RCIMethodInput
On entry: specifies the method to be used.
The exact algorithm is used.
The iterative algorithm is used.
Constraint: method=Nag_RCI_Exact or Nag_RCI_Approx.
2:     n IntegerInput
On entry: n, the sample size.
Constraint: n2.
3:     x[n] const doubleInput
On entry: the sample observations, xi, for i=1,2,,n.
4:     clevel doubleInput
On entry: the confidence interval desired.
For example, for a 95% confidence interval set clevel=0.95.
Constraint: 0.0<clevel<1.0.
5:     theta double *Output
On exit: the estimate of the location, θ^.
6:     thetal double *Output
On exit: the estimate of the lower limit of the confidence interval, θl.
7:     thetau double *Output
On exit: the estimate of the upper limit of the confidence interval, θu.
8:     estcl double *Output
On exit: an estimate of the actual percentage confidence of the interval found, as a proportion between 0.0,1.0.
9:     wlower double *Output
On exit: the upper value of the Wilcoxon test statistic, Wu, corresponding to the lower limit of the confidence interval.
10:   wupper double *Output
On exit: the lower value of the Wilcoxon test statistic, Wl, corresponding to the upper limit of the confidence interval.
11:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
Warning. The iterative procedure to find an estimate of the lower confidence point had not converged in 100 iterations.
Warning. The iterative procedure to find an estimate of Theta had not converged in 100 iterations.
Warning. The iterative procedure to find an estimate of the upper confidence point had not converged in 100 iterations.
On entry, n=value.
Constraint: n2.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
On entry, clevel is out of range: clevel=value.
Not enough information to compute an interval estimate since the whole sample is identical. The common value is returned in theta, thetal and thetau.


nag_rank_ci_1var (g07eac) should produce 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.

Parallelism and Performance

nag_rank_ci_1var (g07eac) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

The time taken increases with the sample size n.


The following program calculates a 95% confidence interval for θ, a measure of symmetry of the sample of 50 observations.

Program Text

Program Text (g07eace.c)

Program Data

Program Data (g07eace.d)

Program Results

Program Results (g07eace.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017