NAG FL Interface
g07eaf (robust_​1var_​ci)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g07eaf computes a rank based (nonparametric) estimate and confidence interval for the location parameter of a single population.

2 Specification

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

3 Description

Consider a vector of independent observations, x= (x1,x2,,xn) T with unknown common symmetric density f(xi-θ). g07eaf 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=(n(n+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, W(x-θ0), for testing the hypothesis that θ=θ0. Effectively W(x-θ0) is a monotonically decreasing step function of θ0 with
mean ​(W)=μ= n(n+1)4, var(W)=σ2= n(n+1)(2n+1)24.  
The estimate θ^ is the solution to the equation W(x-θ^)=μ; 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 W(x-θ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
Wl=μ-0.5+(σΦ-1(α/2))  
and
Wu=μ+ 0.5+(σΦ-1(1-α/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
P(WWl)α/2 P(WWl+1)>α/2  
and
P(WWu)α /2 P(WWu-1)>α /2.  
Let Wu=m-k; then θl=ak+1. This is the largest value θl such that W(x-θl)=Wu.
Let Wl=k; then θu=am-k. This is the smallest value θu such that W(x-θ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.

4 References

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

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 sample size.
Constraint: n2.
3: x(n) Real (Kind=nag_wp) array Input
On entry: the sample observations, xi, for i=1,2,,n.
4: clevel Real (Kind=nag_wp) Input
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 Real (Kind=nag_wp) Output
On exit: the estimate of the location, θ^.
6: thetal Real (Kind=nag_wp) Output
On exit: the estimate of the lower limit of the confidence interval, θl.
7: thetau Real (Kind=nag_wp) Output
On exit: the estimate of the upper limit of the confidence interval, θu.
8: 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).
9: wlower Real (Kind=nag_wp) Output
On exit: the upper value of the Wilcoxon test statistic, Wu, corresponding to the lower limit of the confidence interval.
10: wupper Real (Kind=nag_wp) Output
On exit: the lower value of the Wilcoxon test statistic, Wl, corresponding to the upper limit of the confidence interval.
11: wrk(4×n) Real (Kind=nag_wp) array Workspace
12: iwrk(3×n) Integer array Workspace
13: 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, method=value.
Constraint: method='E' or 'A'.
On entry, n=value.
Constraint: n2.
ifail=2
Not enough information to compute an interval estimate since the whole sample is identical. The common value 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

g07eaf 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).

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g07eaf 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 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 size n.

10 Example

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

10.1 Program Text

Program Text (g07eafe.f90)

10.2 Program Data

Program Data (g07eafe.d)

10.3 Program Results

Program Results (g07eafe.r)