### Baseball, Chess, Psychology and Pychometrics: Everyone Uses the Same Damn Rating System

Here's a short summary of the relationship between common models used in baseball, chess, psychology and education. The starting point for examining the connections between various extended models in these areas. The next steps include multiple attempts, guessing, ordinal and multinomial outcomes, uncertainty and volatility, multiple categories and interactions. There are also connections to standard optimization algorithms (neural  nets, simulated annealing).

Baseball

Common in baseball and other sports, the log5 method provides an estimate for the probability $$p$$ of participant 1 beating participant 2 given respective success probabilities $$p_1, p_2$$. Also let $$q_* = 1 -p_*$$ in the following. The log5 estimate of the outcome is then:

\begin{align}
p &= \frac{p_1 q_2}{p_1 q_2+q_1 p_2}\\
&= \frac{p_1/q_1}{p_1/q_1+p_2/q_2}\\
\frac{p}{q} &= \frac{p_1}{q_1} \cdot \frac{q_2}{p_2}
\end{align}

The final form uses the odds ratio, $$\frac{p}{q}$$. Additional factors can be easily chained using this form to provide more complex estimates. For example, let $$p_e$$ be an environmental factor, then:

\begin{align}
\frac{p}{q} &= \frac{p_1}{q_1} \cdot \frac{q_2}{p_2} \cdot \frac{q_e}{p_e}
\end{align}

Chess

The most common rating system in chess is the Elo rating system. This has also been adopted for various other uses, e.g. hot or not'' websites. This system assigns ratings $$R_1, R_2$$ to players 1 and 2 such that the probability of player 1 beating player 2 is approximately:

\begin{align}
p &= \frac{e^{R_1/C}}{e^{R_1/C}+e^{R_2/C}}
\end{align}

Here $$C$$ is just a scaling factor (typically $$400/\ln{10}$$ ). The Elo rating is connected to log5 via setting $$e^{R/C} = p/q$$. We then recover:

\begin{align}
\frac{p}{q} &= e^{R/C}\\
p &= \frac{e^{R/C}}{1+e^{R/C}}\\
R &= C\cdot \ln(p/q)
\end{align}

Note that $$p$$ is also the probability of this player beating another player with Elo rating 0. The Elo system generally includes enhancements accounting for ties, first-move advantage and also an online algorithm for updating ratings. We'll revisit these features later.

Psychology

The Bradley-Terry-Luce (BTL) model is commonly used in psychology. Given two items, the probability $$p$$ that item 1 is ranked over item 2 is approximately:

\begin{align}
p &= \frac{Q_1}{Q_1+Q_2}
\end{align}

In this context $$Q_*$$ typically reflects the amount of a certain quality. That this model is equivalent to the previous models is immediate:

\begin{align}
Q &= e^{R/C} = p/q\\
R &= C\cdot \ln(Q) = C\cdot \ln(p/q)\\
p &= \frac{Q}{1+Q}
\end{align}

Psychometrics

The dichotomous (two-response) Rasch and item response models are commonly used in psychometrics. For the Rasch model, let $$r_1$$ represent a measurement of ability and $$r_2$$ the difficulty of the test item. The Rasch model estimates the probability of correct response $$p$$ as:

\begin{align}
p &= \frac{e^{r_1-r_2}}{1+e^{r_1-r_2}}
\end{align}

The one-parameter item response model estimates:

\begin{align}
p &= \frac{1}{1+e^{r_2-r_1}}
\end{align}

These are clearly equivalent to each other and to the previous models.

### A Bayes' Solution to Monty Hall

For any problem involving conditional probabilities one of your greatest allies is Bayes' Theorem. Bayes' Theorem says that for two events A and B, the probability of A given B is related to the probability of B given A in a specific way.

Standard notation:

probability of A given B is written $$\Pr(A \mid B)$$
probability of B is written $$\Pr(B)$$

Bayes' Theorem:

Using the notation above, Bayes' Theorem can be written: $\Pr(A \mid B) = \frac{\Pr(B \mid A)\times \Pr(A)}{\Pr(B)}$Let's apply Bayes' Theorem to the Monty Hall problem. If you recall, we're told that behind three doors there are two goats and one car, all randomly placed. We initially choose a door, and then Monty, who knows what's behind the doors, always shows us a goat behind one of the remaining doors. He can always do this as there are two goats; if we chose the car initially, Monty picks one of the two doors with a goat behind it at random.

Assume we pick Door 1 and then Monty sho…

### Mixed Models in R - Bigger, Faster, Stronger

When you start doing more advanced sports analytics you'll eventually starting working with what are known as hierarchical, nested or mixed effects models. These are models that contain both fixed and random effects. There are multiple ways of defining fixed vs random random effects, but one way I find particularly useful is that random effects are being "predicted" rather than "estimated", and this in turn involves some "shrinkage" towards the mean.

Here's some R code for NCAA ice hockey power rankings using a nested Poisson model (which can be found in my hockey GitHub repository):
model <- gs ~ year+field+d_div+o_div+game_length+(1|offense)+(1|defense)+(1|game_id) fit <- glmer(model, data=g, verbose=TRUE, family=poisson(link=log) ) The fixed effects are year, field (home/away/neutral), d_div (NCAA division of the defense), o_div (NCAA division of the offense) and game_length (number of overtime periods); off…

### Notes on Setting up a Titan V under Ubuntu 17.04

I recently purchased a Titan V GPU to use for machine and deep learning, and in the process of installing the latest Nvidia driver's hosed my Ubuntu 16.04 install. I was overdue for a fresh install of Linux, anyway, so I decided to upgrade some of my drives at the same time. Here are some of my notes for the process I went through to get the Titan V working perfectly with TensorFlow 1.5 under Ubuntu 17.04.

Old install:
Ubuntu 16.04
EVGA GeForce GTX Titan SuperClocked 6GB
2TB Seagate NAS HDD