1
$\begingroup$

When dealing with non-binary discrete-choice outcomes, one common way of modeling such problems as a function of some covariates is through a multinomial logit/logistic model, in which there is one set of coefficients per class/choice, each producing a linear score for it, and the probability of a given observation belonging to each class is calculated as: $$ P(y = k | \mathbf{x}) = \frac{ \text{exp}( \mathbf{x} \mathbf{\beta}_k ) }{ \sum_{i=1}^n \text{exp}( \mathbf{x} \mathbf{\beta}_i ) } $$

Given this definition of $P(y = k)$, it would be my intuition that this model should be fit by maximizing the log-likelihood of the observed outcome for each row - i.e.: $$ \sum_{i=1}^m \text{log}( P(y=y_m | \mathbf{x}_m) ) $$

However, if I look at popular software for fitting such models such as GLMNET or scikit-learn, I see that they instead calculate their optimization target as a sum over all the possible values of $y$ - i.e.: $$ \sum_{i=1}^m ( \sum_{k=1}^K I(y_i = k) \times \mathbf{x} \mathbf{\beta}_k - \text{log}( \sum_{j} \text{exp}( \mathbf{x} \mathbf{\beta}_j ) ) ) $$

(where $I(.)$ is the indicator function taking a value of $1$ when the argument is true and zero otherwise)

My question is: why would calculation of the likelihood need to include all the possible values of the response variable if the probability for only the observed outcome of each row already incorporates the coefficients from all the choices?

References:

https://glmnet.stanford.edu/articles/glmnet.html#multinomial-regression-family-multinomial-

https://hastie.su.domains/Papers/multi_response.pdf

$\endgroup$
0

1 Answer 1

2
$\begingroup$

The expressions are equivalent. The indicator function sets to 0 all the summation terms that do not match the class label. Your expression could also be written as $$ (k-1)\times 0 + \sum_{i=1}^m \log( P(y=y_m | \mathbf{x}_m) ) $$ which can again be re-written as $$ \sum_{i=1}^m \sum_{j=1}^k I(y_m=j) \times \text{log}( P(y=j | \mathbf{x}_m) ) + (1 - I(y_m=j)) \times \text{log}(1 - P(y=j | \mathbf{x}_m) ). $$ because all of the $k-1$ terms that do not match class $j$ are 0, and all of those terms involve $\text{log}(1 - P(y=j | \mathbf{x}_m) .$

$\endgroup$
2
  • $\begingroup$ Thanks for pointing this out - I now realized that I transcribed the formula incorrectly and now edited the question copying it more accurately from glmnet's website. The formula there is actually a bit different though. $\endgroup$ Commented Jan 31, 2023 at 18:28
  • 1
    $\begingroup$ The revised question is just about how to manipulate logarithms. Write down $$ P(y = k | \mathbf{x}) = \frac{ \exp( \mathbf{x} \mathbf{\beta}_k ) }{ \sum_{i=1}^n \exp( \mathbf{x} \mathbf{\beta}_i ) } $$ and then write down $$\log P(y = k | \mathbf{x}).$$ $\endgroup$
    – Sycorax
    Commented Jan 31, 2023 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.