数学题中的符号错误相互抵消

R 中的概率谜题

Peter Chi

Assistant Professor of Statistics Villanova University

灵感来源

R 中的概率谜题

rbinom 函数

rbinom(n = 10, size = 5, prob = 0.4)
0 3 4 2 2 1 1 2 3 3
R 中的概率谜题

判断一个值是否为偶数

value <- 3
value/2 == round(value/2)
FALSE

 

value <- 4
value/2 == round(value/2)
TRUE
R 中的概率谜题

用 mean 估计概率

result <- c(TRUE, TRUE, FALSE, TRUE)
mean(result)
0.75
R 中的概率谜题

重温 sapply 函数

sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
rbinom(n, size, prob)
result <- sapply(X = c(0.25, 0.75, 0.1, 0.9), FUN = rbinom, n = 1, size = 1)

result
0 1 0 1
sum(result)
2
R 中的概率谜题

开始练习!

R 中的概率谜题

Preparing Video For Download...