Learn R Programming

independence (version 1.0.1)

relative.order: The relative order of two vectors

Description

Given (X1,Y1),...,(Xn,Yn), many nonparametric statistics depend only on the permutation P that satisfies rank Yi = P[rank Xi]. The function relative_order computes such P given X1,...,Xn and Y1,...,Yn.

Usage

relative.order(xs, ys, na.rm = TRUE, collisions = TRUE)

Arguments

xs, ys

Numeric vectors of same length.

na.rm

Logical: Should missing values, NaN, and Inf be removed?

collisions

Logical: Warn of repeating values in xs or ys.

Value

An integer vector which describes the ordering of the second argument ys, in terms of the ordering of the corresponding values in the first argument xs.

For example, if xs[3] is the ith smallest and ys[3] is the jth smallest, then the returned value in position i is j.

Details

By default, the function removes missing values, and warns of repeating values. Then it computes the relative order by calling the base R function order twice: order(xs[order(ys)]).

Ties may be broken arbitrarily, depending on the behavior of the function order.

Examples

Run this code
# NOT RUN {
relative.order(1:5, c(10,30,50,40,20))
## [1] 1 3 5 4 2

relative.order(c(1,2,5,3,4), c(10,30,50,40,20))
## [1] 1 3 4 2 5

set.seed(123)
relative.order(runif(8), runif(8))
## [1] 5 4 8 1 3 2 7 6
# }

Run the code above in your browser using DataLab