relative.order: The relative order of two vectors

Description Usage Arguments Details Value Examples

View source: R/independence.R

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

1
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.

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.

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.

Examples

1
2
3
4
5
6
7
8
9
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

independence documentation built on Jan. 14, 2021, 5:20 a.m.