Logistic Regression is a statistical method for analyzing a dataset in which there are one or more independent variables that determine an outcome. The outcome is measured with a dichotomous variable (in which there are only two possible outcomes).
Here's a more detailed look at the math behind Logistic Regression:
Model:
Logistic regression models the probability that an observation is in the default class (Y=1) given the values of X (independent variables). Instead of fitting a straight line or hyperplane, logistic regression uses the logistic function to squeeze the output of a linear equation between 0 and 1. The logistic function ( \sigma(t) ), defined as:
[ \sigma(t) = \frac{1}{1 + e^{-t}} ]
where ( t ) is the linear combination of the independent variables X:
[ t = b_0 + b_1x_1 + b_2x_2 + \cdots + b_nx_n ]
In logistic regression, ( t ) is often referred to as the logit.
Probabilities and Odds:
The probability of the default class (Y=1) can be written as:
[ P(Y=1) = \frac{e^t}{1 + e^t} = \sigma(t) ]
The probability of the opposite class (Y=0) is:
[ P(Y=0) = 1 - P(Y=1) = \frac{1}{1 + e^t} ]
The odds of the default class are the ratio of the probability of default to the probability of non-default:
[ \text{odds} = \frac{P(Y=1)}{P(Y=0)} = e^t ]
Taking the natural log of both sides converts the odds to log-odds or logit:
[ \log\left(\frac{P(Y=1)}{P(Y=0)}\right) = t ]
Estimation (Parameter Fitting):
The coefficients ( b_0, b_1, \cdots, b_n ) are unknown and have to be estimated based on the available data. The estimation is typically done through Maximum Likelihood Estimation (MLE).
The likelihood function ( L ) for a set of parameters ( \mathbf{b} = (b_0, b_1, \cdots, b_n) ) given a dataset is the product of the probabilities for each observation:
[ L(\mathbf{b}) = \prod_{i=1}^{n} P(Y_i)^{Y_i} \left( 1 - P(Y_i) \right)^{1 - Y_i} ]
The log-likelihood ( \ell ) is:
[ \ell(\mathbf{b}) = \sum_{i=1}^{n} \left[ Y_i \cdot \log(P(Y_i)) + (1 - Y_i) \cdot \log(1 - P(Y_i)) \right] ]
Maximizing the log-likelihood gives us the MLEs of the coefficients. This is typically done through iterative optimization algorithms like gradient descent, Newton-Raphson, or quasi-Newton methods like BFGS.
Interpretation:
The coefficient ( b_j ) represents the change in the log-odds of the outcome for a one-unit change in the j-th independent variable, holding the other variables at a constant level. In other words, for each one-unit change in ( x_j ), the log odds of the dependent variable ( Y=1 ) change by ( b_j ). If ( b_j > 0 ), a one-unit change in ( x_j ) increases the log odds (and thus probability) of ( Y=1 ), and if ( b_j < 0 ), it decreases the log odds (and thus probability) of ( Y=1 ).