使用 replicate() 进行模拟
使用 replicate() 函数,模拟 100,000 次在抛硬币时等待首次正面出现的试验,其中正面的概率为 20%。通过调用 qplot() 绘制该模拟的直方图。
本练习是课程的一部分
R 中的概率基础
练习说明
- 使用
replicate()模拟 100,000 次几何试验。将给定的表达式复制并粘贴为replicate()的第二个参数。 - 对
replications调用qplot()绘制直方图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Existing code for finding the first instance of heads
which(rbinom(100, 1, 0.2) == 1)[1]
# Replicate this 100,000 times using replicate()
replications <-
# Histogram the replications with qplot
qplot(___)