[R] calculate probability of union of independent events
(Ted Harding)
Ted.Harding at wlandres.net
Wed Feb 19 00:51:33 CET 2014
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
More information about the R-help
mailing list