###Making THE LOOKUP TABLE FOR Pr(Y|X).. we assume log normal model ###Now to create the Ys : we assume E[Y|X,R=1] is log normal. ###start forming c(x) if(Distributiony=="Normal"){ logcx <- truealpha*truef+truealpha^2*sigmay^2/2 ###now we form Pr[R=1|X] pr1x <- 1/(1+exp( trueh + logcx)) ###Now form the look up table for F^-1. Y <- apply(cbind(truef,trueh,pr1x),1,function(x){ xf <- x[1];xh <- x[2]; xpr1<-x[3] ys <- seq(xf-5*sigmay,xf+5*sigmay,len=GRIDSIZE) zs <- pnorm(ys,xf,sigmay)*xpr1 + exp(xh)*exp((truealpha*(truealpha*sigmay^2 + 2*xf))/2.)*(pnorm(ys,xf+truealpha*sigmay^2,sigmay))*xpr1 ys[order(abs(runif(1) - zs))[1]] }) } if(Distributiony=="Lognormal"){ logcx <- truealpha*truef+truealpha^2*sigmay^2/2 ###now we form Pr[R=1|X] pr1x <- 1/(1+exp( trueh + logcx)) ###Now form the look up table for F^-1. Y <- apply(cbind(truef,trueh,pr1x),1,function(x){ xf <- x[1];xh <- x[2]; xpr1<-x[3] ys <- exp(seq(xf-5*sigmay,xf+5*sigmay,len=GRIDSIZE)) zs <- plnorm(ys,xf,sigmay)*xpr1 + exp(xh)*exp((truealpha*(truealpha*sigmay^2 + 2*xf))/2.)*(pnorm(log(ys),xf+truealpha*sigmay^2,sigmay))*xpr1 ys[order(abs(runif(1) - zs))[1]] }) }