2023-10-13 13:19:12 +02:00
\chapter { Generalized Linear Model}
2023-09-22 17:32:56 +02:00
2023-11-10 13:39:13 +01:00
\begin { example}
\begin { description}
\item [Ex. 1 - Credit Carb Default]
Let $ Y _ i $ be a boolean random variable following a Bernoulli distribution.
\item [Ex. 2 - Horseshoe Crabs]
Let $ Y _ i $ , be the number of satellites males.
$ Y _ i $ can be described as following a Poisson distribution.
\end { description}
\end { example}
\begin { remark}
A Poisson distribution can be viewed as an approximation of binomial distribution when $ n $ is high and $ p $ low.
\end { remark}
We will consider the following relation:
\[
\EE (Y_ i) = g^ { -1} X_ i \beta ,
\]
equivalently:
\[
g(\EE (Y_ i)) = X_ i \beta .
\]
\begin { itemize}
\item $ \beta $ is estimated by the maximum likelihood;
\item $ g $ is called the link function.
\end { itemize}
\begin { remark}
In standard linear model, the OLS estimator is the estimator of maximum of likelihood.
\end { remark}
2023-10-13 13:19:12 +02:00
\section { Logistic Regression}
2023-09-22 17:32:56 +02:00
2023-11-10 13:39:13 +01:00
\begin { align*}
& \log (\frac { \Pi } { 1 - \Pi } ) & = \X \beta \\
\Leftrightarrow & e^ { \ln \frac { \Pi } { 1 - \Pi } } = e^ { \X \beta } \\
\Leftrightarrow & \frac { \Pi } { 1 - \Pi } = e^ { \X \beta } \\
\Leftrightarrow & \Pi = (1 - \Pi ) e^ { \X \beta } \\
\Leftrightarrow & \Pi = e^ { \X \beta } - \Pi e^ { \X \beta } \\
\Leftrightarrow & \Pi + \Pi e^ { \X \beta } = e^ { \X \beta } \\
\Leftrightarrow & \Pi (1 - e^ { \X \beta } ) = e^ { \X \beta } \\
\Leftrightarrow & \Pi = \frac { e^ { \X \beta } } { 1 + e^ { \X \beta } }
\end { align*}
\section { Maximum Likelihood estimator}
log-likelihood: the probability to observe what we observe.
Estimate $ \beta $ by $ \hat { \beta } $ such that $ \forall \beta \in \RR [ p + 1 ] $ :
\[
L_ n (\hat { \beta } ) \geq L_ n (\beta )
\]
These estimators are consistent, but not necessarily unbiased.
\section { Test for each single coordinate}
\begin { example} [Payment Default]
Let $ Y _ i $ be the default value for individual $ i $ .
\[
\log (\frac { \Pi (X)} { 1 - \Pi (X)} ) = \beta _ 0 + \beta _ 1 \text { student} + \beta _ 2 \text { balance} + \beta _ 3 \text { income}
\]
In this example, only $ \beta _ 0 $ and $ \beta _ 2 $ are significantly different from 0.
\end { example}
\begin { remark}
We do not add $ \varepsilon _ i $ , because $ \log ( \frac { \Pi ( X ) } { 1 - \Pi ( X ) } ) $ corresponds to the expectation.
\end { remark}
\subsection { Comparison of nested models}
To test $ H _ 0 : \: \beta _ 0 = \ldots = \beta _ p = 0 $ , we use the likelihood ratio test:
\[
T_ n = -2 \log (\mathcal { L} ^ { \texttt { null} } ) + 2 \log (\mathcal { L} (\hat { \beta } )) \underset { H_ 0} { \overunderset { \mathcal { L} } { n \to \infty } { \longrightarrow } } \chi ^ 2(p).
\]
\begin { remark} [Family of Tests]
\begin { itemize}
\item Comparison of estimated values and values under the null hypothesis;
\item Likelihood ratio test;
\item Based on the slope on the derivative.
\end { itemize}
\end { remark}
\section { Relative risk}
$ RR _ i $ is the probably to have the disease, conditional to the predictor $ X _ { i 1 } $ over the probability of having the disease, conditional to the predictor $ X _ { i 2 } $ .
\[
RR(j) = \frac { \Prob (Y_ { i_ 1} = 1 \: | \: X_ { i_ 1} )} { \Prob (Y_ { i_ 2} = 1) \: | \: X_ { i_ 2} } = \frac { \EE (Y_ { i_ 1} )} { \EE (Y_ { i_ 2} )} .
\]
$ \pi ( X _ i ) $ is the probability of having the disease, according to $ X _ i $ .
The relative risk can be written as\dots
\section { Odds}
Quantity providing a measure of the likelihood of a particular outcome:
\[
odd = \frac { \pi (X_ i)} { 1 - \pi (X_ i)}
\]
\[
odds = \exp (X_ i \beta )
\]
odds is the ratio of people having the disease, if Y represent the disease, over the people not having the disease.
\section { Odds Ratio}
\begin { align*}
OR(j) =\frac { odds(X_ { i_ 1} )} { odds(X_ { i_ 2} )} & = \frac { \frac { \pi { X_ { i_ 1} } } { 1 - \pi (X_ { i_ 1} )} } { \frac { \pi { X_ { i_ 2} } } { 1 - \pi (X_ { i_ 2} )} }
\end { align*}
The OR can be written as:
\[
OR(j) = \exp (\beta _ j)
\]
\begin { exercise}
Show that $ OR ( j ) = \exp ( \beta _ j ) $ .
\end { exercise}
\begin { align*}
OR(j) & = \frac { odds(X_ { i_ 1} )} { odds(X_ { i_ 2} )} \\
& = \frac { \exp (X_ { i_ 1} \beta )} { \exp (X_ { i_ 2} \beta )} \\
\end { align*}
\[
\log \left (
\frac { \Prob (Y=1 \: |\: X_ { i_ 1} )} { 1 - \Prob (Y=1 \: |\: X_ { i_ 1} )} \right )
= \beta _ 0 + \beta _ 1 X_ 1^ { (1)} + \beta _ 2 X_ 2^ { (1)} + \ldots + \beta _ p X_ p^ { (1)}
\]
Similarly
\[
\log \left (
\frac { \Prob (Y=1 \: |\: X_ { i_ 2} )} { 1 - \Prob (Y=1 \: |\: X_ { i_ 2} )} \right )
= \beta _ 0 + \beta _ 1 X_ 1^ { (2)} + \beta _ 2 X_ 2^ { (2)} + \ldots + \beta _ p X_ p^ { (2)}
\]
We substract both equations:
\begin { align*}
& \log \left (
\frac { \Prob (Y=1 \: |\: X_ { i_ 1} )} { 1 - \Prob (Y=1 \: |\: X_ { i_ 1} )} \right ) - \log \left (\frac { \Prob (Y=1 \: |\: X_ { i_ 2} )} { 1 - \Prob (Y=1 \: |\: X_ { i_ 2} )} \right ) \\
& = \beta _ 0 + \beta _ 1 X_ 1^ { (1)} + \beta _ 2 X_ 2^ { (1)} + \ldots + \beta _ p X_ p^ { (1)} - \beta _ 0 + \beta _ 1 X_ 1^ { (2)} + \beta _ 2 X_ 2^ { (2)} + \ldots + \beta _ p X_ p^ { (2)} \\
& = \log OR(j) \\
& = \cancel { (\beta _ 0 - \beta _ 0)} + \beta _ 1 \cancel { (X_ 1^ { (1)} - X_ 1^ { (2)} )} + \beta _ 2 \cancel { (X_ 2^ { (1)} - X_ 2^ { (2)} )} + \ldots + \beta _ j \cancelto { 1} { (X_ j^ { (1)} - X_ j^ { (2)} )} + \ldots + \beta _ p \cancel { (X_ p^ { (1)} - X_ p^ { (2)} )} \\
& \Leftrightarrow \log (OR_ j) = \beta _ j \\
& \Leftrightarrow OR(j) = \exp (\beta _ j)
\end { align*}
OR is not equal to RR, except in the particular case of probability (?)
If OR is significantly different from 1, the $ \exp ( \beta _ j ) $ is significantly different from 1, thus $ \beta _ j $ is significantly different from 0.
If we have more than two classes, we do not know what means $ X _ { i _ 1 } - X _ { i _ 2 } = 0 $ . We will have to take a reference class, and compare successively each class with the reference class.
$ \hat { \pi } ( X _ { + } ) = \hat { \Prob ( X = 1 \: | X _ { i 1 } ) } $ for a new individual.
\section { Poisson model}
Let $ Y _ { i } \sim \mathcal { P } ( \lambda _ { i } ) $ , corresponding to a counting.
\begin { align*}
\EE (Y_ { i} ) & = g^ { -1} (X_ { i} \beta ) \\
\Leftrightarrow g(\EE (Y_ { i} )) = X_ { i} \beta
\end { align*}
where $ g ( x ) = \ln ( x ) $ , and $ g ^ { - 1 } ( x ) = e ^ { x } $ .
\[
\lambda _ { i} = \EE (Y_ { i} ) = \Var (Y_ { i} )
\]