-
Notifications
You must be signed in to change notification settings - Fork 173
/
foundations-mathematical.qmd
1483 lines (1181 loc) · 71.4 KB
/
foundations-mathematical.qmd
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Inference with mathematical models {#sec-foundations-mathematical}
```{r}
#| include: false
source("_common.R")
```
```{r}
#| include: false
opts_knit$set(global.par = TRUE)
par(mar = c(2, 0, 0, 0))
```
::: {.chapterintro data-latex=""}
In [Chapter -@sec-foundations-randomization] and [Chapter -@sec-foundations-bootstrapping] questions about population parameters were addressed using computational techniques.
With randomization tests, the data were permuted assuming the null hypothesis.
With bootstrapping, the data were resampled in order to measure the variability.
In many cases (indeed, with sample proportions), the variability of the statistic can be described by the computational method (as in previous chapters) or by a mathematical formula (as in this chapter).
The normal distribution is presented here to describe the variability associated with sample proportions which are taken from either repeated samples or repeated experiments.
The normal distribution is quite powerful in that it describes the variability of many different statistics, and we will encounter the normal distribution throughout the remainder of the book.
For now, however, focus is on the parallels between how data can provide insight about a research question either through computational methods or through mathematical models.
:::
## Central Limit Theorem {#sec-CLTsection}
In recent chapters, we have encountered four case studies.
While they differ in the settings, in their outcomes, and in the technique we have used to analyze the data, they all have something in common: the general shape of the distribution of the statistics (called the **sampling distribution**).\index{sampling distribution} You may have noticed that the distributions were symmetric and bell-shaped.
```{r}
#| include: false
terms_chp_13 <- c("sampling distribution", "null distribution")
```
::: {.important data-latex=""}
**Sampling distribution.**
A sampling distribution is the distribution of all possible values of a *sample statistic* from samples of a given sample size from a given population.
We can think about the sample distribution as describing how sample statistics (e.g., the sample proportion $\hat{p}$ or the sample mean $\bar{x}$) varies from one study to another.
A sampling distribution is contrasted with a data distribution which shows the variability of the *observed* data values.
The data distribution can be visualized from the observations themselves.
However, because a sampling distribution describes sample statistics computed from many studies, it cannot be visualized directly from a single dataset.
Instead, we use either computational or mathematical structures to estimate the sampling distribution and hence to describe the expected variability of the sample statistic in repeated studies.
:::
@fig-FourCaseStudies shows the null distributions in each of the four case studies where we ran 10,000 simulations.
Note that the **null distribution**\index{null distribution} is the sampling distribution of the statistic created under the setting where the null hypothesis is true.
Therefore, the null distribution will always be centered at the value of the parameter given by the null hypothesis.
In the case of the opportunity cost study, which originally had just 1,000 simulations, we have included an additional 9,000 simulations.
```{r}
#| include: false
opportunity_cost_sim_dist <- opportunity_cost |>
specify(response = decision, explanatory = group, success = "buy video") |>
hypothesize(null = "independence") |>
generate(reps = 10000, type = "permute") |>
calculate(stat = "diff in props", order = c("treatment", "control"))
sex_discrimination_sim_dist <- sex_discrimination |>
specify(response = decision, explanatory = sex, success = "promoted") |>
hypothesize(null = "independence") |>
generate(reps = 10000, type = "permute") |>
calculate(stat = "diff in props", order = c("male", "female"))
medical_consultant_sim_dist <- tibble(stat = rbinom(10000, 62, 0.1) / 62)
tappers_listeners_sim_dist <- tibble(stat = rbinom(10000, 120, 0.5) / 120)
```
```{r}
#| label: fig-FourCaseStudies
#| fig-cap: |
#| The null distribution for each of the four case studies presented previously.
#| Note that the center of each distribution is given by the value of the parameter
#| set in the null hypothesis.
#| fig-alt: |
#| Four null hypothesis histograms for examples in the book including
#| opportunity cost, sex discrimination, medical consultant, and tappers
#| and listeners. Each histogram is centered at the null value of the
#| proportion which is 0, 0, 0.1, and 0.5, respectively.
#| fig-asp: 0.7
# opportunity cost -------------------------------------------------------------
p_oc <- ggplot(opportunity_cost_sim_dist, aes(x = stat)) +
geom_histogram(binwidth = 0.013, fill = IMSCOL["blue", "full"]) +
scale_x_continuous(breaks = seq(-0.3, 0.3, 0.1), labels = label_number(accuracy = 0.1), limits = c(-0.35, 0.35)) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
) +
labs(x = expression(H[0]:~ p[T] - p[C] == 0), y = NULL) +
annotate("rect", xmin = -0.13, xmax = 0.13, ymin = 150, ymax = 450, fill = "white", alpha = 0.5) +
annotate("text", x = 0, y = 300, label = "Opportunity cost", size = 6)
# sex discrimination ----------------------------------------------------------
p_gd <- ggplot(sex_discrimination_sim_dist, aes(x = stat)) +
geom_histogram(binwidth = 0.04, fill = IMSCOL["green", "full"]) +
scale_x_continuous(breaks = seq(-0.6, 0.6, 0.2), labels = label_number(accuracy = 0.1), limits = c(-0.6, 0.6)) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
) +
labs(x = expression(H[0]:~ p[M] - p[F] == 0), y = NULL) +
annotate("rect", xmin = -0.18, xmax = 0.18, ymin = 250, ymax = 750, fill = "white", alpha = 0.5) +
annotate("text", x = 0, y = 500, label = "Sex discrimination", size = 6)
# medical consultant -----------------------------------------------------------
p_mc <- ggplot(medical_consultant_sim_dist, aes(x = stat)) +
geom_histogram(binwidth = 0.016, fill = IMSCOL["red", "full"]) +
scale_x_continuous(breaks = seq(-0.1, 0.3, 0.05), labels = label_number(accuracy = 0.01), limits = c(-0.1, 0.30)) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
) +
labs(x = expression(H[0]:~ p == 0.1), y = NULL) +
annotate("rect", xmin = 0, xmax = 0.2, ymin = 200, ymax = 600, fill = "white", alpha = 0.5) +
annotate("text", x = 0.10, y = 400, label = "Medical consultant", size = 6)
# tappers and listeners --------------------------------------------------------
p_tl <- ggplot(tappers_listeners_sim_dist, aes(x = stat)) +
geom_histogram(binwidth = 0.016, fill = IMSCOL["yellow", "full"]) +
scale_x_continuous(breaks = seq(0.30, 0.70, 0.05), labels = label_number(accuracy = 0.01), limits = c(0.3, 0.7)) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
) +
labs(x = expression(H[0]:~ p == 0.5), y = NULL) +
annotate("rect", xmin = 0.3, xmax = 0.7, ymin = 150, ymax = 450, fill = "white", alpha = 0.5) +
annotate("text", x = 0.5, y = 300, label = "Tappers + listeners", size = 6)
(p_oc + p_gd) /
(p_mc + p_tl)
```
::: {.guidedpractice data-latex=""}
Describe the shape of the distributions and note anything that you find interesting.[^13-foundations-mathematical-1]
:::
[^13-foundations-mathematical-1]: In general, the distributions are reasonably symmetric.
The case study for the medical consultant is the only distribution with any evident skew (the distribution is skewed right).
The case study for the medical consultant is the only distribution with any evident skew.
As we observed in [Chapter -@sec-data-hello], it's common for distributions to be skewed or contain outliers.
However, the null distributions we have so far encountered have all looked somewhat similar and, for the most part, symmetric.
They all resemble a bell-shaped curve.
The bell-shaped curve similarity is not a coincidence, but rather, is guaranteed by mathematical theory.
::: {.important data-latex=""}
**Central Limit Theorem for proportions.**\index{Central Limit Theorem}
If we look at a proportion (or difference in proportions) and the scenario satisfies certain conditions, then the sample proportion (or difference in proportions) will appear to follow a bell-shaped curve called the *normal distribution*.
:::
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "Central Limit Theorem")
```
An example of a perfect normal distribution is shown in @fig-simpleNormal.
Imagine laying a normal curve over each of the four null distributions in @fig-FourCaseStudies.
While the mean (center) and standard deviation (width or spread) may change for each plot, the general shape remains roughly intact.
```{r}
#| label: fig-simpleNormal
#| fig-cap: A normal curve.
#| fig-alt: A normal curve centered at 0 with a standard deviation of one.
#| fig-asp: 0.4
#| out-width: 60%
#| fig-width: 5
par(mar = c(0, 0, 0, 0))
normTail(axes = FALSE)
```
Mathematical theory guarantees that if repeated samples are taken a sample proportion or a difference in sample proportions will follow something that resembles a normal distribution when certain conditions are met.
(Note: we typically only take **one** sample, but the mathematical model lets us know what to expect if we *had* taken repeated samples.) These conditions fall into two general categories describing the independence between observations and the need to take a sufficiently large sample size.
1. Observations in the sample are **independent**.
Independence is guaranteed when we take a random sample from a population.
Independence can also be guaranteed if we randomly divide individuals into treatment and control groups.
2. The sample is **large enough**.
The sample size cannot be too small.
What qualifies as "small" differs from one context to the next, and we'll provide suitable guidelines for proportions in [Chapter -@sec-inference-one-prop].
So far we have had no need for the normal distribution.
We've been able to answer our questions somewhat easily using simulation techniques.
However, soon this will change.
Simulating data can be non-trivial.
For example, some of the scenarios encountered in [Chapter -@sec-model-mlr] where we introduced regression models with multiple predictors would require complex simulations in order to make inferential conclusions.
Instead, the normal distribution and other distributions like it offer a general framework for statistical inference that applies to a very large number of settings.
::: {.important data-latex=""}
**Technical Conditions.**
In order for the normal approximation to describe the sampling distribution of the sample proportion as it varies from sample to sample, two conditions must hold.
If these conditions do not hold, it is unwise to use the normal distribution (and related concepts like Z scores, probabilities from the normal curve, etc.) for inferential analyses.
1. **Independent observations**
2. **Large enough sample:** For proportions, at least 10 expected successes and 10 expected failures in the sample.
:::
## Normal Distribution {#sec-normalDist}
Among all the distributions we see in statistics, one is overwhelmingly the most common.
The symmetric, unimodal, bell curve is ubiquitous throughout statistics.
It is so common that people know it as a variety of names including the **normal curve**\index{normal curve}, **normal model**\index{normal model}, or **normal distribution**\index{normal distribution}.[^13-foundations-mathematical-2]
Under certain conditions, sample proportions, sample means, and sample differences can be modeled using the normal distribution.
Additionally, some variables such as SAT scores and heights of US adult males closely follow the normal distribution.
[^13-foundations-mathematical-2]: It is also introduced as the Gaussian distribution after Frederic Gauss, the first person to formalize its mathematical expression.
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "normal curve", "normal model", "normal distribution")
```
::: {.important data-latex=""}
**Normal distribution facts.**
Distributions of many variables are nearly normal, but none are exactly normal.
Thus, the normal distribution, while not perfect for any single problem, is very useful for a variety of problems.
:::
\vspace{-2mm}
In this section, we will discuss the normal distribution in the context of data to become familiar with normal distribution techniques.
In the following sections and beyond, we'll move our discussion to focus on applying the normal distribution and other related distributions to model point estimates for hypothesis tests and for constructing confidence intervals.
### Normal distribution model
The normal distribution always describes a symmetric, unimodal, bell-shaped curve.
However, normal curves can look different depending on the details of the model.
Specifically, the normal model can be adjusted using two parameters: mean and standard deviation.
As you can probably guess, changing the mean shifts the bell curve to the left or right, while changing the standard deviation stretches or constricts the curve.
@fig-twoSampleNormals-1 shows the normal distribution with mean $0$ and standard deviation $1$ (which is commonly referred to as the **standard normal distribution**\index{standard normal distribution}).
A normal distribution with mean $19$ and standard deviation $4$ is shown on the right.
@fig-twoSampleNormalsStacked shows the same two normal distributions on the same axis.
\vspace{-3mm}
```{r}
#| label: fig-twoSampleNormals
#| fig-cap: |
#| Two normal distributions with different centers and spreads.
#| fig-subcap:
#| - Mean = 0, SD = 1
#| - Mean = 19, SD = 4
#| fig-alt: |
#| Two normal curves. The first one has a mean at zero with a standard
#| deviation of one and is called the standard normal distribution. The
#| second one has a mean at 19 with a standard deviation of four.
#| fig-asp: 0.5
#| out-width: 100%
#| layout-ncol: 2
#| fig-width: 5
normals <- tibble(
x = c(rnorm(100000, mean = 0, sd = 1), rnorm(100000, mean = 19, sd = 4)),
group = c(rep(1, 100000), rep(2, 100000))
)
ggplot(normals |> filter(group == 1), aes(x = x)) +
geom_histogram(aes(y = ..density..), alpha = 0.5) +
geom_function(fun = dnorm, args = list(mean = 0, sd = 1), color = IMSCOL["blue", "full"], size = 1) +
labs(y = NULL, x = NULL) +
scale_x_continuous(breaks = -3:3) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
)
ggplot(normals |> filter(group == 2), aes(x = x)) +
geom_histogram(aes(y = ..density..), alpha = 0.5, fill = IMSCOL["green", "full"]) +
geom_function(
fun = dnorm, args = list(mean = 19, sd = 4), color = IMSCOL["green", "full"], size = 1,
linetype = "dashed"
) +
labs(y = NULL, x = NULL) +
scale_x_continuous(breaks = 19 + 4 * (-3:3)) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
)
```
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "standard normal distribution")
```
```{r}
#| label: fig-twoSampleNormalsStacked
#| fig-cap: |
#| The two normal models shown in @fig-twoSampleNormals but plotted together
#| on the same scale.
#| fig-alt: |
#| Two normal curves plotted on the same axis. One is a
#| standard normal curve with a mean at zero and a standard
#| deviation of one. The other has a mean of 19 with a standard
#| deviation of four.
#| fig-asp: 0.25
#| out-width: 100%
ggplot(normals, aes(x = x)) +
geom_function(fun = dnorm, args = list(mean = 0, sd = 1), color = IMSCOL["blue", "full"], size = 1) +
geom_function(fun = dnorm, args = list(mean = 19, sd = 4), color = IMSCOL["green", "full"], size = 1, linetype = "dashed") +
labs(y = NULL, x = NULL) +
theme(
axis.text.y = element_blank(),
panel.grid = element_blank()
)
```
\clearpage
If a normal distribution has mean $\mu$ and standard deviation $\sigma,$ we may write the distribution as $N(\mu, \sigma).$ The two distributions in @fig-twoSampleNormalsStacked can be written as
$$ N(\mu = 0, \sigma = 1)\quad\text{and}\quad N(\mu = 19, \sigma = 4) $$
Because the mean and standard deviation describe a normal distribution exactly, they are called the distribution's **parameters**\index{parameter}.
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "parameter")
```
::: {.workedexample data-latex=""}
Write down the short-hand for a normal distribution with the following parameters.
a. mean 5 and standard deviation 3
b. mean -100 and standard deviation 10
c. mean 2 and standard deviation 9
------------------------------------------------------------------------
a. $N(\mu = 5,\sigma = 3)$
b. $N(\mu = -100, \sigma = 10)$
c. $N(\mu = 2, \sigma = 9)$
:::
### Standardizing with Z scores
::: {.guidedpractice data-latex=""}
SAT scores follow a nearly normal distribution with a mean of 1500 points and a standard deviation of 300 points.
ACT scores also follow a nearly normal distribution with mean of 21 points and a standard deviation of 5 points.
Suppose Nel scored 1800 points on their SAT and Sian scored 24 points on their ACT.
Who performed better?[^13-foundations-mathematical-3]
:::
[^13-foundations-mathematical-3]: We use the standard deviation as a guide.
Nel is 1 standard deviation above average on the SAT: $1500 + 300 = 1800.$ Sian is 0.6 standard deviations above the mean on the ACT: $21+0.6 \times 5 = 24.$ In @fig-satActNormals, we can see that Nel did better compared to other test takers than Sian did, so their score was better.
```{r}
#| label: fig-satActNormals
#| fig-cap: |
#| Nel's and Sian's scores shown with the distributions of SAT and ACT scores.
#| fig-alt: |
#| Nel's SAT score is plotted on a normal curve with a
#| mean of 1500 and a standard deviation of 300. Sian's ACT
#| score is plotted on a normal curve with a mean of 21 and a
#| standard deviation of 5. Nel's score is relatively higher
#| than Sian's score.
#| fig-asp: 0.5
sat_mean <- 1500
sat_sd <- 300
act_mean <- 21
act_sd <- 5
tests <- tibble(
score = c(rnorm(100000, mean = sat_mean, sd = sat_sd), rnorm(100000, mean = act_mean, sd = act_sd)),
test = c(rep("SAT", 100000), rep("ACT", 100000))
)
p_sat <- ggplot(tests |> filter(test == "SAT"), aes(x = score)) +
geom_function(fun = dnorm, args = list(mean = sat_mean, sd = sat_sd), color = IMSCOL["black", "full"]) +
labs(y = NULL, x = NULL) +
theme(
axis.text.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank()
) +
scale_x_continuous(breaks = sat_mean + sat_sd * (-3:3)) +
annotate("segment",
x = 1800, xend = 1800, y = 0, yend = 0.001,
color = IMSCOL["blue", "full"], linetype = "dashed", size = 1
) +
annotate("segment", x = sat_mean - 4 * sat_sd, xend = sat_mean + 4 * sat_sd, y = 0, yend = 0, color = IMSCOL["black", "full"]) +
annotate("text", x = 1800, y = 0.0011, label = "Nel", color = IMSCOL["blue", "full"]) +
coord_cartesian(xlim = sat_mean + c(-1, 1) * 4 * sat_sd)
p_act <- ggplot(tests |> filter(test == "ACT"), aes(x = score)) +
geom_function(
fun = dnorm, args = list(mean = act_mean, sd = act_sd),
color = IMSCOL["black", "full"]
) +
labs(y = NULL, x = NULL) +
theme(
axis.text.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank()
) +
scale_x_continuous(breaks = act_mean + act_sd * (-3:3)) +
annotate("segment",
x = 24, xend = 24, y = 0, yend = 0.075,
color = IMSCOL["green", "full"], linetype = "dashed", size = 1
) +
annotate("segment", x = act_mean - 4 * act_sd, xend = act_mean + 4 * act_sd, y = 0, yend = 0, color = IMSCOL["black", "full"]) +
annotate("text", x = 24, y = 0.08, label = "Sian", color = IMSCOL["green", "full"]) +
coord_cartesian(xlim = act_mean + c(-1, 1) * 4 * act_sd)
p_sat /
p_act
```
\clearpage
The solution to the previous example relies on a standardization technique called a Z score, a method most commonly employed for nearly normal observations (but that may be used with any distribution).
The **Z score**\index{Z score} of an observation is defined as the number of standard deviations it falls above or below the mean.
If the observation is one standard deviation above the mean, its Z score is 1.
If it is 1.5 standard deviations *below* the mean, then its Z score is -1.5.
If $x$ is an observation from a distribution $N(\mu, \sigma),$ we define the Z score mathematically as
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "Z score")
```
$$ Z = \frac{x-\mu}{\sigma} $$
Using $\mu_{SAT}=1500,$ $\sigma_{SAT}=300,$ and $x_{Nel}=1800,$ we find Nel's Z score:
$$ Z_{Nel} = \frac{x_{Nel} - \mu_{SAT}}{\sigma_{SAT}} = \frac{1800-1500}{300} = 1 $$
::: {.important data-latex=""}
**The Z score.**
The Z score of an observation is the number of standard deviations it falls above or below the mean.
We compute the Z score for an observation $x$ that follows a distribution with mean $\mu$ and standard deviation $\sigma$ using
$$Z = \frac{x-\mu}{\sigma}$$
If the observation $x$ comes from a *normal* distribution centered at $\mu$ with standard deviation of $\sigma$, then the Z score will be distributed according to a *normal* distribution with a center of 0 and a standard deviation of 1.
That is, the normality remains when transforming from $x$ to $Z$ with a shift in both the center as well as the spread.
:::
::: {.guidedpractice data-latex=""}
Use Sian's ACT score, 24, along with the ACT mean and standard deviation to compute their Z score.[^13-foundations-mathematical-4]
:::
[^13-foundations-mathematical-4]: $Z_{Sian} = \frac{x_{Sian} - \mu_{ACT}}{\sigma_{ACT}} = \frac{24 - 21}{5} = 0.6$
Observations above the mean always have positive Z scores while those below the mean have negative Z scores.
If an observation is equal to the mean (e.g., SAT score of 1500), then the Z score is $0.$
::: {.workedexample data-latex=""}
Let $X$ represent a random variable from $N(\mu=3, \sigma=2),$ and suppose we observe $x=5.19.$ Find the Z score of $x.$ Then, use the Z score to determine how many standard deviations above or below the mean $x$ falls.
------------------------------------------------------------------------
Its Z score is given by $Z = \frac{x-\mu}{\sigma} = \frac{5.19 - 3}{2} = 2.19/2 = 1.095.$ The observation $x$ is 1.095 standard deviations *above* the mean.
We know it must be above the mean since $Z$ is positive.
:::
::: {.guidedpractice data-latex=""}
Head lengths of brushtail possums follow a nearly normal distribution with mean 92.6 mm and standard deviation 3.6 mm.
Compute the Z scores for possums with head lengths of 95.4 mm and 85.8 mm.[^13-foundations-mathematical-5]
:::
[^13-foundations-mathematical-5]: For $x_1=95.4$ mm: $Z_1 = \frac{x_1 - \mu}{\sigma} = \frac{95.4 - 92.6}{3.6} = 0.78.$ For $x_2=85.8$ mm: $Z_2 = \frac{85.8 - 92.6}{3.6} = -1.89.$
We can use Z scores to roughly identify which observations are more unusual than others.
One observation $x_1$ is said to be more unusual than another observation $x_2$ if the absolute value of its Z score is larger than the absolute value of the other observation's Z score: $|Z_1| > |Z_2|.$ This technique is especially insightful when a distribution is symmetric.
::: {.guidedpractice data-latex=""}
Which of the two brushtail possum observations in the previous guided practice is more *unusual*?[^13-foundations-mathematical-6]
:::
[^13-foundations-mathematical-6]: Because the *absolute value* of Z score for the second observation is larger than that of the first, the second observation has a more unusual head length.
\vspace{-5mm}
### Normal probability calculations
::: {.workedexample data-latex=""}
Nel from the SAT Guided Practice earned a score of 1800 on their SAT with a corresponding $Z=1.$ They would like to know what percentile they fall in among all SAT test-takers.
------------------------------------------------------------------------
Nel's **percentile**\index{percentile} is the percentage of people who earned a lower SAT score than Nel.
We shade the area representing those individuals in @fig-satBelow1800.
The total area under the normal curve is always equal to 1, and the proportion of people who scored below Nel on the SAT is equal to the *area* shaded in @fig-satBelow1800: 0.8413.
In other words, Nel is in the $84^{th}$ percentile of SAT takers.
:::
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "percentile")
```
```{r}
#| label: fig-satBelow1800
#| fig-cap: |
#| The normal model for SAT scores, shading the area of those individuals who
#| scored below Nel.
#| fig-alt: |
#| Nel's SAT score of 1800 is plotted on a normal curve
#| with mean of 1500 and standard deviation of 300. The scores
#| lower than Nel's are shaded in blue and represent roughly
#| 84% of the distribution.
#| fig-asp: 0.3
#| out-width: 60%
#| fig-width: 5
par(mar = c(2, 0, 0, 0))
normTail(m = 1500, s = 300, L = 1800, col = IMSCOL["blue", "full"])
```
We can use the normal model to find percentiles or probabilities.
A **normal probability table**\index{normal probability table}, which lists Z scores and corresponding percentiles, can be used to identify a percentile based on the Z score (and vice versa).
Statistical software can also be used.
```{r}
#| include: false
terms_chp_13 <- c(terms_chp_13, "normal probability table")
```
Normal probabilities are most commonly found using statistical software which we will show here using R.
We use the software to identify the percentile corresponding to any particular Z score.
For instance, the percentile of $Z=0.43$ is 0.6664, or the $66.64^{th}$ percentile.
The `pnorm()` function is available in default R and will provide the percentile associated with any cutoff on a normal curve.
The `normTail()` function is available in the [**openintro**](http://openintrostat.github.io/openintro/) R package and will draw the associated normal distribution curve.
```{r}
#| echo: true
#| fig-asp: 0.3
#| out-width: 60%
#| fig-width: 5
pnorm(0.43, mean = 0, sd = 1)
openintro::normTail(m = 0, s = 1, L = 0.43)
```
We can also find the Z score associated with a percentile.
For example, to identify Z for the $80^{th}$ percentile, we use `qnorm()` which identifies the **quantile** for a given percentage.
The quantile represents the cutoff value.
(To remember the function `qnorm()` as providing a cutoff, notice that both `qnorm()` and "cutoff" start with the sound "kuh".
To remember the `pnorm()` function as providing a probability from a given cutoff, notice that both `pnorm()` and probability start with the sound "puh".) We determine the Z score for the $80^{th}$ percentile using `qnorm()`: 0.84.
```{r}
#| echo: true
#| fig-asp: 0.3
#| out-width: 60%
#| fig-width: 5
qnorm(0.80, mean = 0, sd = 1)
openintro::normTail(m = 0, s = 1, L = 0.842)
```
::: {.guidedpractice data-latex=""}
Determine the proportion of SAT test takers who scored better than Nel on the SAT.[^13-foundations-mathematical-7]
:::
[^13-foundations-mathematical-7]: If 84% had lower scores than Nel, the number of people who had better scores must be 16%.
(Generally ties are ignored when the normal model, or any other continuous distribution, is used.)
### Normal probability examples
Cumulative SAT scores are approximated well by a normal model, $N(\mu=1500, \sigma=300).$
::: {.workedexample data-latex=""}
Shannon is a randomly selected SAT taker, and nothing is known about Shannon's SAT aptitude.
What is the probability that Shannon scores at least 1630 on their SATs?
------------------------------------------------------------------------
First, always draw and label a picture of the normal distribution.
(Drawings need not be exact to be useful.) We are interested in the chance they score above 1630, so we shade the upper tail.
See the normal curve below.
The $x$-axis identifies the mean and the values at 2 standard deviations above and below the mean.
The simplest way to find the shaded area under the curve makes use of the Z score of the cutoff value.
With $\mu=1500,$ $\sigma=300,$ and the cutoff value $x=1630,$ the Z score is computed as
$$ Z = \frac{x - \mu}{\sigma} = \frac{1630 - 1500}{300} = \frac{130}{300} = 0.43 $$
We use software to find the percentile of $Z=0.43,$ which yields 0.6664.
However, the percentile describes those who had a Z score *lower* than 0.43.
To find the area *above* $Z=0.43,$ we compute one minus the area of the lower tail, as seen below.
The probability Shannon scores at least 1630 on the SAT is 0.3336.
This calculation is visualized in @fig-subtractingArea.
:::
```{r}
#| label: fig-subtractingArea
#| fig-cap: |
#| Visual calculation of the probability that Shannon scores at
#| least 1630 on the SAT.
#| fig-alt: |
#| Three normal curves visualizing that probabilities can
#| be calculated using arithmetic on areas. The area above
#| 1630 can be calculated by taking the total area of one and
#| subtracting the area below 1630 (which is 0.6664). The
#| resulting value is 0.3336.
#| fig-asp: 0.45
#| fig-width: 7
par_og <- par(no.readonly = TRUE) # save original par
par(mar = c(0, 0, 0, 0), mfrow = c(2, 1))
normTail(m = 1500, s = 300, U = 1630, col = IMSCOL["blue", "full"])
X <- seq(-3.2, 3.2, 0.01)
Y <- dnorm(X)
plot(X, Y, type = "l", axes = F, xlim = c(-3.4, 16 + 3.4), ylim = c(0, 0.652))
lines(X, rep(0, length(X)))
these <- which(X <= 8)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]), c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X, Y)
# abline(h=0)
lines(c(0, 0), dnorm(0) * c(0.01, 0.99), col = COL[6], lty = 3)
lines(c(3, 8 - 3), c(0.2, 0.2), lwd = 3)
text(0, 0.45, format(c(1, 0.0001), scientific = FALSE, digits = 4)[1], cex = 1)
lines(X + 8, Y, type = "l", xlim = c(-3.4, 3.4))
lines(X + 8, rep(0, length(X)))
these <- which(X <= 0.43)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]) + 8, c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X + 8, Y)
lines(c(0, 0), dnorm(0) * c(0.01, 0.99), col = COL[6], lty = 3)
lines(8 + c(3, 8 - 3), c(0.23, 0.23), lwd = 3)
lines(8 + c(3, 8 - 3), c(0.17, 0.17), lwd = 3)
lines(c(3.72, 4.28), rep(0.45, 2), lwd = 2)
text(8, 0.45, format(0.6664, scientific = FALSE, digits = 4)[1], cex = 1)
lines(X + 8 + 8, Y, type = "l", xlim = c(-3.4, 3.4))
lines(X + 8 + 8, rep(0, length(X)))
these <- which(X > 0.43)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]) + 8 + 8, c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X + 8 + 8, Y)
lines(c(0, 0), dnorm(0) * c(0.01, 0.99), col = COL[6], lty = 3)
text(12, 0.45, "=", cex = 1.5)
text(16, 0.45, format(0.3336, scientific = FALSE, digits = 4)[1], cex = 1)
par(par_og) # restore original par
```
::: {.tip data-latex=""}
**Always draw a picture first, and find the Z score second.**
For any normal probability situation, *always always always* draw and label the normal curve and shade the area of interest first.
The picture will provide an estimate of the probability.
After drawing a figure to represent the situation, identify the Z score for the observation of interest.
:::
::: {.guidedpractice data-latex=""}
If the probability of Shannon scoring at least 1630 is 0.3336, then what is the probability they score less than 1630?
Draw the normal curve representing this exercise, shading the lower region instead of the upper one.[^13-foundations-mathematical-8]
:::
[^13-foundations-mathematical-8]: We found the probability to be 0.6664.
A picture for this exercise is represented by the shaded area below "0.6664".
::: {.workedexample data-latex=""}
Edward earned a 1400 on their SAT.
What is their percentile?
------------------------------------------------------------------------
First, a picture is needed.
Edward's percentile is the proportion of people who do not get as high as a 1400.
These are the scores to the left of 1400, as shown below.
```{r}
#| label: edward-percentile
#| fig-asp: 0.4
#| out-width: 60%
#| fig-align: center
#| fig-alt: |
#| A normal curve with a mean of 1500 and a standard
#| deviation of 300. Values less than 1400 are shaded blue in
#| the lower part of the curve. The shaded part is roughly
#| 37 percent of the graph.
#| fig-width: 5
par(mar = c(2, 0, 0, 0))
normTail(m = 1500, s = 300, L = 1400, col = IMSCOL["blue", "full"])
```
The mean $\mu=1500,$ the standard deviation $\sigma=300,$ and the cutoff for the tail area $x=1400$ are used to compute the Z score:
$$ Z = \frac{x - \mu}{\sigma} = \frac{1400 - 1500}{300} = -0.33$$
Statistical software can be used to find the proportion of the $N(0,1)$ curve to the left of $-0.33$ which is 0.3707.
Edward is at the $37^{th}$ percentile.
:::
::: {.workedexample data-latex=""}
Use the results of the previous example to compute the proportion of SAT takers who did better than Edward.
Also draw a new picture.
------------------------------------------------------------------------
If Edward did better than 37% of SAT takers, then about 63% must have done better than them, as shown below.
```{r}
#| label: edward-percentile-better
#| fig-asp: 0.4
#| out-width: 60%
#| fig-align: center
#| fig-width: 5
#| fig-alt: |
#| A normal curve with a mean of 1500 and a standard deviation of 300.
#| Values greater than 1400 are shaded blue in the upper part of the curve.
#| The shaded part is roughly 63 percent of the graph.
par(mar = c(2, 0, 0, 0))
normTail(m = 1500, s = 300, U = 1400, col = IMSCOL["blue", "full"])
```
:::
::: {.tip data-latex=""}
**Areas to the right.**
Most statistical software, as well as normal probability tables in most books, give the area to the left.
If you would like the area to the right, first find the area to the left and then subtract the amount from one.
:::
::: {.guidedpractice data-latex=""}
Stuart earned an SAT score of 2100.
Draw a picture for each part.
(a) What is their percentile?
(b) What percent of SAT takers did better than Stuart?[^13-foundations-mathematical-9]
:::
[^13-foundations-mathematical-9]: Numerical answers: (a) 0.9772.
(b) 0.0228.
Based on a sample of 100 men,[^13-foundations-mathematical-10] the heights of adults who identify as male, between the ages 20 and 62 in the US is nearly normal with mean 70.0" and standard deviation 3.3".
[^13-foundations-mathematical-10]: This sample was taken from the USDA Food Commodity Intake Database.
::: {.workedexample data-latex=""}
Kamron is 5'7" (67 inches) and Adrian is 6'4" (76 inches).
(a) What is Kamron's height percentile?
(b) What is Adrian's height percentile?
Also draw one picture for each part.
------------------------------------------------------------------------
Numerical answers, calculated using statistical software (e.g., `pnorm()` in R): (a) `r round(pnorm(67, mean = 70, sd = 3.3), 4) * 100`th percentile.
(b) `r round(pnorm(76, mean = 70, sd = 3.3), 4) * 100`th percentile.
:::
The last several problems have focused on finding the probability or percentile for a particular observation.
What if you would like to know the observation corresponding to a particular percentile?
::: {.workedexample data-latex=""}
Yousef's height is at the $40^{th}$ percentile.
How tall are they?
------------------------------------------------------------------------
As always, first draw the picture.
```{r}
#| fig-asp: 0.4
#| out-width: 60%
#| fig-align: center
#| fig-width: 5
par(mar = c(2, 0, 0, 0))
normTail(70, 3.3, L = qnorm(0.4, 70, 3.3), col = IMSCOL["blue", "full"])
text(67, 0.03, "40%\n(0.40)", cex = 1, col = IMSCOL["black", "full"])
```
In this case, the lower tail probability is known (0.40), which can be shaded on the diagram.
We want to find the observation that corresponds to the known probability of 0.4.
We can find the observation in two different ways: using the height curve seen above or using the Z score associated with the standard normal curve centered at zero with a standard deviation of one.
If you have access to software (like R, code seen below) that allows you to specify the mean and standard deviation of the normal curve, you can calculate the observed value on the curve (i.e., Yousef's height) directly.
```{r}
qnorm(0.4, mean = 70, sd = 3.3)
```
Yousef is 69.2 inches tall.
That is, Yousef is about 5'9" (this is notation for 5-feet, 9-inches).
Without access to flexible software, you will need the information given by a standard normal curve (a normal curve centered at zero with a standard deviation of one).
First, determine the Z score associated with the $40^{th}$ percentile.
Because the percentile is below 50%, we know $Z$ will be negative.
Statistical software provides the $Z$ value to be $-0.25.$
```{r}
#| echo: true
qnorm(0.4, mean = 0, sd = 1)
```
Knowing $Z_{Yousef}=-0.25$ and the population parameters $\mu=70$ and $\sigma=3.3$ inches, the Z score formula can be set up to determine Yousef's unknown height, labeled $x_{Yousef}$:
$$ -0.253 = Z_{Yousef} = \frac{x_{Yousef} - \mu}{\sigma} = \frac{x_{Yousef} - 70}{3.3} $$
Solving for $x_{Yousef}$ yields the height 69.2 inches.
Again, Yousef is about 5'9".
:::
::: {.workedexample data-latex=""}
What is the adult male height at the $82^{nd}$ percentile?
------------------------------------------------------------------------
In order to practice using Z scores, we will use the standard normal curve to solve the problem.
Again, we draw the figure first.
```{r}
#| label: height82Perc
#| fig-asp: 0.4
#| out-width: 60%
#| fig-align: center
#| fig-width: 5
par(mar = c(2, 0, 0, 0))
normTail(70, 3.3, L = qnorm(0.82, 70, 3.3), col = IMSCOL["blue", "full"])
text(70, 0.04, "82%\n(0.82)", cex = 1, col = IMSCOL["black", "full"])
text(74.3, 0.02, "18%\n(0.18)", cex = 1, col = IMSCOL["black", "full"])
```
And calculate the Z value associated with the $82^{nd}$ percentile:
```{r}
#| echo: true
qnorm(0.82, mean = 0, sd = 1)
```
Next, we want to find the Z score at the $82^{nd}$ percentile, which will be a positive value (because the percentile is bigger than 50%).
Using `qnorm()`, the $82^{nd}$ percentile corresponds to $Z=0.92.$ Finally, the height $x$ is found using the Z score formula with the known mean $\mu,$ standard deviation $\sigma,$ and Z score $Z=0.92$:
$$ 0.92 = Z = \frac{x-\mu}{\sigma} = \frac{x - 70}{3.3} $$
This yields 73.04 inches or about 6'1" as the height at the $82^{nd}$ percentile.
:::
::: {.guidedpractice data-latex=""}
Using Z scores, answer the following questions.
(a) What is the $95^{th}$ percentile for SAT scores?\
(b) What is the $97.5^{th}$ percentile of the male heights? As always with normal probability problems, first draw a picture.[^13-foundations-mathematical-11]
:::
[^13-foundations-mathematical-11]: Remember: draw a picture first, then find the Z score.
(We leave the pictures to you.) The Z score can be found by using the percentiles and the normal probability table.
(a) We look for 0.95 in the probability portion (middle part) of the normal probability table, which leads us to row 1.6 and (about) column 0.05, i.e., $Z_{95}=1.65.$ Knowing $Z_{95}=1.65,$ $\mu = 1500,$ and $\sigma = 300,$ we setup the Z score formula: $1.65 = \frac{x_{95} - 1500}{300}.$ We solve for $x_{95}$: $x_{95} = 1995.$ (b) Similarly, we find $Z_{97.5} = 1.96,$ again setup the Z score formula for the heights, and calculate $x_{97.5} = 76.5.$
::: {.guidedpractice data-latex=""}
Using Z scores, answer the following questions.
(a) What is the probability that a randomly selected male adult is at least 6'2" (74 inches)?\
(b) What is the probability that a male adult is shorter than 5'9" (69 inches)?[^13-foundations-mathematical-12]
:::
[^13-foundations-mathematical-12]: Numerical answers: (a) 0.1131.
(b) 0.3821.
::: {.workedexample data-latex=""}
What is the probability that a randomly selected adult male is between 5'9" and 6'2"?
------------------------------------------------------------------------
These heights correspond to 69 inches and 74 inches.
First, draw the figure.
The area of interest is no longer an upper or lower tail.
```{r}
#| fig-asp: 0.4
#| out-width: 60%
#| fig-align: center
#| fig-width: 5
par(mar = c(2, 0, 0, 0))
normTail(70, 3.3, M = c(69, 74), col = IMSCOL["blue", "full"])
```
The total area under the curve is 1.
If we find the area of the two tails that are not shaded (from the previous Guided Practice, these areas are $0.3821$ and $0.1131$), then we can find the middle area:
```{r}
#| fig-asp: 0.25
#| fig-align: center
#| out-width: 100%
X <- seq(-3.2, 3.2, 0.01)
Y <- dnorm(X)
par(mar = c(2, 0, 0, 0))
plot(X, Y, type = "l", axes = F, xlim = c(-3.4, 24 + 3.4), ylim = c(0, 0.6), xlab = NA, ylab = NA)
lines(X, rep(0, length(X)))
these <- which(X <= 8)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]), c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X, Y)
lines(c(3, 8 - 3), c(0.2, 0.2), lwd = 3)
lines(X + 8, Y, type = "l")
lines(X + 8, rep(0, length(X)))
these <- which(X < -0.303)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]) + 8, c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X + 8, Y)
lines(8 + c(3, 8 - 3), c(0.2, 0.2), lwd = 3)
lines(X + 16, Y, type = "l")
lines(X + 16, rep(0, length(X)))
these <- which(X > 1.212)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]) + 16, c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X + 16, Y)
lines(16 + c(3, 8 - 3), c(0.23, 0.23), lwd = 3)
lines(16 + c(3, 8 - 3), c(0.17, 0.17), lwd = 3)
lines(X + 24, Y, type = "l", xlim = c(-3.4, 3.4))
lines(X + 24, rep(0, length(X)))
these <- which(X > -0.303 & X < 1.212)
polygon(c(X[these[1]], X[these], X[rev(these)[1]]) + 24, c(0, Y[these], 0), col = IMSCOL["blue", "full"])
lines(X + 24, Y)
text(0, 0.53, "1.0000")
text(8, 0.53, "0.3821")
text(16, 0.53, "0.1131")
text(24, 0.53, "0.5048")
```
That is, the probability of being between 5'9" and 6'2" is 0.5048.
:::
::: {.guidedpractice data-latex=""}
Find the percent of SAT takers who earn between 1500 and 2000.[^13-foundations-mathematical-13]
:::
[^13-foundations-mathematical-13]: This is an abbreviated solution.
(Be sure to draw a figure!) First find the percent who get below 1500 and the percent that get above 2000: $Z_{1500} = 0.00 \to 0.5000$ (area below), $Z_{2000} = 1.67 \to 0.0475$ (area above).
Final answer: $1.0000-0.5000 - 0.0475 = 0.4525.$
::: {.guidedpractice data-latex=""}
What percent of adult males are between 5'5" and 5'7"?[^13-foundations-mathematical-14]
:::
[^13-foundations-mathematical-14]: 5'5" is 65 inches.
5'7" is 67 inches.
Numerical solution: $1.000 - 0.0649 - 0.8183 = 0.1168,$ i.e., 11.68%.
## Quantifying the variability of a statistic
As seen in later chapters, it turns out that many of the statistics used to summarize data (e.g., the sample proportion, the sample mean, differences in two sample proportions, differences in two sample means, the sample slope from a linear model, etc.) vary according to the normal distribution seen above.
The mathematical models are derived from the normal theory, but even the computational methods (and the intuitive thinking behind both approaches) use the general bell-shaped variability seen in most of the distributions constructed so far.
### 68-95-99.7 rule
Here, we present a useful general rule for the probability of falling within 1, 2, and 3 standard deviations of the mean in the normal distribution.
The rule will be useful in a wide range of practical settings, especially when trying to make a quick estimate without a calculator or Z table.
```{r}
#| label: fig-er6895997
#| fig-cap: |
#| Probabilities for falling within 1, 2, and 3 standard deviations of the mean
#| in a normal distribution.
#| fig-alt: |
#| A normal curve showing the area within one standard
#| deviation of the mean (which is 0.68), the area within two
#| standard deviations of the mean (which is 0.95), and the are
#| within three standard deviations of the mean (which is 0.997).
#| fig-asp: 0.3
#| out-width: 60%
par(mar = c(2, 0, 0, 0))
X <- seq(-4, 4, 0.01)
Y <- dnorm(X)
plot(X, Y, type = "n", axes = F, ylim = c(0, 0.4), xlim = c(-3.2, 3.2), xlab = NA, ylab = NA)
abline(h = 0, col = IMSCOL["black", "full"])
axis(1, at = -3:3, label = expression(
mu - 3 * sigma, mu - 2 * sigma, mu - sigma, mu,
mu + sigma, mu + 2 * sigma, mu + 3 * sigma
))
ii <- c(1, 2, 3)
jj <- c(1, 1, 1)
for (i in 3:1) {
these <- (X >= i - 1 & X <= i)
polygon(c(i - 1, X[these], i), c(0, Y[these], 0), col = IMSCOL[ii[i], jj[i]], border = IMSCOL[ii[i], jj[i]])
these <- (X >= -i & X <= -i + 1)
polygon(c(-i, X[these], -i + 1), c(0, Y[these], 0), col = IMSCOL[ii[i], jj[i]], border = IMSCOL[ii[i], jj[i]])
}
# ===> label 99.7 <===#
arrows(-3, 0.03, 3, 0.03, code = 3, col = "#444444", length = 0.15)
text(0, 0.02, "99.7%", pos = 3)
# ===> label 95 <===#
arrows(-2, 0.13, 2, 0.13, code = 3, col = "#444444", length = 0.15)
text(0, 0.12, "95%", pos = 3)
# ===> label 68 <===#
arrows(-1, 0.23, 1, 0.23, code = 3, col = "#444444", length = 0.15)
text(0, 0.22, "68%", pos = 3)
lines(X, Y, col = "#888888")
abline(h = 0, col = "#AAAAAA")
```
::: {.guidedpractice data-latex=""}
Use `pnorm()` (or a Z table) to confirm that about 68%, 95%, and 99.7% of observations fall within 1, 2, and 3, standard deviations of the mean in the normal distribution, respectively.
For instance, first find the area that falls between $Z=-1$ and $Z=1,$ which should have an area of about 0.68.
Similarly there should be an area of about 0.95 between $Z=-2$ and $Z=2.$[^13-foundations-mathematical-15]
:::
[^13-foundations-mathematical-15]: First draw the pictures.
To find the area between $Z=-1$ and $Z=1,$ use `pnorm()` or the normal probability table to determine the areas below $Z=-1$ and above $Z=1.$ Next verify the area between $Z=-1$ and $Z=1$ is about 0.68.
Repeat this for $Z=-2$ to $Z=2$ and for $Z=-3$ to $Z=3.$