knitr::opts_chunk$set(echo = TRUE)
library("hyper2")
library("pracma")
library("magrittr")
knitr::include_graphics(system.file("help/figures/hyper2.png", package = "hyper2"))

This follows on from vsl_teams.Rmd and vsl_partial_ranks.Rmd. But the application of those ideas to MasterChef is flawed: as the competition progresses, Brent and Laura face increasingly skilled competitors, for the weakest ones have been eliminated. And it is not clear to what extent that observation interferes with the assumtion of constant non-focal competitor strength.

f_single_old <- function(a,r,n){  # not vectorised
    B <- 1/(1-a)
    (B-1)/prod(B+(n-r-1):(n-1)) * exp( lfactorial(n)-lfactorial(n-r))
}

f_single <- function(a,r,n){
    B <- 1/(1-a)
    exp(log(B-1)-lgamma(B+n)+lgamma(B+n-r-1)+lfactorial(n)-lfactorial(n-r))
}
f_vec_a <- function(a,r,n){  # vectorised in 'a' but not in 'r'
    sapply(a,function(a){f_single(a,r=r,n=n)})
}
L_range <- function(a,possible,n){ # r1=4 -> came fifth [four b clones ahead]  
    out <- a*0
    for(i in (possible)){
        out <- out + f_vec_a(a,i-1,n-1) }
    return(out)
}

Two teams of size $m$:

`L_win` <- function(a,m){
    b <- 1-a
    ((m-2)*b+1)/((2*m-2)*b+1)}

`L_lose` <- function(a,m){1-L_win(a,m)}

Laura in Australian MasterChef series 6

Brent in Australian MasterChef series 6

L_laura <- function(a){
    b <- 1-a
    out <- a*0 + 1
    out <- out * L_range(a,2:3,24)    # week 1
    out <- out * L_range(a,4:20,24)   # week 2
    out <- out * L_lose(a,11)         # week 2
    out <- out * L_range(a,1:5,11)    # week 2
    out <- out * L_range(a,1:3,21)    # week 3
    out <- out * L_win(a,10)          # week 3
    out <- out * L_range(a,4:16,19)   # week 4
    out <- out * L_win(a,9)           # week 4
    out <- out * 4*b*(1+2*b)/
                 (1+14*b)/(1+10*b)    # week 5
    out <- out * L_range(a,14:15,16)  # week 6
    out <- out * L_win(a,7)           # week 6
    out <- out * L_range(a,1:3,13)    # week 7
    out <- out * L_lose(a,6)          # week 7
    out <- out * L_range(a, 10, 11)   # week 8
    out <- out * L_lose(a,5)          # week 8
    out <- out * L_range(a,1:6,11)    # week 9
    out <- out * L_lose(a,5)          # week 9
    out <- out * L_range(a,4,5)       # week 9
    out <- out * L_range(a,1:3,9)     # week 10
    out <- out * 1/(7-6*a)            # week 10
    out <- out * L_range(a,1:3,7)     #  week 11
    out <- out * L_range(a,4:6,6)     # finals
    out <- out * L_range(a,1:2,3)     # finals
    out <- out * L_range(a,1:3,5)     # finals
    out <- out * L_range(a,1,4)       # finals
    out <- out * L_range(a,1:2,3)     # finals
    out <- out * L_range(a,2,2)       # finals
    return(out)
}
evaluate <- optimize(L_laura,c(0.1,0.9),maximum=TRUE)$max
small <- 1e-4
second <- (2*log(L_laura(evaluate))-log(L_laura(evaluate-small))-log(L_laura(evaluate+small)))/small^2
evaluate
second
f <- function(x){x*(1-x)}
(2*log(f(evaluate))-log(f(evaluate-small))-log(f(evaluate+small)))/small^2
a <- seq(from=0,to=1,by=0.01)
L <- L_laura(a)
L <- L/max(L,na.rm=TRUE)
plot(a,L)
abline(v=evaluate)
plot(a,log(L),ylim=c(-5,0))
abline(h= -2)
abline(v=evaluate)


RobinHankin/hyper2 documentation built on May 6, 2024, 4:25 p.m.