When is logistic regression solved in closed form? - Cross Validated most recent 30 from stats.stackexchange.com 2019-10-22T01:24:30Z https://stats.stackexchange.com/feeds/question/949 https://creativecommons.org/licenses/by-sa/4.0/rdf https://stats.stackexchange.com/q/949 31 When is logistic regression solved in closed form? Yaroslav Bulatov https://stats.stackexchange.com/users/511 2010-07-28T21:59:02Z 2013-07-04T18:23:03Z <p>Take $x \in \{0,1\}^d$ and $y \in \{0,1\}$ and suppose we model the task of predicting y given x using logistic regression. When can logistic regression coefficients be written in closed form?</p> <p>One example is when we use a saturated model.</p> <p>That is, define $P(y|x) \propto \exp(\sum_i w_i f_i(x_i))$, where $i$ indexes sets in the power-set of $\{x_1,\ldots,x_d\}$, and $f_i$ returns 1 if all variables in the $i$'th set are 1, and 0 otherwise. Then you can express each $w_i$ in this logistic regression model as a logarithm of a rational function of statistics of the data. </p> <p>Are there other interesting examples when closed form exists?</p> https://stats.stackexchange.com/questions/949/-/6701#6701 8 Answer by cardinal for When is logistic regression solved in closed form? cardinal https://stats.stackexchange.com/users/2970 2011-01-29T22:03:58Z 2012-09-20T12:47:09Z <p><em>This post was originally intended as a long comment rather than a complete answer to the question at hand.</em></p> <p>From the question, it's a little unclear if the interest lies only in the binary case or, perhaps, in more general cases where they may be continuous or take on other discrete values.</p> <p>One example that doesn't quite answer the question, but is related, and which I like, deals with item-preference rankings obtained via paired comparisons. The Bradley&ndash;Terry model can be expressed as a logistic regression where $$\mathrm{logit}( \Pr(Y_{ij} = 1) ) = \alpha_i - \alpha_j ,$$ and $\alpha_i$ is an "affinity", "popularity", or "strength" parameter of item $i$ with $Y_{ij} = 1$ indicating item $i$ was preferred over item $j$ in a paired comparison.</p> <p>If a full round-robin of comparisons is performed (i.e., a pairwise preference is recorded for each unordered $(i,j)$ pair), then it turns out that the rank order of the MLEs $\hat{\alpha}_i$ correspond to the rank order of $S_i = \sum_{j \neq i} Y_{ij}$, the sum total of times each object was preferred over another.</p> <p>To interpret this, imagine a full round-robin tournament in your favorite competitive sport. Then, this result says that the Bradley&ndash;Terry model ranks the players/teams according to their winning percentage. Whether this is an encouraging or disappointing result depends on your point of view, I suppose.</p> <p><strong>NB</strong> This rank-ordering result does not hold, in general, when a full round-robin is not played.</p> https://stats.stackexchange.com/questions/949/-/37640#37640 33 Answer by StasK for When is logistic regression solved in closed form? StasK https://stats.stackexchange.com/users/5739 2012-09-20T00:13:38Z 2013-07-04T18:23:03Z <p>As kjetil b halvorsen pointed out, it is, in its own way, a miracle that the linear regression admits an analytical solution. And this is so only by virtue of linearity of the problem (with respect to the parameters). In OLS, you have $$\sum_i (y_i - x_i' \beta)^2 \to \min_\beta,$$ which has the first order conditions $$-2 \sum_i (y_i - x_i'\beta) x_i = 0$$ For a problem with $p$ variables (including constant, if needed&mdash;there are some regression through the origin problems, too), this is a system with $p$ equations and $p$ unknowns. Most importantly, it is a linear system, so you can find a solution using the standard <a href="http://en.wikipedia.org/wiki/System_of_linear_equations">linear algebra theory and practice</a>. This system will have a solution with probability 1 unless you have perfectly collinear variables.</p> <p>Now, with logistic regression, things aren't that easy anymore. Writing down the log-likelihood function, $$l(y;x,\beta) = \sum_i y_i \ln p_i + (1-y_i) \ln(1-p_i), \quad p_i = (1+\exp(-\theta_i))^{-1}, \quad \theta_i = x_i' \beta,$$ and taking its derivative to find the MLE, we get $$\frac{\partial l}{\partial \beta'} = \sum_i \frac{{\rm d}p_i}{{\rm d}\theta}\Bigl( \frac{y_i}{p_i} - \frac{1-y_i}{1-p_i} \Bigr)x_i = \sum_i \Bigl[y_i-\frac1{1+\exp(x_i'\beta)}\Bigr]x_i$$ The parameters $\beta$ enter this in a very nonlinear way: for each $i$, there's a nonlinear function, and they are added together. There is no analytical solution (except probably in a trivial situation with two observations, or something like that), and you have to use <a href="http://rads.stackoverflow.com/amzn/click/0898716616">nonlinear optimization methods</a> to find the estimates $\hat\beta$.</p> <p>A somewhat deeper look into the problem (taking the second derivative) reveals that this is a convex optimization problem of finding a maximum of a concave function (a glorified multivariate parabola), so either one exists, and any reasonable algorithm should be finding it rather quickly, or things blow off to infinity. The latter does happen to logistic regression when ${\rm Prob}[Y_i=1|x_i'\beta &gt; c] = 1$ for some $c$, i.e., you have a perfect prediction. This is a rather unpleasant artifact: you would think that when you have a perfect prediction, the model works perfectly, but curiously enough, it is the other way round.</p>