0

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)?

whuber
  • 281,159
  • 54
  • 637
  • 1,101
Phoebe
  • 31
  • 2
  • 5
    `rbinom` is your "noise" generator. The model is conditional on `X`, so adding noise to `Z` is not part of the model. – whuber Oct 12 '21 at 18:50
  • 1
    [Why do we model noise in linear regression but not logistic regression?](https://stats.stackexchange.com/q/481391/1352) approaches this question "from the other side" but may be helpful. – Stephan Kolassa Oct 12 '21 at 20:40

0 Answers0