Why does the glm function converge and not give an error when all y's are equal to the same value? I need to fit a univariate logistic model with few observations (between 10 and 20).
In some cases, y is equal to the same value (example 1) for all observations.
Theoretically, the model should not converge. But, when I use the glm function in R it doesn't show me an error or a warning!
Here is an example of code that I tested:
x=sample(c(0,1),20,replace = TRUE)
y=rep(1,20)
summary(glm(y~x, family = binomial))

Call:
glm(formula = y ~ x, family = binomial)

Deviance Residuals: 
      Min         1Q     Median         3Q        Max  
3.971e-06  3.971e-06  3.971e-06  3.971e-06  3.971e-06  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)  2.557e+01  7.200e+04       0        1
x           -4.549e-10  9.708e+04       0        1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 0.000e+00  on 19  degrees of freedom
Residual deviance: 3.154e-10  on 18  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 24

What do I need to change so that the glm function gives me an error instead of a result?
I don't understand how the model can converge!
Contrary to this question I getting "algorithm did not converge"
I don't get a warning with my model.
I find it strange that R does not show me an error while with another software (SAS) I get an error and the program stops!
Note also that even with 3 observations the glm function converge and gives results without displaying a warning !
y=rep(1,3)
x=sample(c(0,1),3,replace = TRUE)
summary(glm(y~x, family = binomial))

Call:
glm(formula = y ~ x, family = binomial)

Deviance Residuals: 
        1          2          3  
1.079e-05  1.079e-05  1.079e-05  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)  2.357e+01  7.946e+04       0        1
x           -2.545e-08  9.732e+04       0        1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 0.0000e+00  on 2  degrees of freedom
Residual deviance: 3.4957e-10  on 1  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 22

I also want to specify that when we increase the number of observations y>= 101, I get this warning :
x=sample(c(0,1),101,replace = TRUE)
y=rep(1,101)

Warning message:
glm.fit: the algorithm did not converge

Whereas with less observations I don't get this warning
I'd be grateful for your help.

In a regression framework, if the dependent variable shows no variation (say it is 5 for each observation), the regression produces results, it sets the constant to match the dependent variable (in this case 5), and the coefficients on other independent variables (if any) to 0. This happens in the glm case too. The high value of the constant is there so that the resulting predicted value is 1 (to match the dependent).
It is not an error that the dependent variable shows no variation. Estimation routines work. The issue is not with the estimation techniques and with the algorithms. The real question is what do you want to explain if there is no variation to explain?
I hope it helps
