Learn R Programming

hyper2 (version 3.0-0)

hyper3: Weighted probability vectors: hyper3 objects require(hyper2)

Description

Objects of class hyper3 are a generalization of hyper2 objects that allow the brackets to contain weighted probabilities.

As a motivating example, suppose two players with Bradley-Terry strengths p_1,p_2 play chess where we quantify the first-mover advantage with a term omitted. If p_1 plays white a+b times with a wins and b losses, and plays black c+d times with c wins and d losses, then a sensible likelihood function might be

( p_1 p_1 + p_2)^a (p_2 p_1 + p_2)^b (p_1 p_1 + p_2)^c ( p_2p_1 + p_2)^d omitted: see PDF

If a=1,b=2,c=3,d=4 and =1.3omitted appropriate package idiom might be:

H <- hyper3() H[c(p1=1.3)] %<>% inc(1) # a=1 H[c(p2=1)] %<>% inc(2) # b=2 H[c(p1=1.3,p2=1)] %<>% dec(3) # a+b=1+2=3 H[c(p1=1)] %<>% inc(3) # c=3 H[c(p2=1.3)] %<>% inc(4) # d=4 H[c(p1=1,p2=1.3)] %<>% dec(7) # c+d=3+4=7 H > log( (p1=1)^3 * (p1=1, p2=1.3)^-7 * (p1=1.3)^1 * (p1=1.3, p2=1)^-3 * (p2=1)^2 * (p2=1.3)^4)

Usage

hyper3(B = list(), W = list(), powers = 0, pnames)
hyper3_bw(B = list(), W = list(), powers = 0, pnames)
hyper3_nv(L=list(),powers=0,pnames)

Value

Generally return or deal with hyper3 objects

Arguments

B

A list of brackets

W

A list of weights

L

A list of named vectors

powers

Numeric vector of powers

pnames

Character vector of player names

Author

Robin K. S. Hankin

Details

  • Function hyper3() is the user-friendly creation method, which dispatches to helper functions hyper3_bw() and hyper3_nv() depending on its arguments.

  • Function hyper3_bw() takes a list of brackets (character vectors) and a list of weights (numeric vectors) and returns a hyper3 object.

  • Function hyper2_nv() takes a list of named vectors and returns a hyper3 object.

  • Function evaluate3() is a low-level helper function that evaluates a log-likelihood at a point in probability space. Don't use this: use the user-friendly loglik() instead, which dispatches to evaluate3().

  • Function maxp3() is a placeholder (it is not yet written). But the intention is that it will maximize the log-likelihood of a hype3 object over the Bradley Terry strengths and any weights given. This might not be possible as envisaged right now; I present some thoughts in inst/kka.Rmd.

  • Function list2nv() converts a list of character vectors into a named vector suitable for use as argument e of function cheering3(). It is used in inst/global_liveability_ranking.Rmd.

See Also

hyper2

Examples

Run this code

hyper3(B=list("a",c("a","b"),"b"),W=list(1.2,c(1.2,1),1),powers=c(3,4,-7))
hyper3(list(c(a=1.2),c(b=1),c(a=1.2,b=1)),powers=c(3,4,-7))


## Above two objects should be identical


a <- hyper3()  # default creation method [empty object]

a[c(p1=1.3)] <- 5
a[c(p1=1.3)] <- a[c(p1=1.3)] + 3
a[c(p1=1.3,p2=1)]  <- a[c(p1=1.3,p2=1)] -1
a

chess3  # representative simple hyper3 object

Run the code above in your browser using DataLab