[R] probability of occurrence of an event and the probabilityof anevent upon the occurrence of another event

peter dalgaard pdalgd at gmail.com
Fri Sep 6 14:04:58 CEST 2013


On Sep 6, 2013, at 12:34 , Gerrit Eichner wrote:

> Hello, Francesco,
> 
> these could be considered as two of the central questions in statistics in general ... but they do not necessarily have anything to do with R.
> 
> Regards -- Gerrit

Yes.

However, since it is Friday and my brain is fried from the morning lecture anyway:

If you can represent the (finite) sample space in R, you can also do probability calculations in R. Conditioning corresponds to subsetting the sample space. E.g., for a double dice throw (D1,D2) you can find 

> twodice <- expand.grid(d1=1:6,d2=1:6) 
> with(twodice, mean(d1==5))
[1] 0.1666667
> with(subset(twodice,d1+d2==8), mean(d1==5))
[1] 0.2
> with(subset(twodice,d1+d2==11), mean(d1==5))
[1] 0.5

I.e. 

P(D1=5) = 1/6
P(D1=5 | D1+D2=8) = 1/5
P(D1=5 | D1+D2=11) = 1/2

The above works for symmetric probability spaces. For general finite spaces, include a vector of probabilities and do something like this:

> twodice$p <- 1/nrow(twodice)
> with(subset(twodice,d1+d2==11), sum(p[d1==5])/sum(p))
[1] 0.5

- Peter D.


> 
> On Fri, 6 Sep 2013, Francesco Miranda wrote:
> 
>> how can i calculate the probability of occurrence of an event and the probability of an event upon the occurrence of another event.
>> P (A) and P (A | B) ..
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help at 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.
> 
> ______________________________________________
> R-help at 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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list