How do you solve the following problem?
A Simulation Study (Probit Regression).
Assume $y|x\sim {\rm Binary}(p)$, where $p= E(y|x)$, and $Φ^{-1}(\pi)=-1+5.1x_{1i}-0.3x_{2i}$ Generate data with $x_{1i}\sim{\rm Unif}(0,1)$, $x_{2i}=1$ for $i$ odd and $x_{2i}=0$ for $i$ even, and sample size $n=500$. Try generalized linear model (GLM) with logistic and probit links.
Here is what I did, I know there is a problem, but I don't know what:
n <- 500
beta0 <- -1
beta1 <- 5.1
beta2 <- -0.3
x1 <- runif(n=n, min=0, max=1)
x2 <- (1:n)%%2
y <- pnorm(beta0 + beta1*x1 + beta2*x2)
prob.glm <- glm(y~x1+x2, family=binomial(link=probit))
logit.glm <- glm(y~x1+x2, family=binomial)
I know y
is a probability here, but how do you simulate a binary variable from the probability?