I am trying to simulate data where the data generating process is p(X, Y) = p(X)p(Z|X), where the distribution of binary Z depends on the value of X, which is generated from the standard normal distribution.
X is generated by the code below.
X <- rnorm(100, 0, 1)
How would I generate the vector Y conditional on X? My initial thought was to somehow generate a vector of probabilities P using X and then running the code below, but have not been successful in doing so.
sapply(P,function(Y){rbinom(1,1,Y)})