quality:correction, structural:expansion
Multinomial logistic regression: Many explanatory variables and many categories

In the above cases of two categories (binomial logistic regression), the categories were indexed by "0" and "1", and we had two probabilities: The probability that the outcome was in category 1 was given by p (x) {\displaystyle p({\boldsymbol {x}})} and the probability that the outcome was in category 0 was given by 1 − p (x) {\displaystyle 1-p({\boldsymbol {x}})}. The sum of these probabilities equals 1, which must be true, since "0" and "1" are the only possible categories in this setup.

In general, if we have M + 1 {\displaystyle M+1} explanatory variables (including x) and N + 1 {\displaystyle N+1} categories, we will need N + 1 {\displaystyle N+1} separate probabilities, one for each category, indexed by n, which describe the probability that the categorical outcome y will be in category y=n, conditional on the vector of covariates x. The sum of these probabilities over all categories must equal 1. Using the mathematically convenient base e, these probabilities are:

Each of the probabilities except p 0 (x) {\displaystyle p_{0}({\boldsymbol {x}})} will have their own set of regression coefficients β n {\displaystyle {\boldsymbol {\beta }}_{n}}. It can be seen that, as required, the sum of the p n (x) {\displaystyle p_{n}({\boldsymbol {x}})} over all categories n is 1. The selection of p 0 (x) {\displaystyle p_{0}({\boldsymbol {x}})} to be defined in terms of the other probabilities is artificial. Any of the probabilities could have been selected to be so defined. This special value of n is termed the "pivot index", and the log-odds (t) are expressed in terms of the pivot probability and are again expressed as a linear combination of the explanatory variables:

Note also that for the simple case of N = 1 {\displaystyle N=1}, the two-category case is recovered, with p (x) = p 1 (x) {\displaystyle p({\boldsymbol {x}})=p_{1}({\boldsymbol {x}})} and p 0 (x) = 1 − p 1 (x) {\displaystyle p_{0}({\boldsymbol {x}})=1-p_{1}({\boldsymbol {x}})}.

The log-likelihood that a particular set of K measurements or data points will be generated by the above probabilities can now be calculated. Indexing each measurement by k, let the k -th set of measured explanatory variables be denoted by x k {\displaystyle {\boldsymbol {x}}_{k}} and their categorical outcomes be denoted by y k {\displaystyle y_{k}} which can be equal to any integer in. The log-likelihood is then:

where Δ (n, y k) {\displaystyle \Delta (n,y_{k})} is an indicator function which equals 1 if y = n and zero otherwise. In the case of two explanatory variables, this indicator function was defined as y when n = 1 and 1-y when n = 0. This was convenient, but not necessary. Again, the optimum beta coefficients may be found by maximizing the log-likelihood function generally using numerical methods. A possible method of solution is to set the derivatives of the log-likelihood with respect to each beta coefficient equal to zero and solve for the beta coefficients:

where β n m {\displaystyle \beta _{nm}} is the m -th coefficient of the β n {\displaystyle {\boldsymbol {\beta }}_{n}} vector and x m k {\displaystyle x_{mk}} is the m -th explanatory variable of the k -th measurement. Once the beta coefficients have been estimated from the data, we will be able to estimate the probability that any subsequent set of explanatory variables will result in any of the possible outcome categories.