考虑到与标记为d1,d2和d3的滚动3公平骰子相关的概率分布,我必须计算以下概率:
正如stackoverflow中的另一个问题所提到的,我可以解决(a)和(b)如下:
一个。
mean(dice.sums > 12 & dice.sums < 18) # Assume that, I already calculated the dice.sums
湾
mean(dice.sums%%2 ==0)
任何解决问题的建议(c)假设已经创建了等于骰子平均标签的平均值?
答案 0 :(得分:2)
以下是3个案例中每个案例的模拟概率和实际概率之间的比较(理论概率 55/216 , 108/216 和 25/216 由经典的概率定义,理论概率用虚线表示:
# simulated probs
num.repeat <- 100
num.trials <- 10^3
sim.probs <- vector("list", 3)
for (j in 1:num.repeat) {
res <- .rowMeans(replicate(num.trials, {
#dice <- as.integer(runif(3,1,6)) # does not work
dice <- sample(1:6, 3, replace=TRUE)
s <- sum(dice)
p1 <- ((s > 12) && (s < 18))
p2 <- (s %% 2 == 0)
p3 <- ((s/3) == 4)
c(p1, p2, p3)
}), 3, num.trials)
for (i in 1:3) {
sim.probs[[i]] <- c(sim.probs[[i]], res[i])
}
}
plot(x=0, y=0, xlim=c(1,num.repeat), ylim=c(0,0.6), pch=19, xlab='num.repeat', ylab='prob', main='Simulated vs. Actual Probs')
for (i in 1:3) {
points(sim.probs[[i]], pch=i, col=i)
}
legend("topright", c('prob1', 'prob2', 'prob3'), pch=1:3, col=1:3)
# theroetical probs
actual.probs <- rep(0,3)
# all points in the sample space
for (d1 in 1:6)
for (d2 in 1:6)
for (d3 in 1:6) {
s <- d1 + d2 + d3
actual.probs[1] <- actual.probs[1] + ((s > 12) && (s < 18))
actual.probs[2] <- actual.probs[2] + ((s %% 2) == 0)
actual.probs[3] <- actual.probs[3] + ((s / 3) == 4)
}
actual.probs <- actual.probs / 6^3 # theoretical probs
for (i in 1:3) {
abline(h=actual.probs[i], lty=2, lwd=2, col=i)
}
答案 1 :(得分:0)
如果您阅读作业,则提示***表示使用子集来选择事件并总和P.
subs&lt; - subset(data.frame,data.frame $ mean == 4) 然后是colSums(subs)
答案 2 :(得分:0)
# All possible dice rolls:
dice.sums <- outer(outer(1:6, 1:6, FUN = '+'), 1:6, FUN = '+')
# Probability of a roll greater than 12 and less than 18: 0.2546
prob.12.18 <- mean(dice.sums > 12 & dice.sums < 18)
# Probability of an even roll: 0.5
prob.even <- mean(dice.sums %% 2 == 0)
# Probability of a mean roll value of exactly 4: 0.1157
prob.mean.4 <- mean(dice.sums == 12)