Learn R Programming

hyper2 (version 2.0-1)

ordertrans: Order transformation

Description

Given an order vector, shuffle so that the players appear in a specified order.

Usage

ordertrans(x,players)
ordertransplot(ox,oy,...)

Arguments

x

A (generalized) order vector

players

A character vector specifying the order in which the players will be listed; if missing, use sort(names(x))

ox,oy

Rank vectors

...

Further arguments, passed to plot()

Value

Returns a named vector

Details

The best way to describe this function is with an example:

> x <- c(d=2,a=3,b=1,c=4) > x d a b c 2 3 1 4

In the above, we see x is an order vector showing that d came second, a came third, b came first, and c came fourth. This is difficult to deal with because one has to search through the vector to find a particular competitor, or a particular rank. This would be harder if the vector was longer. If we wish to answer the question “where did competitor a come? where did b come?” we would want an order vector in which the competitors are in alphabetical order. This is accomplished by ordertrans():

> o <- ordertrans(x)
> o
a b c d 
3 1 4 2 

(this is equivalent to o <- x[order(names(x))]). Object o contains the same information as x, but presented differently. This says that a came third, b came first, c came fourth, and d came second. In particular, the Plackett-Luce order statistic is identical:

> ordervec2supp(x) == ordervec2supp(o)
> [1] TRUE

There is a nice example of ordertrans() in inst/eurovision.Rmd, and file inst/ordertrans.Rmd provides further discussion and examples.

Function ordertrans() takes a second argument which allows the user to arrange an order vector into the order specified.

See Also

rrank

Examples

Run this code
# NOT RUN {
x <- c(e=4L,a=7L,c=6L,b=1L,f=2L,g=3L,h=5L,i=8L,d=9L)
ordertrans(x,letters[1:9])

o <- skating_table[,1]
names(o) <- rownames(skating_table)
ordertrans(o)


ordertrans(sample(icons_maxp),icons)


rL <- volvo_maxp   # rL is "ranks Likelihood"
rL[] <- rank(-volvo_maxp)

r1 <- volvo_table[,1]  # ranks race 1
names(r1) <- rownames(volvo_table)
ordertransplot(rL,r1,xlab="likelihood rank, all races",ylab="rank, race 1")

# }

Run the code above in your browser using DataLab