I would like to simulate data for logistic regression model as follows,
X = rnorm(1000)
Z = 1 + 2*X
pr = 1/(1 + exp(-Z))
Y = rbinom(1000, 1, pr)
glm(Y ~ X, family="binomial")
I am just wondering, in the step of generating "pr", do I need to add a noise to Z? It seems there is no noise added to Y to fit a logistic regression model. In other words, should I write Z = 1 + 2X or Z = 1 + 2X + rnorm(1000)?
rbinomis your "noise" generator. The model is conditional onX, so adding noise toZis not part of the model. – whuber Oct 12 '21 at 18:50