I have 6 variables, (A,B,C,D,E,F) that can either pass or fail (i.e., true
or false). I can get a table of all pass/fail combinations with this: scenarios <- expand.grid(A = c("pass", "fail"), B = c("pass", "fail"), C = c("pass", "fail"), D = c("pass", "fail"), E = c("pass", "fail"), F = c("pass", "fail")) But I have the extra condition that if E is true, then F must be false, and vice versa, so what I don't know is how to get all combinations when E and F are mutually exclusive. [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Hi Rod,
How about this? scenarios <- expand.grid(A = c("pass", "fail"), B = c("pass", "fail"), C = c("pass", "fail"), D = c("pass", "fail"), E = c("pass", "fail")) scenarios$F<-ifelse(scenarios$E=="pass","fail","pass") Jim On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]> wrote: > I have 6 variables, (A,B,C,D,E,F) that can either pass or fail (i.e., true > or false). > I can get a table of all pass/fail combinations with this: > > scenarios <- expand.grid(A = c("pass", "fail"), B = c("pass", "fail"), C = > c("pass", "fail"), D = c("pass", "fail"), E = c("pass", "fail"), F = > c("pass", "fail")) > > But I have the extra condition that if E is true, then F must be false, and > vice versa, so what I don't know is how to get all combinations when E and F > are mutually exclusive. > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
> On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]>
> wrote: > > But I have the extra condition that if E is true, then F must be false, and > > vice versa, Question: Does 'vice versa' mean a) "if E is False, F must be True" or b) "if F is True, E must be False"? ... which are not the same. b) (and mutual exclusivity in general) does not rule out the condition "E False, F False", which would not be addressed by the pass/fail equivalent equivalent of F <- !E ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Thank you for pointing that out, I realize not only did I use the wrong
language but I did not describe the situation accurately. I do need to address the situation where both variables E and F actually pass, that is the majority case, one or the other can fail, but there can never be a situation where E and F both fail. I do not know a specific term for that situation, but you are correct that mutual exclusivity is wrong. While I can generate a list of all possible combinations with the expand.grid function (which I am not committed to by the way), it would be very helpful if I could exclude the combinations where E and F both fail. I am not sure where to go from here, but the solution does not have to be elegant or even efficient because I do not need to scale higher than 6 variables. On Thu, Aug 2, 2018 at 7:26 AM, S Ellison <[hidden email]> wrote: > > On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]> > > wrote: > > > But I have the extra condition that if E is true, then F must be > false, and > > > vice versa, > > Question: Does 'vice versa' mean > a) "if E is False, F must be True" > or > b) "if F is True, E must be False"? > ... which are not the same. > > b) (and mutual exclusivity in general) does not rule out the condition "E > False, F False", which would not be addressed by the > pass/fail equivalent equivalent of F <- !E > > > > > ******************************************************************* > This email and any attachments are confidential. Any u...{{dropped:13}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
From what I can tell, the simplest way is to
First generate all the combinations Then exclude those you don't want. Here's an example, with only three variables (D, E, and F), that excludes those where E and F both fail > tmp <- c('p','f') > X <- expand.grid(D=tmp, E=tmp, F=tmp) > X <- subset(X, !(E=='f' & F=='f')) > X D E F 1 p p p 2 f p p 3 p f p 4 f f p 5 p p f 6 f p f -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 8/2/18, 8:41 AM, "R-help on behalf of R Stafford" <[hidden email] on behalf of [hidden email]> wrote: Thank you for pointing that out, I realize not only did I use the wrong language but I did not describe the situation accurately. I do need to address the situation where both variables E and F actually pass, that is the majority case, one or the other can fail, but there can never be a situation where E and F both fail. I do not know a specific term for that situation, but you are correct that mutual exclusivity is wrong. While I can generate a list of all possible combinations with the expand.grid function (which I am not committed to by the way), it would be very helpful if I could exclude the combinations where E and F both fail. I am not sure where to go from here, but the solution does not have to be elegant or even efficient because I do not need to scale higher than 6 variables. On Thu, Aug 2, 2018 at 7:26 AM, S Ellison <[hidden email]> wrote: > > On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]> > > wrote: > > > But I have the extra condition that if E is true, then F must be > false, and > > > vice versa, > > Question: Does 'vice versa' mean > a) "if E is False, F must be True" > or > b) "if F is True, E must be False"? > ... which are not the same. > > b) (and mutual exclusivity in general) does not rule out the condition "E > False, F False", which would not be addressed by the > pass/fail equivalent equivalent of F <- !E > > > > > ******************************************************************* > This email and any attachments are confidential. Any u...{{dropped:13}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by radicalrod
Given that clarification, I'd just generate the full set and remove
the ones you aren't interested in, as in: scenarios <- expand.grid(A = c("pass", "fail"), B = c("pass", "fail"), C = c("pass", "fail"), D = c("pass", "fail"), E = c("pass", "fail"), F = c("pass", "fail")) scenarios <- subset(scenarios, !(E == "fail" & F == "fail)) Sarah On Thu, Aug 2, 2018 at 11:41 AM, R Stafford <[hidden email]> wrote: > Thank you for pointing that out, I realize not only did I use the wrong > language but I did not describe the situation accurately. I do need to > address the situation where both variables E and F actually pass, that is > the majority case, one or the other can fail, but there can never be a > situation where E and F both fail. I do not know a specific term for that > situation, but you are correct that mutual exclusivity is wrong. While I > can generate a list of all possible combinations with the expand.grid > function (which I am not committed to by the way), it would be very helpful > if I could exclude the combinations where E and F both fail. I am not sure > where to go from here, but the solution does not have to be elegant or even > efficient because I do not need to scale higher than 6 variables. > > > > On Thu, Aug 2, 2018 at 7:26 AM, S Ellison <[hidden email]> wrote: > >> > On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]> >> > wrote: >> > > But I have the extra condition that if E is true, then F must be >> false, and >> > > vice versa, >> >> Question: Does 'vice versa' mean >> a) "if E is False, F must be True" >> or >> b) "if F is True, E must be False"? >> ... which are not the same. >> >> b) (and mutual exclusivity in general) does not rule out the condition "E >> False, F False", which would not be addressed by the >> pass/fail equivalent equivalent of F <- !E >> >> >> ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Logic:
!(E == "fail" & F == "fail) <==> (E == "pass" | F == "pass") -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Aug 2, 2018 at 8:57 AM, Sarah Goslee <[hidden email]> wrote: > Given that clarification, I'd just generate the full set and remove > the ones you aren't interested in, as in: > > > scenarios <- expand.grid(A = c("pass", "fail"), B = c("pass", "fail"), C = > c("pass", "fail"), D = c("pass", "fail"), E = c("pass", "fail"), F = > c("pass", "fail")) > > > scenarios <- subset(scenarios, !(E == "fail" & F == "fail)) > > Sarah > > On Thu, Aug 2, 2018 at 11:41 AM, R Stafford <[hidden email]> > wrote: > > Thank you for pointing that out, I realize not only did I use the wrong > > language but I did not describe the situation accurately. I do need to > > address the situation where both variables E and F actually pass, that is > > the majority case, one or the other can fail, but there can never be a > > situation where E and F both fail. I do not know a specific term for > that > > situation, but you are correct that mutual exclusivity is wrong. While > I > > can generate a list of all possible combinations with the expand.grid > > function (which I am not committed to by the way), it would be very > helpful > > if I could exclude the combinations where E and F both fail. I am not > sure > > where to go from here, but the solution does not have to be elegant or > even > > efficient because I do not need to scale higher than 6 variables. > > > > > > > > On Thu, Aug 2, 2018 at 7:26 AM, S Ellison <[hidden email]> > wrote: > > > >> > On Thu, Aug 2, 2018 at 11:20 AM, R Stafford <[hidden email]> > >> > wrote: > >> > > But I have the extra condition that if E is true, then F must be > >> false, and > >> > > vice versa, > >> > >> Question: Does 'vice versa' mean > >> a) "if E is False, F must be True" > >> or > >> b) "if F is True, E must be False"? > >> ... which are not the same. > >> > >> b) (and mutual exclusivity in general) does not rule out the condition > "E > >> False, F False", which would not be addressed by the > >> pass/fail equivalent equivalent of F <- !E > >> > >> > >> > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Sarah Goslee
> Given that clarification, I'd just generate the full set and remove
> the ones you aren't interested in, as in: I'd agree; that is probably the most efficient thing to do with only half a dozen binary variables and a single condition. A way of going about it for a more complex case might be to generate a single dummy variable encoding the special case combinations in the expand.grid step, and then decode that. For example (using this case): allowed.EF <- data.frame(E=c("pass", "pass", "fail"), F=c("pass", "fail", "pass" )) AtoEF <- expand.grid(A=c("pass", "fail"),B=c("pass", "fail"), C=c("pass", "fail"), D=c("pass", "fail"), EF=1:3 ) AtoF <- cbind(AtoEF[1:4], allowed.EF[AtoEF$EF,]) #Which gives the same combinations as Sarah's complete/subset method, albeit in a different order and with silly row names. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble | Edit this page |