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_nonpar_rank_regsn (g08ra)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_nonpar_rank_regsn (g08ra) calculates the parameter estimates, score statistics and their variance-covariance matrices for the linear model using a likelihood based on the ranks of the observations.


[prvr, irank, zin, eta, vapvec, parest, ifail] = g08ra(nv, y, x, idist, nmax, tol, 'ns', ns, 'ip', ip)
[prvr, irank, zin, eta, vapvec, parest, ifail] = nag_nonpar_rank_regsn(nv, y, x, idist, nmax, tol, 'ns', ns, 'ip', ip)


Analysis of data can be made by replacing observations by their ranks. The analysis produces inference for regression arguments arising from the following model.
For random variables Y1,Y2,,Yn we assume that, after an arbitrary monotone increasing differentiable transformation, h., the model
hYi= xiT β+εi (1)
holds, where xi is a known vector of explanatory variables and β is a vector of p unknown regression coefficients. The εi are random variables assumed to be independent and identically distributed with a completely known distribution which can be one of the following: Normal, logistic, extreme value or double-exponential. In Pettitt (1982) an estimate for β is proposed as β^=MXTa with estimated variance-covariance matrix M. The statistics a and M depend on the ranks ri of the observations Yi and the density chosen for εi.
The matrix X is the n by p matrix of explanatory variables. It is assumed that X is of rank p and that a column or a linear combination of columns of X is not equal to the column vector of 1 or a multiple of it. This means that a constant term cannot be included in the model (1). The statistics a and M are found as follows. Let εi have pdf fε and let g=-f/f. Let W1,W2,,Wn be order statistics for a random sample of size n with the density f.. Define Zi=gWi, then ai=EZri. To define M we need M-1=XTB-AX, where B is an n by n diagonal matrix with Bii=EgWri and A is a symmetric matrix with Aij=covZri,Zrj. In the case of the Normal distribution, the Z1<<Zn are standard Normal order statistics and EgWi=1, for i=1,2,,n.
The analysis can also deal with ties in the data. Two observations are adjudged to be tied if Yi-Yj<tol, where tol is a user-supplied tolerance level.
Various statistics can be found from the analysis:
(a) The score statistic XTa. This statistic is used to test the hypothesis H0:β=0, see (e).
(b) The estimated variance-covariance matrix XTB-AX of the score statistic in (a).
(c) The estimate β^=MXTa.
(d) The estimated variance-covariance matrix M=XTB-AX -1 of the estimate β^.
(e) The χ2 statistic Q=β^TM-1β^=aTXXTB-AX -1XTa used to test H0:β=0. Under H0, Q has an approximate χ2-distribution with p degrees of freedom.
(f) The standard errors Mii 1/2 of the estimates given in (c).
(g) Approximate z-statistics, i.e., Zi=β^i/seβ^i for testing H0:βi=0. For i=1,2,,n, Zi has an approximate N0,1 distribution.
In many situations, more than one sample of observations will be available. In this case we assume the model
hkYk= XkT β+ek,  k=1,2,,ns,  
where ns is the number of samples. In an obvious manner, Yk and Xk are the vector of observations and the design matrix for the kth sample respectively. Note that the arbitrary transformation hk can be assumed different for each sample since observations are ranked within the sample.
The earlier analysis can be extended to give a combined estimate of β as β^=Dd, where
D-1=k=1ns XkT Bk-AkXk  
d=k= 1ns XkT ak ,  
with ak, Bk and Ak defined as a, B and A above but for the kth sample.
The remaining statistics are calculated as for the one sample case.


Pettitt A N (1982) Inference for the linear model using a likelihood based on ranks J. Roy. Statist. Soc. Ser. B 44 234–243


Compulsory Input Parameters

1:     nvns int64int32nag_int array
The number of observations in the ith sample, for i=1,2,,ns.
Constraint: nvi1, for i=1,2,,ns.
2:     ynsum – double array
nsum, the dimension of the array, must satisfy the constraint nsum= i=1 ns nvi .
The observations in each sample. Specifically, y k=1 i-1 nvk+j  must contain the jth observation in the ith sample.
3:     xldxip – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnsum.
The design matrices for each sample. Specifically, x k=1 i-1 nvk +j l  must contain the value of the lth explanatory variable for the jth observation in the ith sample.
Constraint: x must not contain a column with all elements equal.
4:     idist int64int32nag_int scalar
The error distribution to be used in the analysis.
Extreme value.
Constraint: 1idist4.
5:     nmax int64int32nag_int scalar
The value of the largest sample size.
Constraint: nmax=max1insnvi and nmax>ip.
6:     tol – double scalar
The tolerance for judging whether two observations are tied. Thus, observations Yi and Yj are adjudged to be tied if Yi-Yj<tol.
Constraint: tol>0.0.

Optional Input Parameters

1:     ns int64int32nag_int scalar
Default: the dimension of the array nv.
The number of samples.
Constraint: ns1.
2:     ip int64int32nag_int scalar
Default: the second dimension of the array x.
The number of parameters to be fitted.
Constraint: ip1.

Output Parameters

1:     prvrldprvrip – double array
The variance-covariance matrices of the score statistics and the parameter estimates, the former being stored in the upper triangle and the latter in the lower triangle. Thus for 1ijip, prvrij contains an estimate of the covariance between the ith and jth score statistics. For 1jiip-1, prvri+1j contains an estimate of the covariance between the ith and jth parameter estimates.
2:     iranknmax int64int32nag_int array
For the one sample case, irank contains the ranks of the observations.
3:     zinnmax – double array
For the one sample case, zin contains the expected values of the function g. of the order statistics.
4:     etanmax – double array
For the one sample case, eta contains the expected values of the function g. of the order statistics.
5:     vapvecnmax×nmax+1/2 – double array
For the one sample case, vapvec contains the upper triangle of the variance-covariance matrix of the function g. of the order statistics stored column-wise.
6:     parest4×ip+1 – double array
The statistics calculated by the function.
The first ip components of parest contain the score statistics.
The next ip elements contain the parameter estimates.
parest2×ip+1 contains the value of the χ2 statistic.
The next ip elements of parest contain the standard errors of the parameter estimates.
Finally, the remaining ip elements of parest contain the z-statistics.
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:
On entry,ns<1,
ornmaxmax1ins nvi,
ornvi0, for some i, nvi,
On entry,idist<1,
On entry, all the observations are adjudged to be tied. You are advised to check the value supplied for tol.
The matrix XTB-AX is either ill-conditioned or not positive definite. This error should only occur with extreme rankings of the data.
The matrix X has at least one of its columns with all elements equal.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


The computations are believed to be stable.

Further Comments

The time taken by nag_nonpar_rank_regsn (g08ra) depends on the number of samples, the total number of observations and the number of arguments fitted.
In extreme cases the parameter estimates for certain models can be infinite, although this is unlikely to occur in practice. See Pettitt (1982) for further details.


A program to fit a regression model to a single sample of 20 observations using two explanatory variables. The error distribution will be taken to be logistic.
function g08ra_example

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

% Single sample observations and design matrix
y = [1;  1;  3;  4;  2;  4;  1;  5;  4;  4;
     4;  4;  4;  1;  4;  5;  5;  4;  4;  3];
x = [1, 23;  1, 32;  1, 37;  1, 41;  1, 41;
     1, 48;  1, 48;  1, 55;  1, 55;  0, 56;
     1, 57;  1, 57;  1, 57;  0, 58;  1, 59;
     0, 59;  0, 60;  1, 61;  1, 62;  1, 62];

ns    = size(y,2);
ip    = size(x,2);
idist = int64(2);
nv    = int64(numel(y));
nmax  = nv;
tol   = 1e-05;

fprintf('Number of samples           = %3d\n', ns);
fprintf('Number of parameters fitted = %3d\n', ip);
fprintf('Distribution                = %3d\n', idist);
fprintf('Tolerance for ties          = %8.1e\n', tol);

[parvar, irank, zin, eta, vapvec, parest, ifail] = ...
  g08ra( ...
         nv, y, x, idist, nmax, tol);

% Display results
fprintf('\nScore statistic\n');
fprintf('%9.3f%9.3f\n', parest(1:ip));
fprintf('\nCovariance matrix of score statistic\n');
for j = 1:ip
  fprintf('%9.3f', parvar(1:j,j));
fprintf('\nParameter estimates\n');
fprintf('%9.3f', parest(ip+1:ip+ip));
fprintf('\n\nCovariance matrix of parameter estimates\n');
for j = 1:ip
  fprintf('%9.3f', parvar(j+1,1:j));

chisq = parest(2*ip+1);
fprintf('\nChi-squared statistic = %8.3f with %2d d.f.\n\n', chisq, ip);

sterr = reshape(parest(2*ip+2:end),[ip,2]);
fprintf('Standard errors of estimates and approximate z-statistics\n');

g08ra example results

Number of samples           =   1
Number of parameters fitted =   2
Distribution                =   2
Tolerance for ties          =  1.0e-05

Score statistic
   -1.048   64.333

Covariance matrix of score statistic
   -4.159  533.670

Parameter estimates
   -0.852    0.114

Covariance matrix of parameter estimates
    0.012    0.002

Chi-squared statistic =    8.221 with  2 d.f.

Standard errors of estimates and approximate z-statistics
    1.2492   -0.6824
    0.0444    2.5673

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