Main Content

tiedrank

Rank adjusted for ties

Description

[R,tieadj] = tiedrank(X) returns the rank of each value in X. The function also returns an adjustment for ties between values that is used by the signrank and ranksum functions, and in the computation of the Spearman distance metric (see Distance Metrics). If any values in X are tied, tiedrank returns their average rank.

example

[R,tieadj] = tiedrank(X,1) returns the rank of the each value in X and adjustments for ties that are used in the computation of Kendall's Tau Coefficient.

example

[R,tieadj] = tiedrank(X,0,1) returns the rank of each value in X and adjustments for ties in X that are used in the Ansari-Bradley Test. The function computes the ranks from each end, so that the smallest and largest values are rank 1, the next smallest and largest values are rank 2, and so on.

example

Examples

collapse all

Create a vector that contains tied values, and compute the rank of each element.

A = [-2 1 3 1 4];
tiedrank(A)
ans = 1×5

    1.0000    2.5000    4.0000    2.5000    5.0000

The rank of the first element is 1 because it is has the smallest value. The second and fourth elements have rank 2.5 because their values are tied. The rank of the fifth element is 5 because it has the largest value.

Create a vector that contains tied values, and return the ranks and tie adjustments for use in computing the Spearman distance metric.

A = [-2 1 3 1 4];
[ranks,tieadj] = tiedrank(A)
ranks = 1×5

    1.0000    2.5000    4.0000    2.5000    5.0000

tieadj = 
3

Return the ranks and tie adjustments for use in computing Kendall's tau.

[ranks,tieadj] = tiedrank(A,1)
ranks = 1×5

    1.0000    2.5000    4.0000    2.5000    5.0000

tieadj = 3×1

     1
     0
    18

Return the ranks and tie adjustments for the Ansari-Bradley test.

[ranks,tieadj] = tiedrank(A,0,1)
ranks = 1×5

    1.0000    2.5000    2.0000    2.5000    1.0000

tieadj = 
3

Create a matrix that contains tied values, and compute the ranks of each column for the Ansari-Bradley test.

A = [4 1 4; 2 3 5; 2 1 7; 2 4 2; 1 6 4];
[R,tieadj] = tiedrank(A,0,1)
R = 5×3

    1.0000    1.5000    2.5000
    2.3333    3.0000    2.0000
    2.3333    1.5000    1.0000
    2.3333    2.0000    1.0000
    1.0000    1.0000    2.5000

tieadj = 1×3

    12     3     3

In the first column of R, the first and fifth elements have rank 1 because they have the largest and smallest values, respectively, in the corresponding column of A. The second, third, and fourth elements have rank 2.3333 because their values are tied.

Input Arguments

collapse all

Input data, specified as a numeric vector, matrix, or multidimensional array.

  • If X is a vector, then tiedrank operates on the elements of X.

  • If X is a matrix, then tiedrank operates on each column of X.

  • If X is a multidimensional array, then tiedrank operates along the second dimension of X.

Data Types: single | double

Output Arguments

collapse all

Ranks, returned as a numeric vector, matrix, or multidimensional array that has the same dimensions as X. If any values in X are tied, tiedrank returns their average rank. If the third input argument to tiedrank is true, then tiedrank returns ranks that are used in the Ansari-Bradley Test. In this case, the function computes the ranks from each end, so that the smallest and largest values are rank 1, the next smallest and largest values are rank 2, and so on.

  • If X is a vector, then tiedrank operates on the elements of X.

  • If X is a matrix, then tiedrank operates on each column of X.

  • If X is a multidimensional array, then tiedrank operates along the second dimension of X.

Adjustments for ties, returned as a nonnegative integer or a matrix of nonnegative integers. The content of tieadj is used by the signrank and ranksum functions, and in the computation of the Spearman distance metric (see Distance Metrics). The first dimension of tieadj has length 1, and higher dimensions have length size(X,2), size(X,3), up to size(X,k), where k is the number of dimensions of X. If the second input argument to tiedrank is true, then tieadj has a first dimension length of 3 and is used in the computation of Kendall's Tau Coefficient.

  • If X is a vector, then tiedrank operates on the elements of X.

  • If X is a matrix, then tiedrank operates on each column of X.

  • If X is a multidimensional array, then tiedrank operates along the second dimension of X.

Algorithms

tiedrank treats NaNs in X as missing values and ignores them. The rank of NaNs in R is NaN.

Extended Capabilities

expand all

Version History

Introduced before R2006a