forked from PeterKDunn/SRM-Textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
17-Tools-DistributionsAndModels.Rmd
executable file
·1947 lines (1520 loc) · 64.2 KB
/
17-Tools-DistributionsAndModels.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
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
# Distributions and models {#SamplingDistributions}
```{r, child = if (knitr::is_html_output()) {'./introductions/17-Tools-DistributionsAndModels-HTML.Rmd'} else {'./introductions/17-Tools-DistributionsAndModels-LaTeX.Rmd'}}
```
## Introduction {#Chap17-Intro}
In the decision-making process used in statistics (Sect. \@ref(DecisionMaking)), an *assumption* is made about a parameter that describes the population.
Then, we observe just one of the many different samples that could be drawn from this population.
The sample statistic can vary, depending on which sample we observe.
::: {.importantBox .important data-latex="{iconmonstr-warning-8-240.png}"}
Remember: Studying a sample leads to the following observations:
\vspace{-2ex}
* Every sample is likely to be different.
* Our sample is one of countless possible samples from the population.
* Every sample is likely to produce a different value for the sample statistic.
* Hence we only observe one of the many possible values for the sample statistic.
\vspace{-2ex}
Since many values for the sample statistic are possible, the possible values of the sample statistic vary (called *sampling variation*) and have a *distribution* (called a *sampling distribution*).
:::
Based on the assumption about the parameter, the values of the statistic that we could reasonably *expect* from these all possible samples can be described.
The challenge is that we only study *one* of these many possible samples.
The values of the statistic that we can reasonably *expect* from all possible samples can be described using a *distribution*: that is, by describing what values the statistic can take from all these samples, and how often.
For example, if I deal 15 cards, the *statistic* could be $\hat{p}$, 'the proportion of red cards in a hand of 15'.
Specifically, this is a *sampling distribution*, since the distribution is describing the distribution of a sample statistic (in this case, $\hat{p}$).
The *distribution* would describe what values of $\hat{p}$ are possible, and how likely each one is to be observed.
Under certain circumstances, many sample statistics have a similar-shaped distribution: a *bell-shaped (or normal) distribution*.
We study this distribution, as it often used to describe what values of the statistic are reasonable to observe.
## Distributions: an example
<div style="float:right; width: 222x; border: 1px; padding:10px">
<img src="Illustrations/measure-289399_640.jpg" width="200px"/>
</div>
Consider the heights and weights of *all* American adult females aged 18 or over.
(the populations).
Clearly, the height and weights of *all* American adult females is unknown: no-one has ever, or could ever realistically, measure the heights and weights of every American adult female.
However, the *National Health and Nutrition Examination Survey* (NHANES) data uses a 'nationally *representative* sample' of Americans so is a large, representative *sample* of Americans [@data:NHANES3:Data; @data:NHANES3].
The NHANES data includes the heights and weights of those in the sample; the *distributions* are shown in Fig.\ \@ref(fig:F18HeightsWeights).
```{r, F18HeightsWeights, out.width = '90%', fig.width=7.5, fig.height=3, fig.align='center', fig.cap="The heights (left) and weights (right) of females in the USA aged 18 and over, from the 2009--2012 NHANES survey ($n = 3742$)"}
F18 <- subset( NHANES,
(Age > 18) & (Gender == "female") )
par( mfrow = c(1, 2))
hist(F18$Height,
main = "Heights of adult females\nin the USA",
xlab = "Heights (in cm)",
ylab = "Number",
col = plot.colour,
las = 1,
breaks = seq(120, 200, by = 5))
hist(F18$Weight,
main = "Weights of adult females\nin the USA",
xlab = "Weights (in kg)",
ylab = "Number",
col = plot.colour,
las = 1,
breaks = seq(20, 250, by = 15))
```
Since the sample is representative, and the sample size is large ($n = 3742$), the distribution of the heights and weights in the sample probably will approximately resemble the population.
However, *every sample of the same size is likely to be different*, so a different sample of Americans would produce a different (though probably similar) histogram.
However, we could *assume* a model for the heights and weights of adult American females in the *population* that gave rise to the sample histograms.
The *sample* heights look like they may have come from a *population* of heights that are roughly symmetrical, centred around approximatey $162$cm.
The *sample* weights, though, do *not* look like they may have come from a roughly symmetric *population* of weights; they are right skewed.
Based on this, a distribution of the population heights can be proposed that may have produced the histogram of the sample.
This *model* for the distribution of heights of adult American women is roughly bell-shaped.
These types of distributions are called *normal distributions*.
A model is a *theoretical* idea that might be a useful description of the heights of American adult females in the *population*.
Suppose a *model* for the heights of American adult females is adopted that describes the heights as:
* having a bell-shaped (normal) distribution,
* with a *mean height* of $162$cm, and
* a *standard deviation* of $7$cm.
Then, the *distribution* of the heights of American adult females would look like Fig. \@ref(fig:HeightsModel) (left panel).
That is, most American adult females are between about $155$ and $169$cm, and very few are taller than $183$cm or shorter than $141$cm.
```{r HeightsModel, out.width='95%', results='hide', fig.cap="A model for the heights of American adult females, showing 1, 2 and 3 standard deviations either side of the mean (left); the model for heights of American adult females, plus the histogram from one specific sample of size $n = 200$ (right)", fig.align="center", fig.width=7.75, fig.height=2.5}
HT.mn <- round( mean( F18$Height, na.rm = TRUE) )
HT.sd <- round(sd( F18$Height, na.rm = TRUE))
par( mfrow = c(1, 2),
mar = c(5, 0.25, 4, 0.25))
hide <- plotNormal(mu = HT.mn,
sd = HT.sd,
showZ = TRUE,
xlab = "Height (in cm)",
main = "Heights of American\nadult females")
set.seed(140430)
num.heights <- 200
x <- seq( HT.mn - 4 * HT.sd,
HT.mn + 4 * HT.sd,
length = 100)
y <- dnorm( x,
mean = HT.mn,
sd = HT.sd)
# HISTOGRAM
HT.data <- rnorm( num.heights,
mean = HT.mn,
sd = HT.sd)
out <- hist(HT.data,
breaks = seq(130, 190, by = 5),
col = plot.colour,
border = plot.colour,
xlab = "Heights (in cm)",
axes = FALSE,
plot = TRUE,
xlim = range(x),
main = "Heights of American adult\nfemales: model, and one sample",
sub = "for one sample of size 200",
ylab = "")
axis(side = 1 )
y <- y / max(y) * max (out$counts)
lines( y ~ x,
lwd = 2,
col = "black")
# Plot x-axis
abline(v = 0,
col = "grey",
lwd = 2)
# Plot the mean
abline(h = 0,
col = "grey",
lwd = 2)
```
Since we do not know the heights of all American females, this model represents an idealised, or *assumed*, picture of the histogram of the heights of all American adult females in the *population*.
The sample of females in Fig.\ \@ref(fig:F18HeightsWeights) (left panel) could reasonably have come from this population.
If this model is accurate, the distribution of heights in any *sample* may be shaped a bit like this... but *sampling variation* exists, so every sample will be a bit different.
While any one sample will look a bit different than this model, the model captures the general feel of the histogram from many of these samples.
The model is like the 'average' of many sample histograms.
```{r HeightsModelMovie, animation.hook="gifski", dev=if (is_latex_output()){"pdf"}else{"png"}}
if (knitr::is_html_output()) {
set.seed(14040)
HT.mn <- round( mean( F18$Height, na.rm = TRUE) )
HT.sd <- round(sd( F18$Height, na.rm = TRUE))
num.heights <- 200
x <- seq( HT.mn - 4 * HT.sd,
HT.mn + 4 * HT.sd,
length = 100)
y <- dnorm( x,
mean = HT.mn,
sd = HT.sd)
NumSampleHists <- 20
for (i in (1:(NumSampleHists + 1))){
# HISTOGRAMS
if ( i > 1 ){
HT.data <- rnorm( num.heights,
mean = HT.mn,
sd = HT.sd)
out <- hist(HT.data,
breaks = seq(130, 190, by = 5),
col = plot.colour,
border = plot.colour,
xlab = "Heights (in cm)",
axes = FALSE,
plot = TRUE,
xlim = range(x),
main = "Model for the heights of\nAustralian adult males",
sub = paste( "Sample number:", (i - 1)),
ylab = "")
axis(side = 1)
}
# Plot the normal distribution
if ( i == 1 ) {
plot( range(x), c(0, 1),
axes = FALSE,
type = "n",
main = "Model for the heights of\nAustralian adult males",
xlab = "Height (in cm)",
ylab = "")
axis(side = 1)
lines( (y/max(y)) ~ x,
lwd = 2,
col = "black")
} else {
y <- y/max(y) * max (out$counts)
lines( y ~ x,
lwd = 2,
col = "black")
}
# Plot x-xaxis
abline(v = 0,
col = "grey",
lwd = 2)
# Plot the mean
abline(h = 0,
col = "grey",
lwd = 2)
}
}
```
This *bell-shaped distribution* is called a *normal distribution* or a *normal model*.
A normal distribution is a way of *modelling* the population.
A *model* is a theoretical or ideal concept.
In the same way that a model skeleton isn't $100$% accurate and certainly not exactly like *your* skeleton, it suitably approximates reality.
None of us probably have a skeleton *exactly* like the model, but the model is still useful and helpful.
Likewise, no variable has *exactly* a normal distribution, but the model is still useful and helpful.
The model is a *theoretical* way of describing the distribution in the population; it does not represent any particular sample of data.
If this model turns out to be poor at describing what appears in samples, the *parameters* of the model (the values of $\mu$ and $\sigma$) can be adjusted so the model *does* describe the sample data well.
In fact, evidence suggests that the average height of Americans has been increasing (for example, [see this webpage](https://ncdrisc.org/data-downloads-height.html)) and so the mean of the model may need to be changed to remain a good model.
The heights of adult American females is assumed to have a *normal distribution*.
Normal distribution play a large role in the chapters ahead, so we study normal distributions in this chapter.
All *normal distributions* have these properties:
* Normal distributions are symmetric about the mean.\tightlist
* No upper limit or lower limit exists, in theory, for the variable.
Of course, the chance that some values occur is essentially zero (e.g., a female taller than $350$cm).
These properties are true for *all* normal distributions, whatever the mean $\mu$ and whatever the standard deviation $\sigma$.
## The 68--95--99.7 (empirical) rule {#EmpiricalRule}
One of the most important properties of a normal distribution is given by the *68--95--99.7 rule*, also called the *empirical rule*.
:::{.definition #EmpiricalRule name="The 68--95-99.7 rule"}
For *any* bell-shaped distribution, *approximately*
* $68$% of observations lie within one standard deviation of the mean.
* $95$% of observations lie within two standard deviations of the mean.
* $99.7$\% of observations lie within three standard deviations of the mean.
:::
:::{.example #EmpiricalAmericanFemales name="Using the 68--95--99.7 rule"}
The model proposed for the height of adult American females is a *normal* distribution, with a mean of of $162$cm, and a *standard deviation* of $7$cm.
Using this model:
* about $68$% of women have heights between $162 - 7 = 155$ and $162 + 7 = 169$cm.
* about $95$% of women have heights between $162 - (2\times 7) = 148$ and $162 + (2\times 7) = 176$cm.
* about $99.7$% of women have heights between $162 - (3\times 7) = 141$ and $162 + (3\times 7) = 183$cm.
:::
## Standardising ($z$-scores) {#z-scores}
Since the 68--95--99.7 rule (Sect. \@ref(EmpiricalRule)) applies for all normal distributions, the percentages in the rule only depend on how many standard deviations ($\sigma$) a value ($x$) is from the mean ($\mu$).
This information can be used to learn more about how values are distributed.
::: {.example #HeightsExer1 name="The 68--95--99.7 rule"}
Suppose heights of American adult females have a mean of $\mu = 162$cm, and a standard deviation of $\sigma = 7$cm, and (approximately) follow a normal distribution.
Using this model, what proportion of American adult females are *taller* than $169$cm?
:::
From a picture of the situation (Fig. \@ref(fig:HtsExer1), left panel), $162 + 7 = 169$cm is one standard deviation *above* the mean.
Since $68$% of values are within one standard deviation of the mean, $32$% are outside that range, smaller or larger.
Hence, $16$% are taller than one standard deviation above the mean, so the answer is about $16$%.
(Another $16$% are less than one standard deviation *below* the mean, or less than $175 - 7 = 168$cm in height.)
Again, the percentages only depend on how many standard deviations ($\sigma$) the value ($x$) is from the mean ($\mu$), and not the actual values of $\mu$ and $\sigma$.
```{r HtsExer1, fig.cap="Left: What proportion of American adult females are taller than $169$cm? Right: What proportion of American adult females are shorter than $148$cm?", fig.align="center", fig.width=7.5, fig.height=3, out.width='90%'}
par( mfrow = c(1, 2),
mar = c(5, 0.5, 5, 0.5))
out <- plotNormal(mu = HT.mn,
sd = HT.sd,
ylim = c(0, 0.075),
xlab = "Height (in cm)")
shadeNormal(out$x,
out$y,
lo = 0,
hi = HT.mn - HT.sd,
col = plot.colour)
shadeNormal(out$x,
out$y,
hi = 200,
lo = HT.mn + HT.sd,
col = plot.colour)
abline( v = c(HT.mn - HT.sd,
HT.mn + HT.sd),
col = "grey")
arrows(x0 = HT.mn - HT.sd + 0.5,
y0 = 0.06,
x1 = HT.mn + HT.sd - 0.5,
y1 = 0.06,
code = 3, # Arrow both ends
length = 0.10,
angle = 15)
text(x = HT.mn,
y = 0.06,
"68%",
cex = 0.9,
pos = 3)
arrows(x0 = HT.mn + HT.sd + 0.5,
y0 = 0.06,
x1 = 179,
y1 = 0.06,
code = 1,
length = 0.10,
angle = 15)
lines( x = c(179, 183),
y = c(0.06, 0.06),
lty = 2)
text(x = 148,
y = 0.06,
"16%",
cex = 0.9,
pos = 3)
arrows(x0 = HT.mn - HT.sd - 0.5,
y0 = 0.06,
x1 = 145,
y1 = 0.06,
code = 1,
length = 0.10,
angle = 15)
lines( x = c(145, 141),
y = c(0.06, 0.06),
lty = 2)
text(x = 176,
y = 0.06,
"16%",
cex = 0.9,
pos = 3)
out <- plotNormal(mu = HT.mn,
sd = HT.sd,
ylim = c(0, 0.075),
xlab = "Height (in cm)")
shadeNormal(out$x,
out$y,
lo = 0,
hi = HT.mn - 2 * HT.sd,
col = plot.colour)
shadeNormal(out$x,
out$y,
lo = HT.mn + 2 * HT.sd,
hi = 400,
col = plot.colour)
abline( v = c(HT.mn - 2 * HT.sd,
HT.mn + 2 * HT.sd),
col = "grey")
arrows(x0 = HT.mn - 2 * HT.sd + 0.5,
y0 = 0.06,
x1 = HT.mn + 2 * HT.sd - 0.5,
y1 = 0.06,
code = 3, # Arrow both ends
length = 0.10,
angle = 15)
text(x = HT.mn,
y = 0.06,
"95%",
cex = 0.9,
pos = 3)
arrows(x0 = HT.mn + 2 * HT.sd + 0.5,
y0 = 0.06,
x1 = 179,
y1 = 0.06,
code = 1,
length = 0.10,
angle = 15)
lines( x = c(179, 183),
y = c(0.06, 0.06),
lty = 2)
text(x = 179,
y = 0.06,
"2.5%",
cex = 0.9,
pos = 3)
arrows(x0 = HT.mn - 2 * HT.sd - 0.5,
y0 = 0.06,
x1 = 145,
y1 = 0.06,
code = 1,
length = 0.10,
angle = 15)
lines( x = c(145, 141),
y = c(0.06, 0.06),
lty = 2)
text(x = 144,
y = 0.06,
"2.5%",
cex = 0.9,
pos = 3)
```
::: {.example #HeightsExer2 name="The 68--95--99.7 rule"}
Consider again the heights of American adult females.
Using this model, what proportion are *shorter* than $148$cm?
Again, drawing the situation is helpful (Fig. \@ref(fig:HtsExer1), right panel).
Since $162 - (2\times 7) = 148$, then $148$cm is two standard deviation *below* the mean.
Since $95$% of values are within two standard deviation of the mean, $5$% are outside that range (half smaller, half larger; see Fig. \@ref(fig:HtsExer1), right panel), so that $2.5$% are *shorter* than $148$cm.
(Another $2.5$% are *taller* than $162 + 14 = 176$cm.)
:::
Again, the percentages only depend on how many standard deviations ($\sigma$) the value ($x$) is from the mean ($\mu$).
The number of standard deviations that an observation is from the mean is called a *$z$-score*.
A $z$-score is computed using
\[
z = \frac{ x - \mu}{\sigma},
\]
where $\sigma$ is the standard deviation measuring the variation in the $x$-values.
Converting values to $z$-scores is called *standardising*.
::: {.definition #zScore name="z-score"}
A *$z$-score* measures how many standard deviations a value is from the mean.
In symbols:
\begin{equation}
z = \frac{x - \mu}{\sigma},
(\#eq:zscores)
\end{equation}
where $x$ is the value, $\mu$ is the mean of the distribution, and $\sigma$ is the standard deviation of the distribution (measuring the variation in the $x$-values).
:::
The $z$-score is the *number of standard deviations the observation is away from the mean*, and is also called the *standardised value* or *standard score*, and is calculated using Equation \@ref(eq:zscores).
Note that:
* $z$-scores are negative for observations *below* the mean.
* $z$-scores are positive for observations *above* the mean.
* $z$-scores have no units (that is, not measured in kg, or cm, etc.).
::: {.example #HeightsExer3 name="$z$-scores"}
In Example \@ref(exm:HeightsExer1), the $z$-score for a height of $169$cm is
\[
z = \frac{x-\mu}{\sigma} = \frac{169 - 162}{7} = 1,
\]
one standard deviation *above* the mean.
In Example \@ref(exm:HeightsExer2), the $z$-score for a height of $148$cm is
\[
z = \frac{x-\mu}{\sigma} = \frac{148 - 162}{7} = -2,
\]
two standard deviations *below* the mean (the $z$-score is *negative*).
:::
::: {.example #EmpiricalRuleZ name="The 68--95--99.7 rule"}
Consider the model for the heights of American adult females: a normal distribution, mean $\mu = 162$, standard deviation $\sigma = 7$ (Fig.\ \@ref(fig:HeightsModel)).
Using this model:
* A height of $175$cm is zero standard deviations from the mean: $z = 0$.
* $155$cm is one standard deviation *below* the mean: $z = -1$.
* $169$cm is one standard deviation *above* the mean: $z = 1$.
* $148$cm and $176$cm are two standard deviations from the mean: $z = -2$ and $z = 2$ respectively.
* $141$cm and $183$cm are three standard deviations from the mean: $z = -3$ and $z = 3$ respectively.
:::
## Approximating percentages using the 68--95--99.7 rule {#ApproxProbs}
As we have seen above, percentages under normal distributions can be *approximated* using the [68--95--99.7 rule](#def:EmpiricalRule).
::: {.example #Height160 name="Normal distribution areas"}
Suppose again that heights of American adult females have a mean of $\mu = 162$cm, and a standard deviation of $\sigma = 7$cm, and (approximately) follow a normal distribution (Fig.\ \@ref(fig:HtsEmpirical)).
To find the proportion of females *shorter* than $150$cm, first draw the situation (Fig.\ \@ref(fig:HtsExer3)).
:::
```{r HtsEmpirical, fig.cap="The empirical rule and heights of American adult females", fig.align="center", fig.width=6.0, fig.height=2.75, out.width='62.5%'}
out <- plotNormal(HT.mn,
HT.sd,
xlab = "Heights (in cm)")
mtext(expression( "("*italic(z)==0*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn)
mtext(expression( "("*italic(z)==1*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd)
mtext(expression( "("*italic(z)==2*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd*2)
mtext(expression( "("*italic(z)==3*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd*3)
mtext(expression( "("*italic(z)==-1*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd)
mtext(expression( "("*italic(z)==-2*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd*2)
mtext(expression( "("*italic(z)==-3*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd*3)
```
```{r HtsExer3, fig.cap="What proportion of Australian adult males are shorter than 160cm?", fig.align="center", fig.width=7.0, fig.height=3.00, out.width='70%'}
out <- plotNormal(HT.mn,
HT.sd,
ylim = c(0, 0.085),
xlab = "Heights (in cm)")
shadeNormal(out$x,
out$y,
lo = 140,
hi = 160,
col = plot.colour)
mtext(expression( "("*italic(z)==0*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn)
mtext(expression( "("*italic(z)==1*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd)
mtext(expression( "("*italic(z)==2*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd*2)
mtext(expression( "("*italic(z)==3*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn + HT.sd*3)
mtext(expression( "("*italic(z)==-1*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd)
mtext(expression( "("*italic(z)==-2*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd*2)
mtext(expression( "("*italic(z)==-3*")"),
side = 1,
line = 2,
cex = 0.8,
at = HT.mn - HT.sd*3)
z <- -2.14
x <- 160
lines( x = c(x, x),
y = c(0, max(out$y) * 0.7),
col = "grey")
text(x = x,
y = max(out$y) * 0.7,
pos = 2,
cex = 0.9,
labels = "160 cm")
text(x = 175,
y = 0.070,
pos = 3,
cex = 0.9,
labels = "95%")
text(x = 159,
y = 0.070,
pos = 3,
cex = 0.9,
labels = "2.5%")
text(x = 194,
y = 0.070,
pos = 3,
cex = 0.9,
labels = "2.5%")
abline(v = c(161, 189),
col = "grey")
arrows( x0 = 155,
x1 = 160.5,
y0 = 0.070,
y1 = 0.070,
length = 0.10,
angle = 15,
lwd = 1)
lines( x = c(150, 155),
y = c(0.070, 0.070),
lwd = 1,
lty = 2)
arrows( x0 = 195,
x1 = 189.5,
y0 = 0.070,
y1 = 0.070,
length = 0.10,
angle = 15,
lwd = 1)
lines( x = c(195, 200),
y = c(0.070, 0.070),
lwd = 1,
lty = 2)
arrows( x0 = 161.5,
x1 = 188.5,
y0 = 0.070,
y1 = 0.070,
code = 3,
length = 0.10,
angle = 15,
lwd = 1)
```
Proceeding as before, we ask 'How many standard deviations below the mean is $150$cm?'
Using Equation \@ref(eq:zscores) to compute the $z$-score, $150$cm corresponds to a $z$-score of
\begin{equation}
z = \frac{150 - 162}{7} = -1.71;
(\#eq:zscore214)
\end{equation}
that is, $1.71$ standard deviations *below* the mean.
What percentage of observations are less than this $z$-score?
This case is not covered by the [68--95--99.7 rule](#def:EmpiricalRule), though we can use the [68--95--99.7 rule](#def:EmpiricalRule) to make some *rough estimates*.
About $2.5$% of observations are less than $2$ standard deviations below the mean (Example \@ref(exm:HeightsExer1)); that is, about $2.5$% of men are shorter than $161$cm.
So the percentages males even shorter than $161$cm (that is, further into the tail of the distribution), will be *less* than $2.5$%.
While we don't know the probability exactly, it will be smaller than $2.5$%.
Estimates in this way are crude, but often serviceable.
However, better estimates of 'areas under the normal curve' are found using tables compiled for this very purpose.
These tables are in
`r if ( knitr::is_html_output()) {
'Appendix\\ \\@ref(ZTablesOnline).'
} else {
'Appendices\\ \\@ref(ZTablesNEG) and\\ \\@ref(ZTablesPOS).'
}`
'Percentages' under a normal curve are also called 'areas' under the normal curve.
The *total area* under a normal curve is one (or $100$%), since it represent all possible values that could be observed: evety height appear somewhere in Fig. \@ref(fig:HtsEmpirical).
We now learn how to use these tables for Example \@ref(exm:Height160).
## Exact areas from normal distributions {#ExactAreasUsingTables}
Areas under normal distributions can be found using *online* tables, or *hard copy* tables.
The online tables are easier to use,
`r if (knitr::is_latex_output()) {
'but only the *hard-copy* tables are explained in this book (see the [online](https://bookdown.org/pkaldunn/SRM-Textbook/tables.html#ZTablesOnline) version of this book for how to use the online tables).'
} else {
'but only the *online* tables are explained in this online book (see the hard-copy version for how to use the hard-copy tables).'
}`
```{r, child = if (knitr::is_latex_output()) './Tables/Ztables-Using-Hardcopy.Rmd'}
```
```{r, child = if (knitr::is_html_output()) './Tables/Ztables-Using-Online.Rmd'}
```
The hard-copy or online tables gives an answer of $1.62$%.
This agrees with the approximate answer using the [68--95--99.7 rule](#def:EmpiricalRule): less than $2.5$%.
## Computing areas (probabilities)
The general approach to computing probabilities from normal distributions is:
* *Draw a diagram*, and mark on 160cm (Fig. \@ref(fig:HtsExer3)).
* *Shade* the required region of interest: 'less than 160cm tall' (Fig. \@ref(fig:HtsExer3)).
* *Compute* the $z$-score using Equation \@ref(eq:zscores).
* *Use* the $z$ tables in `r if ( knitr::is_html_output()) { 'Appendix \\@ref(ZTablesOnline).'} else {'Appendices \\@ref(ZTablesNEG) and \\@ref(ZTablesPOS).'}`
* *Compute* the answer.
The number of standard deviations that 160cm is from the mean was computed above (Eq. \@ref(eq:zscore214)): $z = -2.14$.
That is, 160cm is $2.14$ standard deviations *below* the mean, so use $z = -2.14$ in the tables (remembering that the tables give probability (area) *less* than $z = -2.14$; Fig. \@ref(fig:HtsExer3)).
The probability of finding an Australian man less than 160cm tall is about $1.6$%.
The 68--95--99.7 rule can be used to give *approximate* probabilities, as a check that the answer found using tables seems reasonable.
More complicated questions can be asked too, as shown in the next section.
<iframe src="https://learningapps.org/watch?v=ppievv9gc22" style="border:0px;width:100%;height:800px" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
## Examples using $z$-scores {#Z-Score-Forestry}
::: {.example #NormalTrees name="Normal distributions"}
@data:Aedo1997:softwood simulated mechanized forest harvesting systems [@DevoreBerk2007].
In their study, they modelled the diameter of specific trees using
* a normal distribution; with
* a mean of $\mu = 8.8$ inches; and
* a standard deviation of $\sigma = 2.7$ inches.
Using this model, what is the probability that a randomly-chosen tree has a diameter *greater than* than 6 inches?
:::
Follow the steps identified earlier:
* *Draw* a normal curve, and mark on 6 inches (Fig. \@ref(fig:ZDBH1), left panel).
* *Shade* the region corresponding to 'greater than 6 inches' (Fig. \@ref(fig:ZDBH1), right panel).
* *Compute* the $z$-score using Eq. \@ref(eq:zscores):
$\displaystyle z = (6 - 8.8)/2.7 = -2.8/2.7 = -1.04$ to two decimal places.
* *Use* tables:
The probability of a tree diameter *shorter* than 6 inches is $0.1492$.
(The tables always give area *less* than the value of $z$ that is looked up.)
* *Compute* the answer:
Since the *total* area under the normal distribution is one, the probability of a tree diameter *greater* than 6 inches is $1 - 0.1492 = 0.8508$, or about $85$%.
```{r ZDBH1, fig.cap="What proportion of tree diameters are greater than 6 inches?", fig.align="center", fig.width=9.5, fig.height=2.75, out.width='100%'}
DBH.mn <- 8.8
DBH.sd <- 2.7
par(mfrow = c(1, 2))
z <- seq( -3.5, 3.5,
length = 250)
zy <- dnorm( z,
mean = 0,
sd = 1)
mu <- DBH.mn
sigma <- DBH.sd
x <- z * sigma + mu
out <- plotNormal(mu,
sigma,
xlab = "Tree diameters (in inches)",
main = "Draw",
round.dec = 1)
abline(v = 6,
lwd = 2)
out <- plotNormal(mu,
sigma,
xlab = "Tree diameters (in inches)",
main = "Shade",
round.dec = 1)
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 6,
hi = 20)
abline(v = 6,
lwd = 2)
```
::: {.importantBox .important data-latex="{iconmonstr-warning-8-240.png}"}
The normal-distribution tables **always** provide area to the **left** of the $z$-score looked up.
Drawing a picture of the situation is important: it helps visualise getting the answer from what the table give us.
Remember: The *total* area under the normal distribution is one (or 100%).
:::
::: {.thinkBox .think data-latex="{iconmonstr-light-bulb-2-240.png}"}
Match the diagram in Fig. \@ref(fig:MatchDiagrams) with the meaning for the tree-diameter model (recall: $\mu = 8.8$ inches):\label{thinkBox:MatchForward}
1. Tree diameters greater than 11 inches.
2. Tree diameters *between* 6 and 11 inches.
3. Tree diameters less than 11 inches.
4. Tree diameters between 3 and 6 inches.
`r if (knitr::is_latex_output()) '<!--'`
`r webexercises::hide()`
**1:** matches B; **2:** matches C; **3:** matches D; **4:** matches A.
`r webexercises::unhide()`
`r if (knitr::is_latex_output()) '-->'`
:::
```{r MatchDiagrams, fig.cap="Match the diagram with the description", fig.align="center", out.width="85%", fig.height=4.00, fig.width=8}
par( mfrow = c(2, 2))
par( mar = c(5, 1, 1.5, 2) + 0.1)
out <- plotNormal(mu,
sigma,
main = "Diagram A",
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 3,
hi = 6)
out <- plotNormal(mu,
sigma,
main = "Diagram B",
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 11,
hi = 20)
out <- plotNormal(mu,
sigma,
main = "Diagram C",
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 6,
hi = 11)
out <- plotNormal(mu,
sigma,
main = "Diagram D",
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 0,
hi = 11)
```
::: {.example #NormalTrees2 name="Normal distributions"}
Using the model for tree diameters in Example \@ref(exm:NormalTrees), what is the probability that a tree has a diameter *between* 6 and 11 inches?
:::
First, **draw** the situation, and **shade** 'between 6 and 10 inches' (Fig. \@ref(fig:MatchDiagrams), Diagram C).
Then, **compute** the $z$-scores for *both* tree diameters:
* For 6 inches: $\quad z = (6 - 8.8)/2.7 = -1.04$.
* For 11 inches: $\quad z = (11 - 8.8)/2.7 = 0.81$.
Table B can then be used to find the area to the *left* of $z = -1.04$, and also the area to the *left* of $z = 0.81$.
However, neither of these provide the area *between* $z = -1.04$ and $z = 0.81$ (Fig. \@ref(fig:ZDBH3)).
```{r ZDBH3, fig.cap="What proportion of tree diameters are between 6 and 11 inches? The two shaded areas are what we find by using the tables with $z = -1.04$ and $z = 0.81$, but neither give us the area we are seeking.", fig.align="center", fig.width=9.5, fig.height = 2.75,out.width='100%'}
par( mfrow = c(1, 2))
out <- plotNormal(mu,
sigma,
cex.axis = 0.85,
main = expression(What~tables~give~"for"~italic(z)==-1.04),
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 0,
hi = 6)
out <- plotNormal(mu,
sigma,
cex.axis = 0.85,
main = expression(What~tables~give~"for"~italic(z)==0.81),
xlab = "Tree diameters (inches)")
shadeNormal(out$x,
out$y,
col = plot.colour,
lo = 0,
hi = 11)
```
Looking carefully at the areas from the tables and the area sought, that area between the two $z$-scores is
`r if (knitr::is_latex_output()) {
'$0.7910 - 0.1492 = 0.6418$ (the online version has an animation).'
} else {
'$0.7910 - 0.1492 = 0.6418$; see the animation below.'
}`
The probability that a tree has a diameter between 6 and 11 inches is about $0.6418$, or about $64$%.
```{r animation.hook="gifski", dev=if (is_latex_output()){"pdf"}else{"png"}}
RT.mn <- 8.8
RT.sd <- 2.7
lower <- 6
upper <- 11
if (knitr::is_html_output()){
for (i in (1:4)){
if ( i == 1 ){
out <- plotNormal(RT.mn,
sd = RT.sd,
xlab = "Tree diameter (inches)",
round.dec = 1,
main = "Between 6 and 11 inches")
shadeNormal(out$x,
out$y,
col = "azure2",
lo = lower,
hi = upper)
}
if ( i == 3 ){
out <- plotNormal(RT.mn,
sd = RT.sd,
xlab = "Tree diameter (inches)",
round.dec = 1,
main = "Table: Less than 11 inches: 0.7910")
shadeNormal(out$x,