# # Objectives 目标

• Understand Uniform Distribution and Normal Distribution
了解均匀分布正态分布
• Know how to generate the uniform and normal random numbers
知道如何生成均匀和正态随机数
• Know how to use q- function to find the quantiles of the normal distribution
知道如何使用 q- 函数找到正态分布的分位数

# # Uniform Distribution 均匀分布

Uniform Random Variable 均匀随机变量
A uniform random variable is a continuous random variable for which every outcome in an interval is equally likely.

• Example: $X$ is a random real number taken from $[0,1]$.
$X$ 是一个随机实数取自 $[0,1]$

• We can use runif(n) to generate random number taken from $[0,1]$.
我们可以 runif(n) 用来生成随机数取自 $[0,1]$

What will happen if increasing the number of the sample size?

• Notation: $X\sim U[a,b]$

• Probability Density Function pdf :
$f(x) = \frac{1}{b-a}$ for $a\leq x\leq b$

• Cumulative Distribution Function cdf :
For $a\leq x\leq b$

$F(x)= P(a \leq X \le x) = \int_a^x f(t)d t=\int_a^x \frac{1}{b-a}d t=\frac{x-a}{b-a}.$

• Expectation & Variance 期望值与方差
\mu = E(X) &=\int_a^b x\frac{1}{b-a} d x=\left.\frac{x^2}{2(b-a)}\right|_{a}^b=\frac{a+b}{2} \sigma^2 = var(X) &= E(X^2)-[E(X)]^2 = \int_a^b x^2\frac{1}{b-a} d x - \left(\frac{a+b}{2}\right)^2= \left.\frac{x^3}{3(b-a)}\right|_{a}^b-\frac{(a+b)^2}{4} = \frac{(b-a)^2}{12}

## # Important R functions

• To generate random numbers, pdf (aka pmf), cdf, and quantiles.
生成随机数、pdf（又名 pmf）、cdf 和分位数。

• The prefixes for these functions are:
这些函数的前缀是：

 r random number generation 随机数生成 d probability density function or probability mass function 概率密度函数或概率质量函数 p cumulative distribution function 累积分布函数 q quantiles 分位数

## # Example 1

Suppose $X \sim U[-1,1]$

[1] 0.75

[1] 0

[1] 0.0002108174

[1] 0.3333544


## # In-class Exercise: Uniform Distribution 均匀分布

1. Suppose $X \sim U[-2,3]$, please generate the random numbers with sample size $n = 1e6$.

2. Do a histogram for the instances you generated with the y-axis as relative frequency instead of frequency.
使用 y 轴作为相对频率而不是频率为您生成的实例绘制直方图。

3. Find $P(X \le 0)$, $P(X \le 1)$, and $P(X \ge 1)$ (a little tricky).

[1] 0.4

[1] 0.6

[1] 0.4

4. Find Q1, median, Q3 of this random variable $X$. What is the expectation value and variance of $X$?
找到这个随机变量$X$ 的 Q1、中位数、Q3。期望值和方差是多少？

[1] -0.75

[1] 0.5

[1] 1.75


The expectation is $\frac{b+a}{2}=\frac{3+(-2)}{2}=0.5$ . The variance is $\frac{b+a}{2}=\frac{3+(-2)}{2}=0.5\frac{(b-a)^{2}}{12}=\frac{(3-(-2))^{2}}{12}=\frac{25}{12}=2.08333$ .

5. Find Q1, median, Q3, mean, and variance of the sample you generated. Compare your results with the answers in Ex.4.
找出生成的样本的 Q1、中位数、Q3、均值和方差。将您的结果与例 4 中的答案进行比较。

        0%        25%        50%        75%       100%
-1.9999994 -0.7476943  0.5001483  1.7515364  2.9999982

[1] 0.5008553

[1] 2.081609


# # Normal Distribution 正态分布

• The normal distribution (also be called Gaussian distribution) is a symmetric distribution that is centered around a mean and spreads out in both directions.
正态分布（也被称为高斯分布）是围绕平均值和差居中出在两个方向上对称分布。

Examples: Test scores for all ITM 514 students. 所有 ITM 514 学生的考试成绩。

• Notation: $X\sim \mathcal{N}(\mu, \sigma^2)$
符号

• $\mu$ is the mean of the distribution 分布的平均值
• $\sigma^2$ is the variance of the distribution 分布的方差
• Probability Density Function pdf :

$f(x) = \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(x-\mu)^2}{2\sigma^2}},\,\,\,\text{for } -\infty

• CDF: The CDF of normal distribution doesn't have a closed form, i.e., there is no analytic answer of the integral 正态分布的 CDF 没有封闭形式，即没有积分的解析答案

$P(X

$P(x_1

## # Example 2

Suppose $Z$ is the standard normal random variable, i.e., $Z \sim \mathcal{N}(0, 1)$

[1] 0.6914625

[1] 0

[1] -0.002525208

[1] 1.002635


What's the relationship between the general normal random variable $X \sim \mathcal{N}(\mu, \sigma^2)$ and the standard normal random variable?

$Z= \frac{X-\mu}{\sigma} \sim \mathcal{N}(0,1).$

To calculate the probability involving $X\sim \mathcal{N}(\mu,\sigma^2)$, 计算涉及的概率

\begin{eqnarray*} P(a\leq X\leq b) &=& P\left(\frac{a-\mu}{\sigma}\leq \frac{X-\mu}{\sigma}\leq \frac{b-\mu}{\sigma}\right)\\ &=& P\left(\frac{a-\mu}{\sigma}\leq Z\leq \frac{b-\mu}{\sigma}\right), \end{eqnarray*}

## # Example 3

The achievement scores from a college entrance examination are normally distributed with mean 75 and standard deviation 10. What fraction of the scores lies between 80 and 90?

The scores $X\sim \mathcal{N}(75,10^2)$, then

$P(80\leq X\leq 90) = P\left(\frac{80-75}{10}\leq Z\leq \frac{90-75}{10}\right) = P(0.5\leq Z\leq 1.5) .$

[1] 0.2417303

[1] 0.2417303


## # Example 4

Find the value of $z_0$ such that $95\%$ of the standard normal $Z$ values lie between $-z_0$ and $z_0$; that is, $P(-z_0\leq Z\leq z_0) = .95$.

$P(-z_0\le Z \le z_0) = P(Z \le z_0) -P(Z \le -z_0) = (1- P(Z \ge z_0)) - P(Z \le -z_0) = 1- 2P(Z <-z_0) = 0.95 \Rightarrow P(Z<-z_0) = 0.025.$

How to find $z_0$ in R ?

[1] 0.2417303

[1] 0.2417303


### # In-class Exercise

Suppose $Z \sim \mathcal{N}(0,1)$,
can you find a $y>0$ such $P(-y \le Z \le y) = 0.01$?

Critical value $z_{\alpha}$ of a standard normal distribution is the value on the measurement axis for which $\alpha$ of the are under the standard normal curve lies to the right of $z_{\alpha}$.

## # In-class Exercise: Normal Distribution

1. Suppose $X \sim \mathcal{N}(-1,3^2)$, please generate the random numbers with sample size $n = 1e6$.
认为 $X \sim \mathcal{N}(-1,3^2)$，请生成样本大小的随机数 $n = 1e6$.

2. Do a histogram for the instances you generated with the y-axis as relative frequency instead of frequency.
使用 y 轴作为相对频率而不是频率为您生成的实例绘制直方图。

3. Find $P(X \le 0)$, $P(X \le 1)$, $P(X \ge 1)$, and $P( 0\le X \le 1)$.
$P(X \le 0)$, $P(X \le 1)$, $P(X \ge 1)$, and $P( 0\le X \le 1)$

[1] 0.6305587

[1] 0.7475075

[1] 0.7475075

4. Find Q1, median, Q3 of this random variable $X$. What is the expectation value and variance of $X$?
找到这个随机变量$X$ 的 Q1、中位数、Q3，$X$ 的期望值和方差是多少 XX?

[1] -3.023469

[1] -1

[1] 1.023469

5. Find Q1, median, Q3, mean, and variance of the sample you generated. Compare your results with the answers in Ex.4.
找出您生成的样本的 Q1、中位数、Q3、均值和方差。将您的结果与第 4 题中的答案进行比较。

         0%        25%        50%        75%       100%
-15.773765  -3.029712  -1.010223   1.014308  14.674138

[1] -1.008806

[1] 8.978004


# # Conclusion

Normal distribution is the most important distribution. When we talk about the Central Limit Theorem, confidence interval, and hypothesis testing, we will come back to the normal distribution.