stylistic:tone, structural:summarization, information:highlighting, structural:scholar_edition, quality:corruption
Many explanatory variables, two categories

The above example of binary logistic regression on one explanatory variable can be generalized to binary logistic regression on any number of explanatory variables x, x,... and any number of categorical values y = 0, 1, 2, … {\displaystyle y=0,1,2,\dots }.

To begin with, we may consider a logistic model with M explanatory variables, x, x... x and, as in the example above, two categorical values (y = 0 and 1). For the simple binary logistic regression model, we assumed a linear relationship between the predictor variable and the log-odds (also called logit) of the event that y = 1 {\displaystyle y=1}. This linear relationship may be extended to the case of M explanatory variables:

where t is the log-odds and β i {\displaystyle \beta _{i}} are parameters of the model. An additional generalization has been introduced in which the base of the model (b) is not restricted to the Euler number e. In most applications, the base b {\displaystyle b} of the logarithm is usually taken to be e. However, in some cases it can be easier to communicate results by working in base 2 or base 10.

For a more compact notation, we will specify the explanatory variables and the β coefficients as (M + 1) {\displaystyle (M+1)} -dimensional vectors:

with an added explanatory variable x =1. The logit may now be written as:

Solving for the probability p that y = 1 {\displaystyle y=1} yields:

where S b {\displaystyle S_{b}} is the sigmoid function with base b {\displaystyle b}. The above formula shows that once the β m {\displaystyle \beta _{m}} are fixed, we can easily compute either the log-odds that y = 1 {\displaystyle y=1} for a given observation, or the probability that y = 1 {\displaystyle y=1} for a given observation. The main use-case of a logistic model is to be given an observation x {\displaystyle {\boldsymbol {x}}}, and estimate the probability p (x) {\displaystyle p({\boldsymbol {x}})} that y = 1 {\displaystyle y=1}. The optimum beta coefficients may again be found by maximizing the log-likelihood. For K measurements, defining x k {\displaystyle {\boldsymbol {x}}_{k}} as the explanatory vector of the k -th measurement, and y k {\displaystyle y_{k}} as the categorical outcome of that measurement, the log likelihood may be written in a form very similar to the simple M = 1 {\displaystyle M=1} case above:

As in the simple example above, finding the optimum β parameters will require numerical methods. One useful technique is to equate the derivatives of the log likelihood with respect to each of the β parameters to zero yielding a set of equations which will hold at the maximum of the log likelihood:

where x is the value of the x explanatory variable from the k-th measurement.

Consider an example with M = 2 {\displaystyle M=2} explanatory variables, b = 10 {\displaystyle b=10}, and coefficients β 0 = − 3 {\displaystyle \beta _{0}=-3}, β 1 = 1 {\displaystyle \beta _{1}=1}, and β 2 = 2 {\displaystyle \beta _{2}=2} which have been determined by the above method. To be concrete, the model is:

where p is the probability of the event that y = 1 {\displaystyle y=1}. This can be interpreted as follows: