考虑一个游戏,其中包括滚动三个骰子计算结果和概率的事件。
#sample space
install.packages("combinat")
library(combinat)
install.packages("https://cran.r-project.org/src/contrib/Archive/prob/prob_0.9-2.tar.gz", repos = NULL, dependencies = TRUE)
library(prob)
Prob <- prob::prob
s<-rolldie(3,makespace=TRUE)
#a sum of the rolls is greater than 3 but less than 8.
(a_outcomes<-subset(s,X1+X2+X3>3 & X1+X2+X3<8))
(a_probability<-Prob(a_outcomes))
#sum(a_outcomes$probs)
#b All the three rolls are identical
(b_outcomes<-subset(s,X1==X2 &X2==X3))
(b_probability<-Prob(b_outcomes))
round(b_probability<-prob(b_outcomes),5)
#c Only two of the three rolls are identical.
(c_outcomes<-subset(s,X1==X2 & X2!=X3 | X1==X3 & X1!=X2 |X2==X3 &X2!=X1))
(c_probability<-Prob(c_outcomes))
#d None of the three rolls are identical
(d_outcomes<-subset(s,X1!=X2 & X2!=X3 & X3!=X1))
(d_probability<-Prob(d_outcomes))
#e 2 of the 3 rolls are identical given that sum of the rolls is greater than
# 3 and less than 8
e_outcomes(c_outcomes,a_outcomes)
e_outcomes
e_prob<-Prob(c_outcomes,given=a_outcomes)
e_prob
字符串
我得到e_outcomes
的错误.我能够得到概率为e,但无法得到结果.什么是错误的代码?其余的代码都工作正常,除了e_outcomes.请帮助
1条答案
按热度按时间v64noz0r1#
如果你愿意采取不同的方法:
模拟:
字符串
通过置换的精确概率:
型