# [R] warnings associated with logistic regression

Thomas Lumley thomas at biostat.washington.edu
Tue Jul 11 18:41:51 CEST 2000

```On 11 Jul 2000, Allan Strand wrote:

> Hi all,
>
> This is as much as statistical/estimation question as an R-specific
> one, but here goes.
>
> I am trying to use logistic regression to predict suitability of
> habitats for certain plant species.  The response variable is a binary
> one that indicates whether a particular species is found at a site on
> the landscape.  The independent variables represent physical
> characteristics of the landscape derived from a GIS.  A significant
> proportion of the time I get the following warning messages from
> glm():
>
> > lr <- glm(known.v1~elevation+aspect+slope+energy15+energy166+aspect+accum+streams.buffered,family=binomial,data=siteframe)
> Warning messages:
> 1: Algorithm did not converge in: (if (is.empty.model(mt)) glm.fit.null else glm.fit)(x = X, y = Y,
> 2: fitted probabilities numerically 0 or 1 occurred in: (if (is.empty.model(mt)) glm.fit.null else glm.fit)(x = X, y = Y,
>
> Now I can get the algorithm to converge (or at least not produce the
> warning) by increasing the number of iterations, but that does not
> affect the second warning.

Well, that's what you'd expect.  The warning says that for certain
combinations of predictors the fitted response is equal to 0 or 1.  This
also means that the maximum of the likelihood is at infinity for some
coefficients.

This potentially causes numerical problems, at least in that R won't
report infinite coefficients.  It also causes statistical problems,
because the Wald p-values reported are not useful for very large
coefficients.

Sometimes this happens when you try to fit too many parameters, in which
case you may be able to fix it.  It can also happen when the coefficient
in question really is large and happens by chance to give perfect
predictions. A third possibility is that the probability really is zero
(eg above the treeline you really don't have any trees), in which case you
don't want a logistic regression model.

-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```