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.hard...@wlandres.net>
Date: 18-Feb-2014  Time: 23:51:31
This message was sent by XFMail

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to