I used the code below to create the random variable x1 and binary variable y, and fit the regression with y and x1. My questions are:
- Why regression coefficient estimates are not close to 2 and 10 (the values I setup)?
- Why the warnning "did not converge"?
Thank you very much in advance for any thoughts!
n=1000
x1=rnorm(n)
xBeta=2+10*x1
p=1/(1+exp(-xBeta))
y=(p > 0.5)+0
dat = data.frame(y=y,x1=x1)
model <- glm(y ~ x1,family=binomial(link='logit'),data=dat)
summary(model)
Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: fitted probabilities numerically 0 or 1 occurred
Call:
glm(formula = y ~ x1, family = binomial(link = "logit"), data = dat)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1209.197686004 11464.422053391 0.10547 0.91600
x1 5992.507564124 56805.078196891 0.10549 0.91599
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 1.3698653260741e+03 on 999 degrees of freedom
Residual deviance: 6.2933474676058e-05 on 998 degrees of freedom
AIC: 4.0000629334747
Number of Fisher Scoring iterations: 25
Rcode to simulate logistic regression data in several threads, including https://stats.stackexchange.com/a/69873/919, https://stats.stackexchange.com/a/525877/919, https://stats.stackexchange.com/a/260977/919, https://stats.stackexchange.com/a/449216/919, etc. So have many others: see this site search. – whuber Sep 29 '22 at 16:25