Re: [R] Question related to combination and the corresponding probability

2010-11-08 Thread Michael Bedward
Don't know if this is "efficient" but I think it works... yn <- c("Y", "N") X <- expand.grid(x1=yn, x2=yn, x3=yn, x4=yn) Yp <- c(0.6, 0.5, 0.8, 0.9) X$prob <- apply(X, 1, function(x) cumprod(ifelse(x == "Y", Yp, 1-Yp))[length(x)]) Michael On 9 November 2010 17:05, Kate Hsu wrote: > Dear r user

[R] Question related to combination and the corresponding probability

2010-11-08 Thread Kate Hsu
Dear r users, I have 4 variables x1,x2,x3,x4 and each one has two levels, for example Y and N. For x1: prob(Y)=0.6, prob(N)=0.4; For x2: prob(Y)=0.5, prob(N)=0.5; For x3: prob(Y)=0.8, prob(N)=0.2; For x4: prob(Y)=0.9, prob(N)=0.1; Therefore, the sample space for (x1, x2, x3, x4)={, YYYN, Y