/
NormalCurveAreaBetween.Rmd
87 lines (66 loc) · 2.26 KB
/
NormalCurveAreaBetween.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Normal Area Between"
params:
a: 3.3
b: 5.5
mu: 5
sigma: 1.2
jupyter:
kernelspec:
display_name: R
language: R
name: ir
---
```{r options, eval=FALSE, include=FALSE}
options(repr.plot.width=4, repr.plot.height=2.5)
```
```{r params, include=FALSE}
if(!exists("params")) {
params<-list(a=3.3,b=5.5,mu=5,sigma=1.2)
}
a<-params$a
b<-params$b
mu<-params$mu
sigma<-params$sigma
```
```{r computed, include=FALSE}
lowerz<-round((a-mu)/sigma,2)
upperz<-round((b-mu)/sigma,2)
areaB <- round(pnorm(upperz),4)
areaA <- round(pnorm(lowerz),4)
areaBetween <- round(areaB-areaA,4)
```
```{r graphicsutils, include=FALSE}
source("graphics_utils.R")
```
We are going to find the area between the two x-values $x=`r a`$ and $x=`r b`$ for a normal distribution with mean of $\mu = `r mu`$ and with a standard deviation of $\sigma = `r sigma`$.
Here is what the area looks like:
```{r xarea, include=TRUE, echo=FALSE, fig.align="center", fig.width=4, fig.height=2.5}
normal_draw_area_between(a,b,mu,sigma)
```
We will convert both the x-values to z-values, then find the area between those z-values using the standard normal distribution (z distribution).
Lets find the "lower z-value" first. This is the z-value for the left endpoint ($x=`r a`$):
$$
z =\frac{x-\mu}{\sigma} =\frac{`r a`-`r mu`}{`r sigma`} =\frac{`r a-mu`}{`r sigma`} =`r round(lowerz,2)`
$$
Next lets find the "upper z-value". This is the z-value for the right endpoint ($x=`r b`$):
$$
z =\frac{x-\mu}{\sigma} =\frac{`r b`-`r mu`}{`r sigma`} =\frac{`r b-mu`}{`r sigma`} =`r round(upperz,2)`
$$
Now the area that we want that is between $z = `r lowerz`$ and $z = `r upperz`$
```{r zarea, include=TRUE, echo=FALSE, fig.align="center", fig.width=4, fig.height=2.5}
z_draw_area_between(lowerz,upperz)
```
We will find the area between these two z-values by subtracting the left tail areas for each one.
Using the standard normal table we find the left tail area for $z=`r upperz`$ first:
$$
\text{left tail area for `r upperz`} =`r areaB`
$$
Then we find the left tail area for $z = `r lowerz`$ next:
$$
\text{left tail area for `r lowerz`} =`r areaA`
$$
Finally subtract these two areas to find the area between the two:
$$
\text{area between}=`r areaB` - `r areaA`=`r areaBetween`
$$