knitr::opts_chunk$set(echo = TRUE) library("hyper2")
Formula 1 grand prix racing, 2022 season. We wonder whether placing well at a race helps the team in some way in the next race. The "help" might be an $\alpha$ weighting term for just the winners, or a $\alpha^n$ term for placing $n$-th in the previous race. I would have thought $\alpha>1$ [the help accruing from a win is positive] but it is possible that $\alpha<1$ which would correspond to it being a hindrance in some way. Perhaps winning leads to overconfidence or complacency in the next one?
setwd("~/rstudio/hyper2/inst") finish <- read.table("formula1_2023.txt",header=TRUE) finish <- finish[,seq_len(ncol(finish)-1)] finish[1:9,1:5]
f <- function(i){ # this is column 'i' of finish ordertable2supp(finish[,i,drop=FALSE]) } g <- function(i){ suppressWarnings(out <- as.numeric(finish[,i,drop=TRUE])) out[is.na(out)] <- length(out) names(out) <- rownames(finish) return(out) }
weightedlikelihood <- function(alpha){ out <- hyper3() for(i in seq(from=2,to=ncol(finish))){ H <- f(i) previous <- g(i-1) H[names(previous)] <- as.weight(alpha^previous) out <- out + H } return(out) }
H <- weightedlikelihood(0.9) mH <- maxp(H)
mH dotchart(mH) loglik(mH,H)
H91 <- weightedlikelihood(0.91) mH91 <- maxp(H91)
mH91 dotchart(mH91) loglik(mH91,H91)
likealpha <- function(alpha){ H <- weightedlikelihood(alpha) mH <- maxp(H) return(loglik(mH,H)) }
alpha <- seq(from=0.95,to=1.02,by=0.01) likes <- sapply(alpha,likealpha)
plot(alpha,likes-max(likes),type='b') abline(h=c(0,-2)) abline(v=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.