An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140218/4fc32b21/attachment.pl>
calculate probability of union of independent events
2 messages · Meinfelder, Florian, (Ted Harding)
On 18-Feb-2014 22:08:38 Meinfelder, Florian wrote:
Dear all, I am looking for a way to calculate the probability of the union of k independent events in R. Is there a function that takes a k-dimensional probability vector as input and returns p(A_1 U A_2 U...U A_k)? Thanks, Florian
I don't know (off-hand); but it is very easy to write one's own!
Since
P(A1 U A2 U ... U Ak )
= 1 - P(not(A1 U A2 U ... u Ak))
= 1 - P((not A1) & (not A2) & ... & (not Ak))
= 1 - P(not A1)*P(not A2)* ... *P(not Ak) [by independence]
= 1 - (1-p1)*(1-p2)* ... *(1-pk)
where pj is P(Aj). Hence
punion <- function(p){1 - prod(1-p)}
should do it!
Ted.
-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 18-Feb-2014 Time: 23:51:31
This message was sent by XFMail