Logistic Regression

Figure 4.2: Logistic function
Image fig_logit

There is a family of linear models, called generalized linear models (generalized linear model), that relate the dependent variable to the explanatory variables through a nonlinear function. Logistic regression belongs to this class of models in the special case where the variable $y$ is dichotomous, that is, it can take only the values $0$ or $1$. This type of problem is particularly important in classification.

For binary problems, the probabilities of success and failure can be defined as

\begin{displaymath}
\begin{array}{l}
P[Y=1\vert\mathbf{x}]=p(\mathbf{x}) \\
P[Y=0\vert\mathbf{x}]=1-p(\mathbf{x}) \\
\end{array}\end{displaymath} (4.126)

The response of a linear predictor of the form

\begin{displaymath}
y' = \boldsymbol\beta \cdot \mathbf{x} + \varepsilon
\end{displaymath} (4.127)

is not bounded between $0$ and $1$, so it is unsuitable for this purpose. The response of the linear predictor must therefore be related to the response of a function $g$ of the probability $p(\mathbf{x})$:
\begin{displaymath}
g(p(\mathbf{x}) ) = \boldsymbol\beta \cdot \mathbf{x} + b
\end{displaymath} (4.128)

where $g(p)$, the mean function, is a nonlinear function defined on $[0,1]$. $g(p)$ must be invertible, and its inverse $g^{-1}(y')$ is the link function.

A widely used model for the function $g(p)$ is the logit function, defined as:

\begin{displaymath}
logit(p) = \log \frac{p}{1-p} = \boldsymbol\beta \cdot \mathbf{x}
\end{displaymath} (4.129)

The function $\frac{p}{1-p}$, which represents the odds of success relative to failure, is called the odds; consequently, Equation (4.129) represents the logarithm of the probability of an event occurring relative to the probability of the same event not occurring (log-odds).

Its inverse exists and is given by

\begin{displaymath}
\E[Y\vert\mathbf{x}] = p( \mathbf{x} ) = \frac{ e^{\boldsymb...
...dot \mathbf{x}} }{ 1 + e^{\boldsymbol\beta \cdot \mathbf{x}} }
\end{displaymath} (4.130)

which is the logistic function.

In this case, the maximum likelihood method is not equivalent to the least-squares method. Assuming independent Bernoulli observations, the likelihood function is

\begin{displaymath}
\mathcal{L}(\boldsymbol\beta) = \prod_{i=1}^{n} p(\mathbf{x}_i)^{y_i} \left(1-p(\mathbf{x}_i)\right)^{1-y_i}.
\end{displaymath} (4.131)

which gives the log-likelihood function
\begin{displaymath}
\log \mathcal{L}(\boldsymbol\beta) = \sum_{i=1}^{n} y_i (\bo...
...log \left( 1 + e^{\boldsymbol\beta \cdot \mathbf{x}_i} \right)
\end{displaymath} (4.132)

Maximizing this function using iterative methods yields estimates of the parameters $\boldsymbol\beta$.

Paolo medici
2026-10-19