
To cite the hyper2 package in publications, please use
Hankin (2017).
library("hyper2", quietly=TRUE)
lines <- readLines("scottish_premier_league.txt")
orderstat <- lapply(lines, function(z) {as.character(read.table(text=z, header=FALSE)[-1])})
years <- sapply(lines, function(z) {as.numeric(read.table(text=z, header=FALSE)[1])})
names(years) <- NULL
names(orderstat) <- years
orderstat[[1]]
## [1] "Celtic" "Motherwell" "Aberdeen"
## [4] "Dundee United" "Inverness Caledonian Thistle" "St Johnstone"
## [7] "Ross County" "St Mirren" "Kilmarnock"
## [10] "Partick Thistle" "Hibernian" "Heart of Midlothian"
L <- hyper2()
for(i in seq_along(orderstat)){L <- L + race(orderstat[[i]])}
summary(L)
## A hyper2 object of size 17.
## pnames: Aberdeen Celtic Dundee Dundee United Falkirk Hamilton Academical Heart of Midlothian Hibernian Inverness Caledonian Thistle Kilmarnock Livingston Motherwell Partick Thistle Rangers Ross County St Johnstone St Mirren
## Number of brackets: 159
## Sum of powers: 0
##
## Table of bracket lengths:
## 1 2 3 4 5 6 7 8 9 10 11 12
## 17 13 13 13 13 13 13 12 13 13 13 13
##
## Table of powers:
## -2 -1 1 3 5 6 7 9 10 11 12 13
## 1 141 1 1 2 2 1 2 3 1 1 3
Find the evaluate:
M <- maxp(L)
M
## Aberdeen Celtic Dundee
## 0.00610315 0.89961146 0.00092055
## Dundee United Falkirk Hamilton Academical
## 0.00114516 0.00592721 0.00064333
## Heart of Midlothian Hibernian Inverness Caledonian Thistle
## 0.00237927 0.00357227 0.00106174
## Kilmarnock Livingston Motherwell
## 0.00127623 0.00105114 0.00213577
## Partick Thistle Rangers Ross County
## 0.00106335 0.06919572 0.00092740
## St Johnstone St Mirren
## 0.00173108 0.00125518
pie(M)
Now profile likelihood for Celtic:
p <- seq(from=0.6, to=0.995, len=17)
s <- profsupp(L, "Celtic", p)
plot(p, s, type="b")
hyper2 Package: Likelihood Functions for Generalized Bradley-Terry Models.” The R Journal 9 (2): 429–39.