| ordertrans {hyper2} | R Documentation |
Given an order vector, shuffle so that the players appear in a specified order.
ordertrans(x,players) ordertransplot(ox,oy,...)
x |
A (generalized) order vector |
players |
A character vector specifying the order in which the
players will be listed; if missing, use |
ox,oy |
Rank vectors |
... |
Further arguments, passed to |
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.
Returns a named vector
The argument to ordertrans() is technically an order vector
because it answers the question “where did the first-named
competitor come?” (see the discussion at rrank.Rd). But it is
not a helpful order vector because you have to go searching through
the names—which can appear in any order—for the competitor you are
interested in. I guess “generalised order vector” might be a
better description of the argument.
Robin K. S. Hankin
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")