# Algorithm does not converge in R

I am doing a logistic regression in R, where I am modeling how potholes and weather correlate to accidents. When I run a logistic regression, I get the message "Algorithm does not converge"

The problem I think I have is that I have 24,000 accidents with only 350 potholes related to these accidents. Is this to small of a sample size?

The other possible issue I thought of, is that when I look at sample logistic regressions, the outcome is either zero or one, but the only outcome I have is the outcome of one, or accident in my case. I do not have any non accident data in my set, could this be what is causing the problem?

I will attach my current code and its output.

require(ggplot2)
require(sandwich)
require(msm)
## view the first few rows of the data
summary(mydata)
mylogit <- glm(Accident ~  Rain + Snow, data = mydata, family = "binomial")

Date Pothole Rain Snow Accident
1 1/1/2012       0    0    0        1
2 1/1/2012       0    0    0        1
3 1/1/2012       0    0    0        1
4 1/1/2012       0    0    0        1
5 1/1/2012       0    0    0        1
6 1/1/2012       0    0    0        1
> summary(mydata)
Date          Pothole            Rain              Snow            Accident
1/8/2014  :   87   Min.   :0.0000   Min.   :0.00000   Min.   : 0.0000   Min.   :1
1/30/2013 :   82   1st Qu.:0.0000   1st Qu.:0.00000   1st Qu.: 0.0000   1st Qu.:1
3/21/2013 :   77   Median :0.0000   Median :0.00000   Median : 0.0000   Median :1
12/21/2012:   76   Mean   :0.0173   Mean   :0.08077   Mean   : 0.1129   Mean   :1
3/10/2013 :   66   3rd Qu.:0.0000   3rd Qu.:0.00000   3rd Qu.: 0.0000   3rd Qu.:1
12/13/2013:   59   Max.   :8.0000   Max.   :3.32000   Max.   :11.1000   Max.   :1
(Other)   :23606
> mylogit <- glm(Accident ~  Rain + Snow, data = mydata, family = "binomial")
Warning message:
glm.fit: algorithm did not converge


## migrated from stackoverflow.comNov 8 '14 at 17:32

This question came from our site for professional and enthusiast programmers.

• If all your data has an accident, you cannot use a glm to predict an accident (because everything is always an accident in your data). But the question you are asking isn't really about programming, it is about statistical modeling, and as such it better belongs on Cross Validated instead. – MrFlick Nov 8 '14 at 1:01
• there is a large and somewhat difficult body of ecological literature about such "presence-only" data; typically people handle this by generating "pseudo-absences" in some reasonably sensible way, but it's a pretty big can of worms. – Ben Bolker Nov 8 '14 at 1:30
• This looks like a variant of Complete Separation as described in en.wikipedia.org/wiki/…. Because all your examples have outcome one you can predict them accurately by using a very large constant in the regression equation. But the larger the constant the better the fit, because the predicted probabilities get closer and closer to one, and no finite constant gives you the best fit, because you can always increase the goodness of fit by increasing it. – mcdowella Nov 8 '14 at 5:53