-3
$\begingroup$

How can I simulate the data for the variable Y in R,.suppose I have Y1=rpois(n,u), Y2= ruinf(n,0,1) , z=y1+y2 and a=0.5 and then I want to simulate the data for the same variable as Y=Y={log(Z-a) if Z-a>0 log(e) if z-a<=0}. then how will i do it?

$\endgroup$

1 Answer 1

1
$\begingroup$
genY <- function(z) {
    if (z > 0.5){
        Y = log10(z-0.5)
    }
    else{
        Y = log10(2.71828)
    }
}

Y = {}
for (z in runif(10000, 0, 1)){
    y = genY(z);
    Y = c(Y, y)
}

Is this what you need?

$\endgroup$
1
  • $\begingroup$ I don't think it's difficult, just read the manual and try it yourself. $\endgroup$
    – hxhc
    Commented Jul 18, 2017 at 2:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.