目录

  • 1 概率论的基本概念
    • 1.1 随机试验
    • 1.2 样本空间、随机事件
    • 1.3 频率与概率
    • 1.4 等可能概型(古典概型)
    • 1.5 条件概率
    • 1.6 独立性
  • 2 随机变量及其分布
    • 2.1 随机变量
    • 2.2 离散型随机变量及其分布
    • 2.3 随机变量的分布函数
    • 2.4 连续型随机变量及其概率密度
    • 2.5 随机变量的函数的分布
  • 3 多维随机变量及其分布
    • 3.1 二维随机变量
    • 3.2 边缘分布
    • 3.3 新建目录
    • 3.4 新建目录
    • 3.5 二维随机变量的特征数
  • 4 随机变量的数字特征
    • 4.1 数学期望
    • 4.2 随机变量的数字特征
    • 4.3 协方差及相关系数
    • 4.4 矩、协方差矩阵
  • 5 大数定律与中心极限定理
    • 5.1 大数定律
    • 5.2 中心极限定理
  • 6 统计量及其分布
    • 6.1 样本数据的整理与显示
    • 6.2 统计量及其分布
  • 7 参数估计
    • 7.1 点估计得几种方法
    • 7.2 点估计的评价标准
    • 7.3 区间估计
  • 8 假设检验
    • 8.1 假设检验的基本思想与概念
    • 8.2 正态总体参数假设检验
  • 9 基于R语言的实验
    • 9.1 R语言介绍
    • 9.2 R软件下载与安装
    • 9.3 初识R软件
    • 9.4 蒲丰投针的计算
    • 9.5 同一天生日的计算
    • 9.6 抛硬币和骰子
    • 9.7 两点分布
    • 9.8 二项分布
    • 9.9 泊松分布
    • 9.10 正态分布
    • 9.11 指数分布
两点分布

There is a whole world of R functions we can use to sample random values from probability distributions or obtain probabilities from them. Generally, each of these functions is referenced with an abbreviation (pois for Poisson, geom for Geometric, binom for the Binomial, etc.) preceded by the type of function we want, referenced by a letter:

  • r… for simulating from a distribution of interest

  • d… for obtaining the probability mass function P[X=x] (or probability density function for continuous random variables)

  • p… for obtaining the cumulative distribution function, which is just a fancy way of saying P[Xq] for any value of q.

  • q… for the quantile function of a distribution of interest


9.7.1 The Bernoulli Distribution 二项分布

A Bernoulli random variable (XBernoulli(p)) is equivalent to a (not necessarily fair) coin flip, but the outcome sample space is {0,1} instead of heads and tails. The parameter p, by convention, signifies the probability of getting a 1, and a single draw of a Bernoulli random variable is called a “trial.”

Random Samples: rbinom

The best way to simulate a Bernoulli random variable in R is to use the binomial functions (more on the binomial below), because the Bernoulli is a special case of the binomial: when the sample size (number of trials) is equal to one (size = 1).

The rbinom function takes three arguments:

  • n: how many observations we want to draw

  • size: the number of trials in the sample for each observation (here =1)

  • p: the probability of success on each trial

rbinom(n = 1, size = 1, p = 0.7)
## [1] 1

We can also randomly draw a whole bunch of Bernoulli (single) trials:

rbinom(n = 20, size = 1, p = 0.7)
##  [1] 0 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 0 0 1 1

Check out the help function for rbinom to see the arguments you can use with this function, and their meaning.

Density Functions: dbinom

The Bernoulli has a very simple PDF,Pr(X=x)={px=11px=0.This time, we’ll use the density function inside a barplot command, to send it directly to a plot.

barplot(names.arg = 0:1, 
        height = dbinom(0:1, size = 1, p = 0.7),
        main = "Bernoulli PDF", xlab = 'X', ylab = 'Probability')

Cumulative Distribution Functions: pbinom

The CDF of a Bernoulli random variable is also simple.

barplot(names.arg = 0:1, 
        height = pbinom(0:1, size = 1, p = 0.7),
        main = "Bernoulli CDF", xlab = 'X', ylab = 'Probability')