Fundamentals of Machine Learning for NHS using R
Aim: To predict the dependent variable \(Y\). \[P(Y=0)=1-P(Y=1)\] Denote \(k\) independent variables \[x_1,x_2, .,x_k\]
Suppose we roll a dice numbered 1 to 6 and we are interested in the outcome of rolling greater than a 2. \[ P(Roll>2) = 4/6 \\ P(Roll \leq 2) = 2/6 \] Therefore, the odds of rolling >2 \[ Odds=P(Roll>2)/P(Roll \leq 2)= 4/2 = 2 \] Odds 2:1
However, there is a problem using this calculation in the model. If probability =1 then \[
Odds = 1/0= \infty
\]
So, we use log odds instead. \[
Odds = Ln(P(Y=1)/P(Y=0) )
\] It maps probability ranging between 0 and 1 to log odds ranging from negative infinity to positive infinity.
From mathematics, it can be shown that: \[ Ln\frac{P(Y=1)}{P(Y=0)}=\beta_0+\beta_1x_1+\beta_2x_2+\ldots+\beta_k x_k \] Hence we need to rearrange this function in terms of P(Y=1).
Given the fact that \[ \frac{P(Y=1)}{P(Y=0)}=\frac{P(Y=1)}{1 - P(Y=1)} \]
Taking logs of both sides you get \[ \frac{P(Y=1)}{1 - P(Y=1)} = e^{\beta_0+\beta_1x_1+\beta_2x_2+\ldots+\beta_k x_k} \]
The logit function or the log-odds is therefore \[ P(Y=1) = \frac{1}{1 + e^-(\beta_0+\beta_1x_1+\beta_2x_2+\ldots+\beta_k x_k)} \]
Questions?