From Binary Outcomes to a Likelihood
In exposure-response analysis, an outcome may record whether a specified event occurred—for example, whether a participant experienced a binary pharmacodynamic response during a defined assessment period. Once the exposure values are treated as known predictors, logistic regression describes how the event probability varies with exposure. The likelihood makes this model useful for estimation: it quantifies how compatible each candidate set of coefficients is with the observed outcomes.
For observation \(i\), let \(Y_i\) equal 1 if the event occurs and 0 otherwise, and let \(x_i\) be its exposure value. Consider the intercept-and-slope model \(\operatorname{logit}(p_i)=\beta_0+\beta_1x_i\), where \(p_i=P(Y_i=1\mid x_i)\). Here \(\operatorname{logit}(p)=\log\{p/(1-p)\}\), so \(p_i=1/\{1+\exp[-(\beta_0+\beta_1x_i)]\}\). The slope \(\beta_1\) describes the change in log odds per unit of exposure.
The likelihood is the joint probability of the observed outcomes, viewed as a function of the unknown coefficients. Independence means that this joint probability is a product of individual Bernoulli probabilities. A Bernoulli observation has probability \(p_i\) when \(Y_i=1\), and \(1-p_i\) when \(Y_i=0\). Both cases are represented by \(p_i^{Y_i}(1-p_i)^{1-Y_i}\).
Here \(\boldsymbol{\beta}=(\beta_0,\beta_1)^\mathsf{T}\), \(L\) is the likelihood, and \(\ell=\log L\) is the log-likelihood. Maximizing either gives the same coefficient estimates because the logarithm is strictly increasing. The log-likelihood is preferred for calculation because it converts a product into a sum.
Deriving the Score and Observed Information
Write \(\eta_i=\beta_0+\beta_1x_i\). Since \(\log(p_i)=\eta_i-\log(1+\exp(\eta_i))\) and \(\log(1-p_i)=-\log(1+\exp(\eta_i))\), the log-likelihood can also be written as a sum of \(Y_i\eta_i-\log(1+\exp(\eta_i))\). Differentiating this expression gives the score, the vector of first derivatives of the log-likelihood.
In the general linear-predictor notation, \(x_{ij}\) is predictor \(j\) for observation \(i\), with \(x_{i0}=1\) for the intercept. The derivative follows because \(\partial\eta_i/\partial\beta_j=x_{ij}\) and \(\partial\log(1+\exp(\eta_i))/\partial\eta_i=p_i\). Thus each observation contributes its residual \(Y_i-p_i\), weighted by its predictor values.
The matrix \(\mathbf I_{\mathrm{obs}}\) is the observed information: the negative Hessian of the log-likelihood at the parameter value under consideration. To obtain it, differentiate the score contribution \(x_{ij}(Y_i-p_i)\). Since \(\partial p_i/\partial\beta_k=p_i(1-p_i)x_{ik}\), the second derivative for coefficients \(j,k\) is \(-\sum_i x_{ij}x_{ik}p_i(1-p_i)\). This establishes the matrix expression above. Under this Bernoulli-logit model, the observed information has the same form as the expected Fisher information conditional on the predictors.
The score equations usually have no closed-form solution when exposure is continuous. Numerical optimization finds the coefficient values where the score is zero. A Newton step from a current value \(\boldsymbol{\beta}\) is \(\boldsymbol{\beta}_{\mathrm{new}}=\boldsymbol{\beta}+\mathbf I_{\mathrm{obs}}^{-1}\mathbf U\), when the information is invertible. The update moves uphill locally; software may use step-size control if a full step does not improve the log-likelihood.
Worked Example: Evaluating the Likelihood and Score
Consider four hypothetical independent outcomes at exposure values \(x=(0,1,2,3)\), with observed responses \(y=(0,1,0,1)\). Evaluate the likelihood, log-likelihood, and score at the trial coefficients \(\beta_0=-1\) and \(\beta_1=0.5\). These are trial values, not asserted maximum-likelihood estimates.
The linear predictors are \((-1,-0.5,0,0.5)\), giving fitted probabilities approximately \((0.2689,0.3775,0.5000,0.6225)\). For the observed response pattern, the likelihood is the product of \(1-p_i,p_i,1-p_i,p_i\), respectively:
The score residuals \(y_i-p_i\) are approximately \((-0.2689,0.6225,-0.5000,0.3775)\). The intercept score is their sum, and the exposure score weights each residual by its \(x_i\):
The exposure component is \(0.622459-1.000000+3(0.377541)\approx0.755081\), which rounds to 0.7551. Because the score is not zero, these trial coefficients are not at a stationary point of the log-likelihood. The positive exposure component indicates that, locally, increasing \(\beta_1\) while holding the other coefficient fixed increases the log-likelihood.
Estimating an Exposure Effect From Grouped Data
When several independent Bernoulli observations share the same exposure, their outcomes can be summarized by the number of events in that group. The grouped likelihood is binomial: for \(r_g\) events among \(n_g\) observations at exposure \(x_g\), its probability is \({n_g\choose r_g}p_g^{r_g}(1-p_g)^{n_g-r_g}\). The binomial coefficient is constant with respect to the regression coefficients, so it does not change the score or the maximum-likelihood estimates.
Worked Example: A Two-Level Exposure Effect
Suppose a hypothetical study observes 2 events among 10 participants at \(x=0\), and 6 events among 10 participants at \(x=1\). Assume independent Bernoulli outcomes and the logit model \(\operatorname{logit}(p_g)=\beta_0+\beta_1x_g\). Because each exposure group has its own fitted probability under this two-parameter model, the maximizing fitted probabilities are \(p_0=2/10=0.2\) and \(p_1=6/10=0.6\).
For a group with \(r\) events among \(n\) observations, the log-likelihood, apart from its constant binomial coefficient, is \(r\log(p)+(n-r)\log(1-p)\). Its derivative with respect to \(p\) is \(r/p-(n-r)/(1-p)\), which is zero at \(p=r/n\). Thus the group proportions maximize their respective likelihood contributions. Converting these fitted probabilities to logits gives
The score is zero: at each exposure group, \(r_g-n_gp_g=0\), so both the intercept score \(\sum_g(r_g-n_gp_g)\) and slope score \(\sum_gx_g(r_g-n_gp_g)\) vanish. The slope is in log-odds units per one exposure unit; its exponent, \(\exp(1.7918)\approx6.000\), is the model-implied multiplicative change in the odds for a one-unit exposure increase.
At the fitted values, the observed information is \(\mathbf X^\mathsf{T}\mathbf W\mathbf X\), where group \(g\) contributes \(n_gp_g(1-p_g)\begin{pmatrix}1&x_g\\x_g&x_g^2\end{pmatrix}\). The \(x=0\) group contributes \(10(0.2)(0.8)=1.6\) to the intercept-intercept entry; the \(x=1\) group contributes \(10(0.6)(0.4)=2.4\) to each entry. Therefore
Its determinant is \(4.0(2.4)-2.4^2=3.84\), and the slope variance from the inverse information is \(4.0/3.84\approx1.0417\). The corresponding model-based standard error is approximately \(\sqrt{1.0417}=1.021\) log-odds units per exposure unit. This is a local, large-sample approximation; with only 20 observations, it should not be treated as a guarantee of precise inference.
Numerical Optimization and Diagnostics
The Newton update uses both the score and curvature. For a two-coefficient model, its matrix calculation can be checked directly, which helps distinguish a numerical problem from a data or model problem.
Worked Example: One Newton Step
Use again the hypothetical data \(x=(0,1,2,3)\), \(y=(0,1,0,1)\), and start at \(\boldsymbol{\beta}=(0,0)^\mathsf{T}\). All fitted probabilities are \(0.5\). The score is \(\sum_i(y_i-0.5)=0\) for the intercept and \(\sum_i x_i(y_i-0.5)=1.0\) for exposure. Since each weight \(p_i(1-p_i)=0.25\), the observed information is
The determinant of the information matrix is \(1(3.5)-1.5^2=1.25\), so its inverse is \(\begin{pmatrix}2.8&-1.2\\-1.2&0.8\end{pmatrix}\). The Newton step is therefore
This is one update, not necessarily the final estimate. An optimizer continues updating until the score is sufficiently close to zero and the log-likelihood and coefficients have stabilized. It should also verify that the information matrix is well-conditioned enough to solve the update reliably.
Useful checks include confirming that the fitted probabilities lie between 0 and 1, the likelihood is finite, and the score is near zero at the reported estimate. A singular or nearly singular information matrix can indicate that predictors are redundant or that the available exposure values do not support separate coefficient estimates. Extremely large coefficient estimates or unstable iterations can also occur when the outcome pattern nearly determines the response from the predictors; such cases require special scrutiny rather than blind trust in a routine optimizer.
A common failure is to treat \(Y_i-p_i\) as if it were the score for every coefficient. It is only the intercept contribution; the exposure coefficient's score contribution is \(x_i(Y_i-p_i)\). Omitting the predictor weight gives the wrong estimating equation and can falsely suggest that a fitted model is optimal. Another error is to use \(\mathbf X^\mathsf{T}\mathbf W\mathbf X\) as the score. It is the negative second derivative, not the first derivative, and belongs in the curvature-based update and approximate variance calculation.
The likelihood approach differs from least squares on the binary outcomes: least squares does not enforce probabilities between 0 and 1 and does not use the Bernoulli sampling distribution. Logistic maximum likelihood instead derives both estimation and curvature from the specified outcome probabilities. Its standard errors rely on an adequate model and a suitable large-sample approximation; dependence, misspecification, weak exposure information, and sparse outcomes can undermine those approximations. This derivation concerns a linear exposure effect on the logit scale; more flexible exposure functions require defining a different predictor.
Check Your Understanding
Use the model and assumptions defined above. Solutions follow each question so that the score and information calculations can be checked.
- For one observation with \(Y_i=1\), write its likelihood contribution and log-likelihood contribution.
- At \(x=2\), \(Y=1\), and \(p=0.7\), what are this observation's contributions to the intercept and exposure scores?
- Why does the binomial coefficient in a grouped likelihood not change the coefficient estimates?
- For a single predictor \(x_i=1\), \(p_i=0.4\), calculate its contribution to the observed information matrix.
- What should be checked if an optimizer reports estimates but the score is not close to zero?
Solutions. (1) The likelihood contribution is \(p_i\), and its log is \(\log(p_i)\), because the observed value is 1. (2) The residual is \(1-0.7=0.3\). The intercept score contribution is 0.3 and the exposure score contribution is \(2(0.3)=0.6\). (3) The binomial coefficient is constant in the model coefficients, so adding its logarithm changes the log-likelihood value but not its derivatives or maximizing coefficients. (4) The information weight is \(p_i(1-p_i)=0.4(0.6)=0.24\); with predictor vector \((1,1)^\mathsf{T}\), its contribution is \(0.24\begin{pmatrix}1&1\\1&1\end{pmatrix}\). (5) Check convergence, the score calculation, the predictor coding and rank, and whether the information matrix is numerically stable; a reported optimizer status alone does not establish that a valid maximum was found.