开始使用免费开始使用

从二项分布和正态分布进行模拟

在本练习中,您将通过模拟来自二项分布及其正态近似的大样本并比较它们的直方图,来亲自检验正态分布是否能较好地近似二项分布。

本练习是课程的一部分

R 中的概率基础

查看课程

练习说明

  • 生成来自 Binomial(1000, .2) 分布的 100,000 次抽样。将其保存为 binom_sample
  • 使用 rnorm() 函数生成近似该二项分布的正态分布的 100,000 次抽样。(请记住,rnorm() 的参数是均值和标准差,而标准差是方差的平方根)。将其保存为 normal_sample
  • 使用 compare_histograms() 函数比较这两个分布。(请记住,它需要两个参数:要比较的第一个和第二个向量)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Draw a random sample of 100,000 from the Binomial(1000, .2) distribution
binom_sample <-

# Draw a random sample of 100,000 from the normal approximation
normal_sample <- 

# Compare the two distributions with the compare_histograms function
编辑并运行代码