ordertable.RdManipulate, print and coerce to and from ordertable form
as.ordertable(w)
ordertable(x)The package makes extensive use of order tables and these are discussed
here together with a list of order tables available in the package as
data. See also ranktable.Rd.
The prototypical ordertable would be pentathlon_table:
> pentathlon_table
An ordertable:
shooting fencing swimming riding running
Moiseev 5 1 1 6 5
Zadneprovskis 6 2 5 5 1
Capalini 4 6 2 3 4
Cerkovskis 3 3 7 7 2
Meliakh 1 7 4 1 6
Michalik 2 4 6 2 7
Walther 7 5 3 4 3
Although pentathlon_table is a dataset in the package, the source
dataset is also included in the inst/ directory as file
pentathlon.txt; use idiom like
read.table("inst/pentathlon.txt") to load the order table.
Object pentathlon_table is a representative example of an
ordertable. Each row is a competitor, each column an event (venue,
judge, ...). The first row shows Moiseev's ranking in shooting
(5th), fencing (1st), and so on. The first column shows the ranks of
the competitors in shooting. Thus Moiseev came fifth, Zadneprovskis
came 6th, and so on.
However, to create a likelihood function we need ranks, not orders. We
need to know, for a given event, who came first, who came second, and so
on (an extended discussion on the difference between rank and order is
given at rrank). We can convert from an order table to a rank
table using ordertable_to_ranktable() (see also
ranktable.Rd):
> ordertable_to_ranktable(pentathlon_table)
c1 c2 c3 c4 c5
shooting Meliakh Michalik Cerkovskis Capalini Moiseev
fencing Moiseev Zadneprovskis Cerkovskis Michalik Walther
swimming Moiseev Capalini Walther Meliakh Zadneprovskis
riding Meliakh Michalik Capalini Walther Zadneprovskis
running Zadneprovskis Cerkovskis Walther Capalini Moiseev
c6 c7
shooting Zadneprovskis Walther
fencing Capalini Meliakh
swimming Michalik Cerkovskis
riding Moiseev Cerkovskis
running Meliakh Michalik
Above, we see the same data in a different format (an extended discussion on the difference between rank and order is given in rrank).
Many of the order tables in the package include entries that correspond to some variation on “did not finish”. Consider the volvo dataset, an ordertable:
> volvo_table
An ordertable:
leg1 leg2 leg3 leg4 leg5 leg6 leg7 leg8 leg9
AbuDhabi 1 3 2 2 1 2 5 3 5
Brunel 3 1 5 5 4 3 1 5 2
Dongfeng 2 2 1 3 DNF 1 4 7 4
MAPFRE 7 4 4 1 2 4 2 4 3
Alvimedica 5 5 3 4 3 5 3 6 1
SCA 6 6 6 6 5 6 6 1 7
Vestas 4 DNF DNS DNS DNS DNS DNS 2 6
In the above order table, we have DNF for “did not finish”
and DNS for “did not start”. The formula1 order
table has other similar entries such as DSQ for
“disqualified” and a discussion is given at
ordertable2supp.Rd.
Links are given below to all the order tables in the package. Note that
the table in inst/eurovision.Rmd (wiki_matrix) is not an
order table because no country is allowed to vote for itself.
To coerce a table like the Volvo dataset shown above into an order table
[that is, replace DNS with zeros, and also force nonzero entries
to be contiguous], use as.ordertable().
Given an ordertable such as F1_table_2017 which is a
“wikitable” object, function as.ordertable() returns a
nicified version in which entries such as DNS are replaced with
zeros. Finishing competitors are assigned numbers \(1-n\) with no
gaps; the function can be used to extract a subset of competitors.
Function ordertable2supp() offers similar functionality but
returns a hyper2 object directly.
There is an experimental extraction method which extracts certain rows
of an ordertable; this is used in inst/skating.Rmd.
ordertable_to_ranktable(soling_table)
#> A ranktable:
#> c1 c2 c3 c4 c5 c6 c7 c8
#> I netherlands russia nz USA norway denmark sweden australia
#> II ukraine norway nz finland netherlands italy UK russia
#> III norway USA germany russia sweden australia ukraine UK
#> IV australia nz norway UK italy ukraine germany russia
#> V netherlands USA france UK norway russia nz spain
#> VI netherlands USA nz denmark sweden spain france canada
#> c9 c10 c11 c12 c13 c14 c15 c16
#> I france canada finland ukraine UK germany spain italy
#> II canada germany australia spain france USA sweden denmark
#> III canada nz france denmark netherlands italy finland spain
#> IV france sweden netherlands denmark canada finland spain USA
#> V australia germany denmark canada finland italy ukraine sweden
#> VI russia italy germany ukraine UK australia finland norway
suppfun(soling_table) == soling # should be TRUE
#> [1] TRUE
as.ordertable(F1_table_2017)
#> An ordertable:
#> AUS CHN BHR RUS ESP MON CAN AZE AUT GBR HUN BEL ITA SIN MAL JPN USA
#> Hamilton 2 1 2 4 1 7 1 5 4 1 4 1 1 1 2 1 1
#> Vettel 1 2 1 2 2 1 4 4 2 7 1 2 3 0 4 0 2
#> Bottas 3 6 3 1 0 4 2 2 1 2 3 5 2 3 5 4 5
#> Raikkonen 4 5 4 3 0 2 7 14 5 3 2 4 5 0 0 5 3
#> Ricciardo 0 4 5 0 3 3 3 1 3 5 0 3 4 2 3 3 0
#> Verstappen 5 3 0 5 0 5 0 0 0 4 5 0 10 0 1 2 4
#> Perez 7 9 7 6 4 13 5 0 7 9 8 17 9 5 6 7 8
#> Ocon 10 10 10 7 5 12 6 6 8 8 9 9 6 10 10 6 6
#> Sainz 8 7 0 10 7 6 0 8 0 0 7 10 14 4 0 0 7
#> Hulkenberg 11 12 9 8 6 0 8 0 13 6 17 6 13 0 16 0 0
#> Massa 6 14 6 9 13 9 0 0 9 10 0 8 8 11 9 10 9
#> Stroll 0 0 0 11 16 15 9 3 10 16 14 11 7 8 8 0 11
#> Grosjean 0 11 8 0 10 8 10 13 6 13 0 7 15 9 13 9 14
#> Magnussen 0 8 0 13 14 10 12 7 0 12 13 15 11 0 12 8 16
#> Alonso 0 0 14 0 12 0 16 9 0 0 6 0 17 0 11 11 0
#> Vandoorne 13 0 0 14 0 0 14 12 12 11 10 14 0 7 7 14 12
#> Palmer 0 13 13 0 15 11 11 0 11 0 12 13 0 6 15 12 0
#> Wehrlein 0 0 11 16 8 0 15 10 14 17 15 0 16 12 17 15 0
#> Kvyat 9 0 12 12 9 14 0 0 16 15 11 12 12 0 0 0 10
#> Ericsson 0 15 0 15 11 0 13 11 15 14 16 16 18 0 18 0 15
#> Gasly 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 13 0
#> Giovinazzi 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> Hartley 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13
#> Button 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> Resta 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> MEX BRA ABU
#> Hamilton 9 4 2
#> Vettel 4 1 3
#> Bottas 2 2 1
#> Raikkonen 3 3 4
#> Ricciardo 0 6 0
#> Verstappen 1 5 5
#> Perez 7 9 7
#> Ocon 5 0 8
#> Sainz 0 11 0
#> Hulkenberg 0 10 6
#> Massa 11 7 10
#> Stroll 6 16 18
#> Grosjean 15 15 11
#> Magnussen 8 0 13
#> Alonso 10 8 9
#> Vandoorne 12 0 12
#> Palmer 0 0 0
#> Wehrlein 14 14 14
#> Kvyat 0 0 0
#> Ericsson 0 13 17
#> Gasly 13 12 16
#> Giovinazzi 0 0 0
#> Hartley 0 0 15
#> Button 0 0 0
#> Resta 0 0 0
ordertable2supp(as.ordertable(F1_table_2017[1:9,]))
#> log(Bottas^19 * (Bottas + Hamilton + Ocon + Perez + Raikkonen +
#> Ricciardo + Sainz + Verstappen)^-5 * (Bottas + Hamilton + Ocon + Perez
#> + Raikkonen + Ricciardo + Sainz + Verstappen + Vettel)^-20 * (Bottas +
#> Hamilton + Ocon + Perez + Raikkonen + Ricciardo + Sainz + Vettel)^-2 *
#> (Bottas + Hamilton + Ocon + Perez + Raikkonen + Sainz + Verstappen +
#> Vettel)^-1 * (Bottas + Hamilton + Ocon + Perez + Ricciardo + Sainz +
#> Verstappen)^-2 * (Bottas + Hamilton + Ocon + Perez + Sainz +
#> Verstappen)^-1 * (Bottas + Ocon + Perez + Raikkonen + Ricciardo +
#> Sainz)^-1 * (Bottas + Ocon + Perez + Raikkonen + Ricciardo + Sainz +
#> Verstappen)^-6 * (Bottas + Ocon + Perez + Raikkonen + Ricciardo + Sainz
#> + Verstappen + Vettel)^-9 * (Bottas + Ocon + Perez + Raikkonen +
#> Ricciardo + Sainz + Vettel)^-2 * (Bottas + Ocon + Perez + Raikkonen +
#> Sainz)^-2 * (Bottas + Ocon + Perez + Raikkonen + Sainz + Verstappen)^-2
#> * (Bottas + Ocon + Perez + Raikkonen + Sainz + Verstappen + Vettel)^-1
#> * (Bottas + Ocon + Perez + Raikkonen + Sainz + Vettel)^-2 * (Bottas +
#> Ocon + Perez + Ricciardo + Sainz)^-1 * (Bottas + Ocon + Perez +
#> Ricciardo + Sainz + Verstappen)^-1 * (Bottas + Ocon + Perez + Sainz)^-1
#> * (Bottas + Ocon + Perez + Sainz + Verstappen)^-1 * (Bottas + Ocon +
#> Raikkonen + Sainz + Verstappen)^-1 * (Bottas + Raikkonen + Sainz +
#> Verstappen)^-1 * Hamilton^20 * (Hamilton + Ocon + Perez)^-1 * (Hamilton
#> + Ocon + Perez + Raikkonen + Ricciardo + Sainz + Verstappen)^-3 *
#> (Hamilton + Ocon + Perez + Raikkonen + Ricciardo + Sainz + Verstappen +
#> Vettel)^-3 * (Hamilton + Ocon + Perez + Raikkonen + Ricciardo + Sainz +
#> Vettel)^-1 * (Hamilton + Ocon + Perez + Raikkonen + Sainz +
#> Verstappen)^-2 * (Hamilton + Ocon + Perez + Raikkonen + Sainz +
#> Verstappen + Vettel)^-1 * (Hamilton + Ocon + Perez + Ricciardo +
#> Sainz)^-1 * (Hamilton + Ocon + Perez + Ricciardo + Sainz +
#> Verstappen)^-3 * (Hamilton + Ocon + Perez + Ricciardo + Sainz +
#> Vettel)^-1 * (Hamilton + Ocon + Perez + Sainz)^-1 * (Hamilton + Ocon +
#> Perez + Sainz + Verstappen)^-1 * (Hamilton + Perez + Ricciardo +
#> Sainz)^-1 * (Hamilton + Ricciardo + Sainz)^-1 * Ocon^18 * (Ocon +
#> Perez)^-2 * (Ocon + Perez + Raikkonen + Ricciardo + Sainz +
#> Verstappen)^-4 * (Ocon + Perez + Raikkonen + Ricciardo + Sainz +
#> Verstappen + Vettel)^-4 * (Ocon + Perez + Raikkonen + Sainz)^-1 * (Ocon
#> + Perez + Raikkonen + Sainz + Verstappen)^-4 * (Ocon + Perez +
#> Raikkonen + Sainz + Verstappen + Vettel)^-2 * (Ocon + Perez + Raikkonen
#> + Sainz + Vettel)^-1 * (Ocon + Perez + Raikkonen + Verstappen +
#> Vettel)^-1 * (Ocon + Perez + Ricciardo)^-1 * (Ocon + Perez + Ricciardo
#> + Sainz)^-6 * (Ocon + Perez + Ricciardo + Sainz + Verstappen)^-6 *
#> (Ocon + Perez + Ricciardo + Sainz + Verstappen + Vettel)^-1 * (Ocon +
#> Perez + Ricciardo + Sainz + Vettel)^-1 * (Ocon + Perez + Sainz)^-3 *
#> (Ocon + Perez + Sainz + Verstappen)^-4 * (Ocon + Perez + Sainz +
#> Vettel)^-2 * (Ocon + Raikkonen + Sainz)^-1 * (Ocon + Raikkonen + Sainz
#> + Verstappen)^-1 * (Ocon + Raikkonen + Verstappen + Vettel)^-1 * (Ocon
#> + Ricciardo)^-2 * (Ocon + Ricciardo + Sainz)^-3 * (Ocon + Sainz)^-1 *
#> (Ocon + Sainz + Verstappen)^-2 * Perez^18 * (Perez + Raikkonen + Sainz
#> + Verstappen)^-1 * (Perez + Raikkonen + Verstappen)^-1 * (Perez +
#> Ricciardo)^-1 * (Perez + Ricciardo + Sainz)^-1 * (Perez + Sainz)^-1 *
#> (Perez + Sainz + Verstappen)^-2 * (Perez + Sainz + Vettel)^-1 * (Perez
#> + Verstappen)^-1 * Raikkonen^17 * (Raikkonen + Sainz + Verstappen)^-1 *
#> Ricciardo^14 * (Ricciardo + Sainz)^-1 * Sainz^11 * (Sainz +
#> Verstappen)^-1 * Verstappen^13 * Vettel^18)