# 5-1. Continuous Random Variables

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-LyfaLk51dhWdh2Aa_9H%2F-LyfatXX8ooOVZxQWsnJ%2FChapter-05-1(Kor).pdf?alt=media&token=6a9e6467-d548-4bbf-8c86-f7a4e06d13af>" %}
Chapter 5-1 (Korean)
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-LyfblnC0sQtMNngZ_wI%2F-Lyfd0H5mfORv1foVRmG%2FChapter-05-2(Kor).pdf?alt=media&token=09243664-7c95-43da-913f-a2445a6df1bf>" %}
Chapter 5-2 (Korean)
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lz9x5xyUoefFcYcI7-I%2F-Lz9x9M_Ur9nITmyxytX%2FChapter-05-1_Chinese.pdf?alt=media&token=03223a6d-9534-4f52-a80b-b4b15f1c89f6>" %}
Chapter 5-1 (Chinese)
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lz9x5xyUoefFcYcI7-I%2F-Lz9xC1AoZOzaG7ubzwP%2FChapter-05-2_Chinese.pdf?alt=media&token=992b95ff-a024-49fe-ad17-b671f38e8aad>" %}
Chapter 5-2 (Chinese)
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lz9xK8oM58DiS3mkaa0%2F-Lz9xR7ueIyCi9UtwbYM%2FExamples-5-1.zip?alt=media&token=f98f1f2f-8087-4b94-b8de-ba741b572091>" %}
Examples of Chapter 5-1 (R Sources)
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-LzjC0TKZIgeL2mSvTCP%2F-LzjIVEUoBdeKLI3WNC7%2FExamples-5-2.zip?alt=media&token=931f4f25-9cb0-47c3-af58-e6309592ed1d>" %}
Examples of Chapter 5-2 (R Sources) - Changed
{% endfile %}

{% file src="<https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr2T2cnL0KFZamP_47F%2F-Lr2T8s9-AzmKEbCkNnH%2Fch4_continuous.pdf?alt=media&token=dcbc706a-fb23-45dc-b6e2-347140d28459>" %}
Continuous Random Variables
{% endfile %}

## **1.** The Probability Distribution of a Continuous Random Variable

*The* **probability distribution of a continuous random variable** *X* *is an assignment of probabilities to **intervals** of decimal numbers using a function* $$f(x)$$ , *called a* density function, *in the following way: the probability that* *X* *assumes a value in the interval* \[a,b]\[a,b] *is equal to the area of the region that is bounded above by the graph of the equation* $$y=f(x)$$ , *bounded below by the* *x-axis, and bounded on the left and right by the vertical lines through* *a* *and* *b*, *as illustrated in Figure  "Probability Given as Area of a Region under a Curve"*.

![Probability Given as Area of a Region under a Curve](https://saylordotorg.github.io/text_introductory-statistics/section_09/a4a078a33c22b212350844a6cd8789b6.jpg)

> Every **probability density function(p.d.f)** $$f(x)$$ must satisfy the following two conditions:
>
> 1. For all numbers $$x,$$ $$f(x)≥0$$ , so that the graph of $$y=f(x)$$ never drops below the *x*-axis.
>
> 2. The area of the region under the graph of $$y=f(x)$$ and above the *x*-axis is 1.
>
> For any continuous random variable $$X$$ :&#x20;
>
> &#x20;     $$P(a≤X≤b)=P(a\<X≤b)=P(a≤X\<b)=P(a\<X\<b)$$ <br>

## 2. Uniform Distribution

> **균일분포(Uniform distribution)**&#xB294; 유한한 실수 구간 $$\[a, b]$$ 에서 동일한 확률로 관측되는 확률변수 $$X$$의 분포이다.
>
> (p.d.f)                           $$f(x) = \frac{1}{b-a},$$   $$a \le X \le b$$ .

> Expected Values and Variance of Uniform Distribution
>
> &#x20;      $$E(X) = \int\_{a}^{b}x\frac{1}{b-a}dx = \frac{b^2-a^2}{2(b-a)}=\frac{a+b}{2}$$&#x20;
>
> &#x20;      $$E(X^2) = \int\_{a}^{b}x^2\frac{1}{b-a}dx = \frac{b^3-a^3}{3(b-a)}=\frac{a^2+ab+b^2}{3}$$&#x20;
>
> &#x20;      $$Var(X) = E(X^2) - E(X)^2 = \frac{a^2+ab+b^2}{3} - \left ( \frac{a+b}{2} \right )^2 = \frac{(b-a)^2}{12}$$&#x20;

**EXAMPLE 1.**  A random variable $$X$$ has the **uniform distribution** on the interval $$\[0,1]$$ : \
the density function is     \
&#x20;                            $$f(x)=1$$ if *x* is between 0 and 1 \
&#x20;                     and $$f(x)=0$$ for all other values of $$x$$ , \
as shown in Figure  "Uniform Distribution on ".

![Uniform Distribution on \[0, 1\]](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lqze3AT6UEiqEXTqbND%2F-Lqzf6Fu6evIz-k2YzCI%2Fimage.png?alt=media\&token=3a6f82a2-a742-456f-b519-43a538d6d462)

1. Find $$P(X > 0.75)$$ , the probability that $$X$$ assumes a value greater than 0.75.
2. Find $$P(X ≤ 0.2)$$ , the probability that $$X$$ assumes a value less than or equal to 0.2.
3. Find $$P(0.4 < X < 0.7)$$ , the probability that $$X$$ assumes a value between 0.4 and 0.7.

**\[ Solution ]**

![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lqzf_acAAahd-py3xmp%2F-LqzfavvxJsoAxKsUiCU%2Fimage.png?alt=media\&token=31a4d720-6dd2-4ec2-b0cf-7e4a89c6251e)

1. $$P(X > 0.75)$$ is the area of the rectangle of height 1 and base length $$1−0.75=0.25$$ , hence is $$base×height=(0.25)⋅(1)=0.25$$ . See Figure 5.3 "Probabilities from the Uniform Distribution on "(a).
2. $$P(X ≤ 0.2)$$ is the area of the rectangle of height 1 and base length $$0.2−0=0.2$$ , hence is $$base×height=(0.2)⋅(1)=0.2$$ . See Figure 5.3 "Probabilities from the Uniform Distribution on "(b).
3. $$P(0.4 < X < 0.7)$$ is the area of the rectangle of height 1 and length $$0.7−0.4=0.3$$ , hence is $$base×height=(0.3)⋅(1)=0.3$$ . See Figure 5.3 "Probabilities from the Uniform Distribution on "(c).

{% tabs %}
{% tab title="R Source" %}

```
library(Rstat)

# 0. Probability Distribution Function
fx <- function(x) dunif(x, 0, 1)

win.graph(7, 6); par(mfrow=c(1,1));

# E(X), Var(X) and Plot
cont.exp(fx, -0.2, 1.2, prt=TRUE, plot=TRUE)

# 1. P(X>0.75)
punif(0.75, min=0, max=1, lower.tail=FALSE)

# 2. P(X<0.2)
punif(0.2, min=0, max=1, lower.tail=TRUE)

# 3. P(0.4<X<0.7) = P(X<0.7) - P(X<0.4)
punif(0.7, min=0, max=1, lower.tail=TRUE) - punif(0.4, min=0, max=1, lower.tail=TRUE) 
```

{% endtab %}

{% tab title="Prob. Distribution Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lt1zBzUMWzztat_b7_3%2F-Lt21bJTe3_W_eHvW99n%2Fimage.png?alt=media\&token=33ef9b56-220a-4366-a532-ceb5da43e5bd)
{% endtab %}

{% tab title="1. P(X>0.75)" %}

```
> # 1. P(X>0.75)
> punif(0.75, min=0, max=1, lower.tail=FALSE)
## [1] 0.25
```

{% endtab %}

{% tab title="2. P(X<0.2)" %}

```
> # 2. P(X<0.2)
> punif(0.2, min=0, max=1, lower.tail=TRUE)
## [1] 0.2
```

{% endtab %}

{% tab title="3. P(0.4\<X<0.7)" %}

```
> # 3. P(0.4<X<0.7) = P(X<0.7) - P(X<0.4)
> punif(0.7, min=0, max=1, lower.tail=TRUE) - punif(0.4, min=0, max=1, lower.tail=TRUE) 
## [1] 0.3
```

{% endtab %}
{% endtabs %}

**EXAMPLE 2**. A man arrives at a bus stop at a random time (that is, with no regard for the scheduled service) to catch the next bus. Buses run every 30 minutes without fail, hence the next bus will come any time during the next 30 minutes with evenly distributed probability (a uniform distribution). Find the probability that a bus will come within the next 10 minutes.

**\[ Solution ]**

The graph of the density function is a horizontal line above the interval from 0 to 30 and is the *x*-axis everywhere else. Since the total area under the curve must be 1, the height of the horizontal line is 1/30. See Figure 5.4 "Probability of Waiting At Most 10 Minutes for a Bus". The probability sought is $$P(0≤X≤10)$$ .&#x20;

By definition, this probability is the area of the rectangular region bounded above by the horizontal line $$f(x)=1∕30,$$ bounded below by the *x*-axis, bounded on the left by the vertical line at 0 (the *y*-axis), and bounded on the right by the vertical line at 10. This is the shaded region in Figure 5.4 "Probability of Waiting At Most 10 Minutes for a Bus". Its area is the base of the rectangle times its height, $$10⋅(1∕30)=1∕3$$ .&#x20;

Thus $$P(0≤X≤10)=1∕3$$ .<br>

![Probability of Waiting At Most 10 Minutes for a Bus](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lqzfg7MBrXwQpEtbV3r%2F-LqzfrQRTeKOl-lBSZsG%2Fimage.png?alt=media\&token=edb50a5a-92cf-4088-9238-0714573b50a6)

{% tabs %}
{% tab title="R Source" %}

```
library(Rstat)

min <- 0
max <- 30

# 0. Probability Distribution Function
fx <- function(x) dunif(x, min, max)

# E(X), Var(X) and Plot
t <- (max-min) * 0.2 
cont.exp(fx, min-t, max+t, prt=TRUE, plot=TRUE)

# 1. P(X<10)
punif(10, min=min, max=max, lower.tail=TRUE)

```

{% endtab %}

{% tab title="Prob. Distribution Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lt225aqouzHPDTWK3jr%2F-Lt23rHHrmJ7NRVAwoc7%2Fimage.png?alt=media\&token=b4e78e5c-c31b-473b-83ad-32d00804c181)
{% endtab %}

{% tab title="P(0≤X≤10)" %}

```
> punif(10, min=min, max=max, lower.tail=TRUE)
## [1] 0.3333333
```

{% endtab %}
{% endtabs %}

## 3. Uniform Distribution in R

| Function                         |   | parameters                                   |
| -------------------------------- | - | -------------------------------------------- |
| density function                 | d | `dunif(x, min, max)`                         |
| cumulative distribution function | p | `punif(q, min, max, lower.tail =TRUE/FALSE`  |
| quantile function                | q | `qunif(p, min, max, lower.tail = TRUE/FALSE` |
| random nunber generation         | r | `runif(n, min, max)`                         |

### 3-1. Uniform Distribution Plot

`dunif()`

* Uniform Distribution of $$0 \le X \le 10$$

{% tabs %}
{% tab title="R Source" %}

```
library(ggplot2)

# uniform distribution plot (min=0, max=10)
# fun = dunif
ggplot(data.frame(x=c(-2,20)), aes(x=x)) +
stat_function(fun=dunif, args=list(min = 0, max = 10), 
        colour="black", size=1) +
ggtitle("Uniform Distribution of (min=1, max=10)")

```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr0yW-GCAQAxykiy3qI%2F-Lr1-C0ghE7vnrE4wE7x%2Fimage.png?alt=media\&token=f11b613a-457a-47c3-b1bc-8545282de051)
{% endtab %}
{% endtabs %}

&#x20;

### 3-2. Cumulative Uniform Distribution Plot

`punif()`

* Uniform Distribution of $$0 \le X \le 10$$

{% tabs %}
{% tab title="R Source" %}

```
# Cumulative Uniform distribution plot) : fun = punif 

ggplot(data.frame(x=c(-2,20)), aes(x=x)) + 
stat_function(fun=punif, args=list(min = 0, max = 10), 
               colour="black", size=1) + 
ggtitle("Cumulative Uniform Distribution of (min=0, max=10)")
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr0yW-GCAQAxykiy3qI%2F-Lr105tqj1gBtvURdN_u%2Fimage.png?alt=media\&token=85405eea-08e1-4c93-a537-3c17e668a0b1)
{% endtab %}
{% endtabs %}

### 3-3. Probability Calculation

* Uniform Distribution of $$0 \le X \le 10$$, $$X$$ from 0 to 3"

&#x20;                            min = 0, max = 10 => $$P(0 \<X<3) = ?$$&#x20;

{% tabs %}
{% tab title="R Source" %}

```
# 확률 값 계산 : punif()
# punif(q, min, max, lower.tail = TRUE/FALSE)
punif(3, min=0, max=10, lower.tail=TRUE)

# Uniform Distribution of (min=1, max=10), x from 0 to 3"
ggplot(data.frame(x=c(-2,20)), aes(x=x)) +
stat_function(fun=dunif, args=list(min = 0, max = 10), colour="black", size=1) +
annotate("rect", xmin=0, xmax=3, ymin=0, ymax=0.1, alpha=0.2, fill="yellow") +
ggtitle("Uniform Distribution of (min=1, max=10), x from 0 to 3")
```

{% endtab %}

{% tab title="Probability" %}

```
> punif(3, min=0, max=10, lower.tail=TRUE)
## [1] 0.3
```

{% endtab %}

{% tab title="P(0\<X<3) : Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr10K6UsfIrEdCbpFuR%2F-Lr10tgdhEVyiCsXGwRX%2Fimage.png?alt=media\&token=26ea180a-bb9b-47b8-8905-2e7e40fbabb5)
{% endtab %}
{% endtabs %}

### 3-4. Quartiles

`qunif(p, min, max, lower.tail=TRUE/FALSE)`

* Uniform Distribution of $$0 \le X \le 10$$

{% tabs %}
{% tab title="R Source" %}

```
qunif(0.3, min=0, max=10, lower.tail = TRUE)
```

{% endtab %}

{% tab title="quartile" %}

```
> qunif(0.3, min=0, max=10, lower.tail = TRUE)
## [1] 3
```

{% endtab %}
{% endtabs %}

### 3-5. Random Number Generation

`runif(n=100, min=0, max = 10)`

{% tabs %}
{% tab title="R Source" %}

```
# Random Number Generation
ru_100 <- runif(n=100, min=0, max = 10) ; ru_100

# density plot of runif(n=100, min=0, max = 10) & adding line of 0.1 uniform probability
hist(ru_100, freq=FALSE, breaks=10, col="yellow", ylim=c(0, 0.15))
abline(h=0.1, lty=3, lwd=3, col="red")
 
```

{% endtab %}

{% tab title="Random Number" %}

```
> ru_100 <- runif(n=100, min=0, max = 10); ru_100
##   [1] 1.97018452 3.71806505 7.41606720 8.48671408 0.47856458 3.60782547 5.10053850 6.42437469 4.00373441 4.03389579 1.77176371 5.67226059 9.03927102 9.39120243 0.94763774 8.59339938 1.86347542 9.00808273 7.53425727 0.18291435
##  [21] 1.10629222 2.14713704 3.61159600 9.91049072 3.97496036 1.21901205 1.99912945 2.29975202 7.91296603 4.59785103 7.19803239 0.69360516 9.75771851 6.12264345 4.95634087 6.48131121 2.58554254 2.17646432 1.46618064 6.81097950
##  [41] 2.21970354 0.97172896 9.06870417 0.45217870 0.67816859 3.33815603 2.48469822 0.43481027 4.69975307 6.09926291 3.16123004 2.60607698 9.47217206 1.41006090 8.04198232 3.13095264 0.24097621 8.39983448 7.62463219 4.76048162
##  [61] 3.04053000 7.10983243 8.16657863 5.57156257 0.10561342 5.79480714 4.82581432 8.82737239 3.05016402 0.90337332 9.90451497 4.08636837 5.81762119 7.91393302 2.50766472 9.94363813 0.07042486 5.73481684 6.59473334 7.20472657
##  [81] 4.69420254 1.31388268 4.45257513 4.29468046 6.15421702 1.19002639 7.00127259 3.90113476 8.53588901 9.12484395 8.33627391 8.85767937 4.97731321 3.21789454 2.33261707 3.71808882 1.03884319 0.84080657 3.43642535 3.42259390
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr10K6UsfIrEdCbpFuR%2F-Lr13IhV50KXbcD5CtS8%2Fimage.png?alt=media\&token=33bd3f71-db8f-4b2e-aa13-b95309b762c0)
{% endtab %}
{% endtabs %}

* **Drawing PDF and CDF of Continuous Uniform Distribution**

{% tabs %}
{% tab title="R Source" %}

```
library(ggplot2)
library(dplyr)
options(scipen = 999, digits = 2) # sig digits

min <- 0
max <- 1
events <- seq(min, max, by=0.005)

density <- dunif(x = events, min=min, max=max)
prob <- punif(q = events, min=min, max=max, lower.tail = TRUE)
df <- data.frame(events, density, prob)
ggplot(df, aes(x = events, y = density)) + 
  geom_col(width=0.02) +
#  geom_text(
#    aes(label = round(density,2), y = density + 0.01),
#    position = position_dodge(0.9),
#    size = 3,
#    vjust = 0
#  ) +
  labs(title = "PMF and CDF of Uniform Distribution",
#      subtitle = "P(3).",
       x = "Events (x)",
       y = "Density") +
  geom_line(data = df, aes(x = events, y = prob), col="blue")
```

{% endtab %}

{% tab title="Result" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lz9faU99JjDiLCRiUsr%2F-Lz9g_B4aEN0WZhn8CNe%2Fimage.png?alt=media\&token=17de6ee9-ce4a-4605-907f-9ed8eeefd7f0)
{% endtab %}
{% endtabs %}

* Using **Rstat** Package

{% tabs %}
{% tab title="R Sourced" %}

```
library(Rstat)

min <- 0
max <- 1
events <- seq(min, max, by=0.005)

dcol <- c("red", "blue", "green2")

# Survival Function
win.graph(7, 5)
par(mfrow=c(1,2))

plot(events, punif(q = events, min=min, max=max, lower.tail = TRUE), 
     type="l", lwd=2, col=dcol[1], 
     main="CDF of Gamma Distribution",
     ylab="CDF", ylim=c(0,1))

grid(col=3)

plot(events, dunif(events, min=min, max=max), 
     type="l", lwd=2, col=dcol[2], 
     main="PDF of Gamma Distribution",
     ylab="CDF", ylim=c(0,1))
grid(col=3)
```

{% endtab %}

{% tab title="Result" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lz9j_fC8DDMvwyNpZi_%2F-Lz9lu88dyMcSvxXsnFr%2Fimage.png?alt=media\&token=938ed90c-3163-4b78-83e2-fe65b21f1644)
{% endtab %}
{% endtabs %}

## 4. Normal Distributions

The formula for $$f(x)$$ contains two parameters $$μ$$ and $$σ$$ that can be assigned any specific numerical values, so long as $$σ$$ is positive. We will not need to know the formula for $$f(x)$$ , but for those who are interested it is

&#x20;                                                              $$f(x)= \frac {1}{\sqrt{ 2 \pi} \sigma } e^ {-\frac{1}{2} \left ( \frac{x-\mu}{\sigma }  \right ) ^2 }$$&#x20;

where $$π≈3.14159$$ and $$e ≈ 2.71828$$ is the base of the natural logarithms.

![Bell Curves with σ = 0.25 and Different Values of μ](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-LqzgKZVwmsgbU3tlAZo%2F-LqzhoPwv8coPF7Dsqc3%2Fimage.png?alt=media\&token=d7b6d4f4-b0fe-4d9e-96b0-fe731deadbd1)

{% tabs %}
{% tab title="R Source" %}

```
library(ggplot2)

# uniform distribution plot (min=0, max=10)
# fun = dnorm
mu <- c(-2, -1, 1)

ggplot(data.frame(x=c(-4,4)), aes(x=x)) +
stat_function(fun=dnorm, args=list(mean = mu[1], sd = 0.25), 
        colour="black", size=1) +
stat_function(fun=dnorm, args=list(mean = mu[2], sd = 0.25), 
        colour="blue", size=1) +
stat_function(fun=dnorm, args=list(mean = mu[3], sd = 0.25), 
        colour="red", size=1) +
ggtitle("Normal Distribution of (mu=c(-2, -1, 1), sigma=0.25)")
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lt29r9Aefvt4YpHvvIU%2F-Lt2Bk4qkxo-8RgXJ5xc%2Fimage.png?alt=media\&token=1e6b89f0-86ea-4749-abac-3d0bd702e9c6)
{% endtab %}
{% endtabs %}

The value of $$σ$$ determines whether the bell curve is tall and thin or short and squat, subject always to the condition that the total area under the curve be equal to 1.&#x20;

![Bell Curves with μ = 6 and Different Values of σ](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lqzhzw8cw60rXSwLoKb%2F-Lqzi3mJK0QieiP98-D4%2Fimage.png?alt=media\&token=1203271f-3136-4fed-b7f5-855e685579eb)

{% tabs %}
{% tab title="R Source" %}

```
library(ggplot2)

# uniform distribution plot (min=0, max=10)
# fun = dnorm
mu <- 6
sd <- c(0.5, 1, 2)

ggplot(data.frame(x=c(-2,14)), aes(x=x)) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[1]), 
        colour="black", size=1) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[2]), 
        colour="blue", size=1) +
stat_function(fun=dnorm, args=list(mean = mu, sd = sd[3]), 
        colour="red", size=1) +
ggtitle("Normal Distribution of (mean=6, sigma=c(0.5, 1, 2))")
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lt29r9Aefvt4YpHvvIU%2F-Lt2DT-lEF2huu-FFSBI%2Fimage.png?alt=media\&token=5bcf799e-6f66-4958-92b5-85c3a6c45105)
{% endtab %}
{% endtabs %}

> *The probability distribution corresponding to the density function for the bell curve with parameters* $$μ$$ *and* $$σ$$ *is called the* **normal distribution** *with mean* $$μ$$ *and standard deviation* $$σ$$ .

> *A continuous random variable whose probabilities are described by the normal distribution with mean* $$μ$$ *and standard deviation* $$σ$$ *is called a* **normally distributed random variable, or a normal random variable** *for short, with mean* $$μ$$ *and standard deviation* $$σ$$  : $$X \sim N(\mu , \sigma )$$ .

> The density curve for the normal distribution is **symmetric about the mean**.

![Density Function for a Normally Distributed Random Variable with Mean μ and Standard Deviation σ](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lqzhzw8cw60rXSwLoKb%2F-LqziWX2XZgl0tfnMpdg%2Fimage.png?alt=media\&token=601bb646-ce46-45de-97fc-1c5d744c5500)

**EXAMPLE 3.** Heights of 25-year-old men in a certain region have mean 69.75 inches and standard deviation 2.59 inches. These heights are approximately normally distributed. Thus the height *X* of a randomly selected 25-year-old man is a normal random variable with mean *μ* = 69.75 and standard deviation *σ* = 2.59. Sketch a qualitatively accurate graph of the density function for *X*. Find the probability that a randomly selected 25-year-old man is more than 69.75 inches tall.

**\[ Solution ]**

Since the total area under the curve is 1, by symmetry the area to the right of 69.75 is half the total, or 0.5. But this area is precisely the probability $$P(X > 69.75)$$, the probability that a randomly selected 25-year-old man is more than 69.75 inches tall.

![Density Function for Heights of 25-Year-Old Men](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-LqzictBHqMQzHSae8MZ%2F-LqziqB0cZJGM7sBLW_G%2Fimage.png?alt=media\&token=517ada02-d340-4720-a7b9-1ce237382e6a)

{% tabs %}
{% tab title="R Source" %}

```
library(Rstat)

# 1. Compute P(X<=69.75
pnorm(69.75, mean=69.75, sd=2.59)

# 2. Plot
norm.trans(69.75, 2.59, a=0, b=69.75)

```

{% endtab %}

{% tab title="P(X < 69.75)" %}

```
> pnorm(69.75, mean=69.75, sd=2.59)
## [1] 0.5
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lt2JeIjzKbxz7Sr4GTj%2F-Lt2Llvc7WPMb3cMSHNl%2Fimage.png?alt=media\&token=3499024e-3ad6-492d-a78b-f083ed2d4a51)
{% endtab %}
{% endtabs %}

We will learn how to compute other probabilities in the next two sections.

### 4-1. Random Number Generation & Plotting using R

* Random Number Generation : `dnorm(x, mena = , sd = )`
* Plotting : `plot(x, dnorm())`

mean $$μ$$ = 69.75 , standard deviation $$σ$$ = 2.59.&#x20;

{% tabs %}
{% tab title="R Source" %}

```
# Normal distribution plot, X~N(69.76, 2.59)
mu <- 69.75
sigma <- 2.59
x <- seq((mu - 6 * sigma), (mu + 6 * sigma), length=200) # x-axis values
dnorm(x, mean=mu, sd=sigma)   # random number

main_title <- paste("Normal Distribution, X ~ N(", mu,",",sigma,")", sep="")
ylab_title <- paste("dnorm(x, mean = ", mu, ", sd = ", sigma,")", sep="")

plot(x, dnorm(x, mean=mu, sd=sigma), 
        type='l', 
        main=main_title,
        ylab=ylab_title)
abline(v=mu, col="yellow")
abline(h=0, col="gray")
```

{% endtab %}

{% tab title="Random Number" %}

```
> dnorm(x, mean=mu, sd=sigma)   # random number
  [1] 2.345901e-09 3.362418e-09 4.801916e-09 6.832792e-09 9.687297e-09 1.368447e-08 1.926078e-08 2.701100e-08 3.774229e-08 5.254562e-08 7.288962e-08 1.007432e-07 1.387351e-07 1.903610e-07 2.602497e-07 3.545057e-07 4.811463e-07
 [18] 6.506565e-07 8.766924e-07 1.176965e-06 1.574347e-06 2.098255e-06 2.786358e-06 3.686687e-06 4.860226e-06 6.384067e-06 8.355245e-06 1.089536e-05 1.415615e-05 1.832606e-05 2.363818e-05 3.037944e-05 3.890149e-05 4.963333e-05
 [35] 6.309595e-05 7.991905e-05 1.008602e-04 1.268266e-04 1.588991e-04 1.983597e-04 2.467211e-04 3.057594e-04 3.775497e-04 4.645038e-04 5.694102e-04 6.954756e-04 8.463683e-04 1.026261e-03 1.239872e-03 1.492508e-03 1.790100e-03
 [52] 2.139236e-03 2.547187e-03 3.021926e-03 3.572133e-03 4.207191e-03 4.937165e-03 5.772763e-03 6.725285e-03 7.806537e-03 9.028735e-03 1.040438e-02 1.194610e-02 1.366650e-02 1.557790e-02 1.769218e-02 2.002048e-02 2.257296e-02
 [69] 2.535849e-02 2.838435e-02 3.165595e-02 3.517649e-02 3.894668e-02 4.296445e-02 4.722465e-02 5.171887e-02 5.643521e-02 6.135812e-02 6.646833e-02 7.174278e-02 7.715472e-02 8.267373e-02 8.826598e-02 9.389446e-02 9.951931e-02
 [86] 1.050983e-01 1.105871e-01 1.159403e-01 1.211114e-01 1.260539e-01 1.307219e-01 1.350707e-01 1.390577e-01 1.426427e-01 1.457890e-01 1.484639e-01 1.506391e-01 1.522914e-01 1.534029e-01 1.539618e-01 1.539618e-01 1.534029e-01
[103] 1.522914e-01 1.506391e-01 1.484639e-01 1.457890e-01 1.426427e-01 1.390577e-01 1.350707e-01 1.307219e-01 1.260539e-01 1.211114e-01 1.159403e-01 1.105871e-01 1.050983e-01 9.951931e-02 9.389446e-02 8.826598e-02 8.267373e-02
[120] 7.715472e-02 7.174278e-02 6.646833e-02 6.135812e-02 5.643521e-02 5.171887e-02 4.722465e-02 4.296445e-02 3.894668e-02 3.517649e-02 3.165595e-02 2.838435e-02 2.535849e-02 2.257296e-02 2.002048e-02 1.769218e-02 1.557790e-02
[137] 1.366650e-02 1.194610e-02 1.040438e-02 9.028735e-03 7.806537e-03 6.725285e-03 5.772763e-03 4.937165e-03 4.207191e-03 3.572133e-03 3.021926e-03 2.547187e-03 2.139236e-03 1.790100e-03 1.492508e-03 1.239872e-03 1.026261e-03
[154] 8.463683e-04 6.954756e-04 5.694102e-04 4.645038e-04 3.775497e-04 3.057594e-04 2.467211e-04 1.983597e-04 1.588991e-04 1.268266e-04 1.008602e-04 7.991905e-05 6.309595e-05 4.963333e-05 3.890149e-05 3.037944e-05 2.363818e-05
[171] 1.832606e-05 1.415615e-05 1.089536e-05 8.355245e-06 6.384067e-06 4.860226e-06 3.686687e-06 2.786358e-06 2.098255e-06 1.574347e-06 1.176965e-06 8.766924e-07 6.506565e-07 4.811463e-07 3.545057e-07 2.602497e-07 1.903610e-07
[188] 1.387351e-07 1.007432e-07 7.288962e-08 5.254562e-08 3.774229e-08 2.701100e-08 1.926078e-08 1.368447e-08 9.687297e-09 6.832792e-09 4.801916e-09 3.362418e-09 2.345901e-09
>
```

{% endtab %}

{% tab title="Plot" %}
![](https://2234305379-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lqmt1Wp54aKlZ5eVcaS%2F-Lr1BOFlhEdp9flk6Sk2%2F-Lr1EkZyQ19tLZBNsn14%2Fimage.png?alt=media\&token=2d06e909-d3fd-4bb6-bcb5-d1c307d2d41a)
{% endtab %}
{% endtabs %}

**概率密度函数** Probability Density Function \
**均匀分布** Uniform probability distribution \
**正态分布** Normal probability distribution
