R 統計學入門
Maggie Matsui
Content Developer, DataCamp


rbinom(# of trials, # of coins, # probability of heads/success)
1 = 正面,0 = 反面
rbinom(1, 1, 0.5)
1
rbinom(1, 1, 0.5)
0
rbinom(8, 1, 0.5)
1 0 0 1 0 0 1 0

rbinom(1, 8, 0.5)
3

rbinom(10, 3, 0.5)
2 0 1 0 1 1 3 3 3 1

rbinom(10, 3, 0.25)
1 1 0 0 1 1 1 1 2 1

一串獨立試驗中,成功次數的機率分配
例如:一串拋硬幣中的正面次數
由 $n$ 與 $p$ 描述


$P(\text{heads} = 7)$
# dbinom(num heads, num trials, prob of heads)
dbinom(7, 10, 0.5)
0.1171875
$P(\text{heads} \le 7)$
pbinom(7, 10, 0.5)
0.9453125
$P(\text{heads} > 7)$
pbinom(7, 10, 0.5, lower.tail = FALSE)
0.0546875
1 - pbinom(7, 10, 0.5)
0.0546875
$\text{Expected value} = n \times p$
10 次拋擲中正面的期望值 $= 10 \times 0.5 = 5$
二項分配:一串獨立試驗中成功次數的機率分配

二項分配:一串獨立試驗中成功次數的機率分配
第二次試驗的機率會受第一次結果影響
若試驗不獨立,就不能用二項分配!

R 統計學入門