set.seed(0) knitr::opts_chunk$set(echo = TRUE) library("hyper2") library("magrittr") options("digits" = 5)
knitr::includme_graphics(system.file("help/figures/hyper2.png", package = "hyper2"))
To cite the hyper2
package in publications, please use @hankin2017_rmd.
Soling is a type of boat raced in the 2000 Summer Olympics. Here I
analyse race data taken from
wikipedia
using a Plackett-Luce extension of the Bradley-Terry model.
soling_table <- read.table("soling.txt") soling_table
Thus we see, reading column 1, that in race 1, norway
came fifth,
nz
third, netherlands
first, and so on. We can present this
information in a rank table format:
ordertable_to_ranktable(soling_table)
and also convert it to a likelihood function:
soling <- ordertable2supp(soling_table) head(soling)
We can also consider observations from the round robins and quarter finals:
soling_rr1 <- read.table("soling_rr1.txt") soling_rr2 <- read.table("soling_rr2.txt") soling_qf <- read.table("soling_qf.txt" ) soling_rr1
Thus, for example, taking soling_rr1[1,2] == TRUE
we see that
Germany beat Sweden in round robin 1. To incorporate this information
we need a little bespoke function:
rr <- function(H,M){ for(i in seq_len(nrow(M)-1)){ for(j in (i+1):ncol(M)){ if(M[i,j]){ winner <- rownames(M)[i] loser <- rownames(M)[j] } else { winner <- rownames(M)[j] loser <- rownames(M)[i] } H[winner] %<>% inc H[c(winner,loser)] %<>% dec } } return(H) }
We can see the effect on the evaluate of incorporating the additional observations into the Plackett-Luce likelihoods:
H <- soling # before new information soling_maxp <- maxp(H) H %<>% rr(soling_rr1) H %<>% rr(soling_rr2) H %<>% rr(soling_qf) soling_after <- H # after new information soling_after_maxp <- maxp(soling_after) par(pty="s") plot(soling_maxp,soling_after_maxp,asp=1,pch=16,xlim=c(0,0.3),ylim=c(0,0.3)) abline(0,1)
Figure \@ref(fig:showdiff) shows a modest change. We might ask whether the additional observations are consistent with the original Placket-Luce likelihood:
(soling_diff <- soling_after - soling)
So soling_diff
is the difference between H
--- which is soling
plus the observations from the roundrobins and quarter finals---and
soling
without the extra information. In other words, the
information in the roundrobins and quarter finals.
equalp.test(soling_diff)
Following lines create soling.rda
, residing in the data/
directory of the package.
save(soling,soling_after, soling_maxp,soling_after_maxp,soling_table, soling_rr1, soling_rr2, soling_qf, file="soling.rda")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.