-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chapter_36.html
996 lines (945 loc) · 92.7 KB
/
Chapter_36.html
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 36 Practical. Introduction to R | Fundamental statistical concepts and techniques in the biological and environmental sciences: With jamovi</title>
<meta name="description" content="This is an introductory statistics textbook for students in the biological and environmental sciences with examples using jamovi statistical software." />
<meta name="generator" content="bookdown 0.37 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 36 Practical. Introduction to R | Fundamental statistical concepts and techniques in the biological and environmental sciences: With jamovi" />
<meta property="og:type" content="book" />
<meta property="og:description" content="This is an introductory statistics textbook for students in the biological and environmental sciences with examples using jamovi statistical software." />
<meta name="github-repo" content="bradduthie/statistics_book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 36 Practical. Introduction to R | Fundamental statistical concepts and techniques in the biological and environmental sciences: With jamovi" />
<meta name="twitter:description" content="This is an introductory statistics textbook for students in the biological and environmental sciences with examples using jamovi statistical software." />
<meta name="author" content="Brad Duthie" />
<meta name="date" content="2024-02-24" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="Chapter_35.html"/>
<link rel="next" href="Week12.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { font-weight: bold; } /* Alert */
code span.an { font-style: italic; } /* Annotation */
code span.cf { font-weight: bold; } /* ControlFlow */
code span.co { font-style: italic; } /* Comment */
code span.cv { font-style: italic; } /* CommentVar */
code span.do { font-style: italic; } /* Documentation */
code span.dt { text-decoration: underline; } /* DataType */
code span.er { font-weight: bold; } /* Error */
code span.in { font-style: italic; } /* Information */
code span.kw { font-weight: bold; } /* Keyword */
code span.pp { font-weight: bold; } /* Preprocessor */
code span.wa { font-style: italic; } /* Warning */
</style>
<style type="text/css">
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>
<style type="text/css">
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">Statistics with jamovi</a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Preface</a>
<ul>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#structure"><i class="fa fa-check"></i>How this book is structured</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#datasets"><i class="fa fa-check"></i>Datasets used in this book</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#acknowledgements"><i class="fa fa-check"></i>Acknowledgements</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#author"><i class="fa fa-check"></i>About the author</a></li>
</ul></li>
<li class="part"><span><b>I Background mathematics and data organisation</b></span></li>
<li class="chapter" data-level="" data-path="Week1.html"><a href="Week1.html"><i class="fa fa-check"></i>Part I Overview</a></li>
<li class="chapter" data-level="1" data-path="Chapter_1.html"><a href="Chapter_1.html"><i class="fa fa-check"></i><b>1</b> Background mathematics</a>
<ul>
<li class="chapter" data-level="1.1" data-path="Chapter_1.html"><a href="Chapter_1.html#numbers-and-operations"><i class="fa fa-check"></i><b>1.1</b> Numbers and operations</a></li>
<li class="chapter" data-level="1.2" data-path="Chapter_1.html"><a href="Chapter_1.html#logarithms"><i class="fa fa-check"></i><b>1.2</b> Logarithms</a></li>
<li class="chapter" data-level="1.3" data-path="Chapter_1.html"><a href="Chapter_1.html#order-of-operations"><i class="fa fa-check"></i><b>1.3</b> Order of operations</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Chapter_2.html"><a href="Chapter_2.html"><i class="fa fa-check"></i><b>2</b> Data organisation</a>
<ul>
<li class="chapter" data-level="2.1" data-path="Chapter_2.html"><a href="Chapter_2.html#tidy-data"><i class="fa fa-check"></i><b>2.1</b> Tidy data</a></li>
<li class="chapter" data-level="2.2" data-path="Chapter_2.html"><a href="Chapter_2.html#data-files"><i class="fa fa-check"></i><b>2.2</b> Data files</a></li>
<li class="chapter" data-level="2.3" data-path="Chapter_2.html"><a href="Chapter_2.html#managing-data-files"><i class="fa fa-check"></i><b>2.3</b> Managing data files</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Chapter_3.html"><a href="Chapter_3.html"><i class="fa fa-check"></i><b>3</b> <em>Practical</em>. Preparing data</a>
<ul>
<li class="chapter" data-level="3.1" data-path="Chapter_3.html"><a href="Chapter_3.html#exercise-1-transferring-data-to-a-spreadsheet"><i class="fa fa-check"></i><b>3.1</b> Exercise 1: Transferring data to a spreadsheet</a></li>
<li class="chapter" data-level="3.2" data-path="Chapter_3.html"><a href="Chapter_3.html#exercise-2-making-spreadsheet-data-tidy"><i class="fa fa-check"></i><b>3.2</b> Exercise 2: Making spreadsheet data tidy</a></li>
<li class="chapter" data-level="3.3" data-path="Chapter_3.html"><a href="Chapter_3.html#exercise-3-making-data-tidy-again"><i class="fa fa-check"></i><b>3.3</b> Exercise 3: Making data tidy again</a></li>
<li class="chapter" data-level="3.4" data-path="Chapter_3.html"><a href="Chapter_3.html#exercise-4-tidy-data-and-spreadsheet-calculations"><i class="fa fa-check"></i><b>3.4</b> Exercise 4: Tidy data and spreadsheet calculations</a></li>
<li class="chapter" data-level="3.5" data-path="Chapter_3.html"><a href="Chapter_3.html#summary"><i class="fa fa-check"></i><b>3.5</b> Summary</a></li>
</ul></li>
<li class="part"><span><b>II Statistical concepts</b></span></li>
<li class="chapter" data-level="" data-path="Week2.html"><a href="Week2.html"><i class="fa fa-check"></i>Part II Overview</a></li>
<li class="chapter" data-level="4" data-path="Chapter_4.html"><a href="Chapter_4.html"><i class="fa fa-check"></i><b>4</b> Populations and samples</a></li>
<li class="chapter" data-level="5" data-path="Chapter_5.html"><a href="Chapter_5.html"><i class="fa fa-check"></i><b>5</b> Types of variables</a></li>
<li class="chapter" data-level="6" data-path="Chapter_6.html"><a href="Chapter_6.html"><i class="fa fa-check"></i><b>6</b> Accuracy, precision, and units</a>
<ul>
<li class="chapter" data-level="6.1" data-path="Chapter_6.html"><a href="Chapter_6.html#accuracy"><i class="fa fa-check"></i><b>6.1</b> Accuracy</a></li>
<li class="chapter" data-level="6.2" data-path="Chapter_6.html"><a href="Chapter_6.html#precision"><i class="fa fa-check"></i><b>6.2</b> Precision</a></li>
<li class="chapter" data-level="6.3" data-path="Chapter_6.html"><a href="Chapter_6.html#systems-of-units"><i class="fa fa-check"></i><b>6.3</b> Systems of units</a></li>
<li class="chapter" data-level="6.4" data-path="Chapter_6.html"><a href="Chapter_6.html#other-examples-of-units"><i class="fa fa-check"></i><b>6.4</b> Other examples of units</a>
<ul>
<li class="chapter" data-level="6.4.1" data-path="Chapter_6.html"><a href="Chapter_6.html#units-of-density"><i class="fa fa-check"></i><b>6.4.1</b> Units of density</a></li>
<li class="chapter" data-level="6.4.2" data-path="Chapter_6.html"><a href="Chapter_6.html#mass-of-metal-discharged-from-a-catchment"><i class="fa fa-check"></i><b>6.4.2</b> Mass of metal discharged from a catchment</a></li>
<li class="chapter" data-level="6.4.3" data-path="Chapter_6.html"><a href="Chapter_6.html#soil-carbon-inventories"><i class="fa fa-check"></i><b>6.4.3</b> Soil carbon inventories</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Chapter_7.html"><a href="Chapter_7.html"><i class="fa fa-check"></i><b>7</b> Uncertainty propagation</a>
<ul>
<li class="chapter" data-level="7.1" data-path="Chapter_7.html"><a href="Chapter_7.html#adding-or-subtracting-errors"><i class="fa fa-check"></i><b>7.1</b> Adding or subtracting errors</a></li>
<li class="chapter" data-level="7.2" data-path="Chapter_7.html"><a href="Chapter_7.html#multiplying-or-dividing-errors"><i class="fa fa-check"></i><b>7.2</b> Multiplying or dividing errors</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="Chapter_8.html"><a href="Chapter_8.html"><i class="fa fa-check"></i><b>8</b> <em>Practical</em>. Introduction to jamovi</a>
<ul>
<li class="chapter" data-level="8.1" data-path="Chapter_8.html"><a href="Chapter_8.html#summary_statistics_02"><i class="fa fa-check"></i><b>8.1</b> Exercise for summary statistics</a></li>
<li class="chapter" data-level="8.2" data-path="Chapter_8.html"><a href="Chapter_8.html#transforming_variables_02"><i class="fa fa-check"></i><b>8.2</b> Exercise on transforming variables</a></li>
<li class="chapter" data-level="8.3" data-path="Chapter_8.html"><a href="Chapter_8.html#computing_variables_02"><i class="fa fa-check"></i><b>8.3</b> Exercise on computing variables</a></li>
<li class="chapter" data-level="8.4" data-path="Chapter_8.html"><a href="Chapter_8.html#summary-1"><i class="fa fa-check"></i><b>8.4</b> Summary</a></li>
</ul></li>
<li class="part"><span><b>III Summary statistics</b></span></li>
<li class="chapter" data-level="" data-path="Week3.html"><a href="Week3.html"><i class="fa fa-check"></i>Part III Overview</a></li>
<li class="chapter" data-level="9" data-path="Chapter_9.html"><a href="Chapter_9.html"><i class="fa fa-check"></i><b>9</b> Decimal places, significant figures, and rounding</a>
<ul>
<li class="chapter" data-level="9.1" data-path="Chapter_9.html"><a href="Chapter_9.html#decimal-places-and-significant-figures"><i class="fa fa-check"></i><b>9.1</b> Decimal places and significant figures</a></li>
<li class="chapter" data-level="9.2" data-path="Chapter_9.html"><a href="Chapter_9.html#rounding"><i class="fa fa-check"></i><b>9.2</b> Rounding</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="Chapter_10.html"><a href="Chapter_10.html"><i class="fa fa-check"></i><b>10</b> Graphs</a>
<ul>
<li class="chapter" data-level="10.1" data-path="Chapter_10.html"><a href="Chapter_10.html#histograms"><i class="fa fa-check"></i><b>10.1</b> Histograms</a></li>
<li class="chapter" data-level="10.2" data-path="Chapter_10.html"><a href="Chapter_10.html#barplots-and-pie-charts"><i class="fa fa-check"></i><b>10.2</b> Barplots and pie charts</a></li>
<li class="chapter" data-level="10.3" data-path="Chapter_10.html"><a href="Chapter_10.html#box-whisker-plots"><i class="fa fa-check"></i><b>10.3</b> Box-whisker plots</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="Chapter_11.html"><a href="Chapter_11.html"><i class="fa fa-check"></i><b>11</b> Measures of central tendency</a>
<ul>
<li class="chapter" data-level="11.1" data-path="Chapter_11.html"><a href="Chapter_11.html#the-mean"><i class="fa fa-check"></i><b>11.1</b> The mean</a></li>
<li class="chapter" data-level="11.2" data-path="Chapter_11.html"><a href="Chapter_11.html#the-mode"><i class="fa fa-check"></i><b>11.2</b> The mode</a></li>
<li class="chapter" data-level="11.3" data-path="Chapter_11.html"><a href="Chapter_11.html#the-median-and-quantiles"><i class="fa fa-check"></i><b>11.3</b> The median and quantiles</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="Chapter_12.html"><a href="Chapter_12.html"><i class="fa fa-check"></i><b>12</b> Measures of spread</a>
<ul>
<li class="chapter" data-level="12.1" data-path="Chapter_12.html"><a href="Chapter_12.html#the-range"><i class="fa fa-check"></i><b>12.1</b> The range</a></li>
<li class="chapter" data-level="12.2" data-path="Chapter_12.html"><a href="Chapter_12.html#the-inter-quartile-range"><i class="fa fa-check"></i><b>12.2</b> The inter-quartile range</a></li>
<li class="chapter" data-level="12.3" data-path="Chapter_12.html"><a href="Chapter_12.html#the-variance"><i class="fa fa-check"></i><b>12.3</b> The variance</a></li>
<li class="chapter" data-level="12.4" data-path="Chapter_12.html"><a href="Chapter_12.html#the-standard-deviation"><i class="fa fa-check"></i><b>12.4</b> The standard deviation</a></li>
<li class="chapter" data-level="12.5" data-path="Chapter_12.html"><a href="Chapter_12.html#the-coefficient-of-variation"><i class="fa fa-check"></i><b>12.5</b> The coefficient of variation</a></li>
<li class="chapter" data-level="12.6" data-path="Chapter_12.html"><a href="Chapter_12.html#the-standard-error"><i class="fa fa-check"></i><b>12.6</b> The standard error</a></li>
</ul></li>
<li class="chapter" data-level="13" data-path="skew-and-kurtosis.html"><a href="skew-and-kurtosis.html"><i class="fa fa-check"></i><b>13</b> Skew and Kurtosis</a>
<ul>
<li class="chapter" data-level="13.1" data-path="skew-and-kurtosis.html"><a href="skew-and-kurtosis.html#skew"><i class="fa fa-check"></i><b>13.1</b> Skew</a></li>
<li class="chapter" data-level="13.2" data-path="skew-and-kurtosis.html"><a href="skew-and-kurtosis.html#kurtosis"><i class="fa fa-check"></i><b>13.2</b> Kurtosis</a></li>
<li class="chapter" data-level="13.3" data-path="skew-and-kurtosis.html"><a href="skew-and-kurtosis.html#moments"><i class="fa fa-check"></i><b>13.3</b> Moments</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="Chapter_14.html"><a href="Chapter_14.html"><i class="fa fa-check"></i><b>14</b> <em>Practical</em>. Plotting and statistical summaries in jamovi</a>
<ul>
<li class="chapter" data-level="14.1" data-path="Chapter_14.html"><a href="Chapter_14.html#reorganise-the-dataset-into-a-tidy-format"><i class="fa fa-check"></i><b>14.1</b> Reorganise the dataset into a tidy format</a></li>
<li class="chapter" data-level="14.2" data-path="Chapter_14.html"><a href="Chapter_14.html#histograms-and-box-whisker-plots"><i class="fa fa-check"></i><b>14.2</b> Histograms and box-whisker plots</a></li>
<li class="chapter" data-level="14.3" data-path="Chapter_14.html"><a href="Chapter_14.html#calculate-summary-statistics"><i class="fa fa-check"></i><b>14.3</b> Calculate summary statistics</a></li>
<li class="chapter" data-level="14.4" data-path="Chapter_14.html"><a href="Chapter_14.html#reporting-decimals-and-significant-figures"><i class="fa fa-check"></i><b>14.4</b> Reporting decimals and significant figures</a></li>
<li class="chapter" data-level="14.5" data-path="Chapter_14.html"><a href="Chapter_14.html#comparing-across-sites"><i class="fa fa-check"></i><b>14.5</b> Comparing across sites</a></li>
</ul></li>
<li class="part"><span><b>IV Probability models and the Central Limit Theorem</b></span></li>
<li class="chapter" data-level="" data-path="Week4.html"><a href="Week4.html"><i class="fa fa-check"></i>Part IV Overview</a></li>
<li class="chapter" data-level="15" data-path="Chapter_15.html"><a href="Chapter_15.html"><i class="fa fa-check"></i><b>15</b> Introduction to probability models</a>
<ul>
<li class="chapter" data-level="15.1" data-path="Chapter_15.html"><a href="Chapter_15.html#an-instructive-example"><i class="fa fa-check"></i><b>15.1</b> An instructive example</a></li>
<li class="chapter" data-level="15.2" data-path="Chapter_15.html"><a href="Chapter_15.html#biological-applications"><i class="fa fa-check"></i><b>15.2</b> Biological applications</a></li>
<li class="chapter" data-level="15.3" data-path="Chapter_15.html"><a href="Chapter_15.html#sampling-with-and-without-replacement"><i class="fa fa-check"></i><b>15.3</b> Sampling with and without replacement</a></li>
<li class="chapter" data-level="15.4" data-path="Chapter_15.html"><a href="Chapter_15.html#probability-distributions"><i class="fa fa-check"></i><b>15.4</b> Probability distributions</a>
<ul>
<li class="chapter" data-level="15.4.1" data-path="Chapter_15.html"><a href="Chapter_15.html#binomial-distribution"><i class="fa fa-check"></i><b>15.4.1</b> Binomial distribution</a></li>
<li class="chapter" data-level="15.4.2" data-path="Chapter_15.html"><a href="Chapter_15.html#poisson-distribution"><i class="fa fa-check"></i><b>15.4.2</b> Poisson distribution</a></li>
<li class="chapter" data-level="15.4.3" data-path="Chapter_15.html"><a href="Chapter_15.html#uniform-distribution"><i class="fa fa-check"></i><b>15.4.3</b> Uniform distribution</a></li>
<li class="chapter" data-level="15.4.4" data-path="Chapter_15.html"><a href="Chapter_15.html#normal-distribution"><i class="fa fa-check"></i><b>15.4.4</b> Normal distribution</a></li>
</ul></li>
<li class="chapter" data-level="15.5" data-path="Chapter_15.html"><a href="Chapter_15.html#summary-2"><i class="fa fa-check"></i><b>15.5</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="16" data-path="Chapter_16.html"><a href="Chapter_16.html"><i class="fa fa-check"></i><b>16</b> The Central Limit Theorem (CLT)</a>
<ul>
<li class="chapter" data-level="16.1" data-path="Chapter_16.html"><a href="Chapter_16.html#the-distribution-of-means-is-normal"><i class="fa fa-check"></i><b>16.1</b> The distribution of means is normal</a></li>
<li class="chapter" data-level="16.2" data-path="Chapter_16.html"><a href="Chapter_16.html#probability-and-z-scores"><i class="fa fa-check"></i><b>16.2</b> Probability and z-scores</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="Chapter_17.html"><a href="Chapter_17.html"><i class="fa fa-check"></i><b>17</b> <em>Practical</em>. Probability and simulation</a>
<ul>
<li class="chapter" data-level="17.1" data-path="Chapter_17.html"><a href="Chapter_17.html#probabilities-from-a-dataset"><i class="fa fa-check"></i><b>17.1</b> Probabilities from a dataset</a></li>
<li class="chapter" data-level="17.2" data-path="Chapter_17.html"><a href="Chapter_17.html#probabilities-from-a-normal-distribution"><i class="fa fa-check"></i><b>17.2</b> Probabilities from a normal distribution</a></li>
<li class="chapter" data-level="17.3" data-path="Chapter_17.html"><a href="Chapter_17.html#central-limit-theorem"><i class="fa fa-check"></i><b>17.3</b> Central limit theorem</a></li>
</ul></li>
<li class="part"><span><b>V Statistical inference</b></span></li>
<li class="chapter" data-level="" data-path="Week5.html"><a href="Week5.html"><i class="fa fa-check"></i>Part V Overview</a></li>
<li class="chapter" data-level="18" data-path="Chapter_18.html"><a href="Chapter_18.html"><i class="fa fa-check"></i><b>18</b> Confidence intervals (CIs)</a>
<ul>
<li class="chapter" data-level="18.1" data-path="Chapter_18.html"><a href="Chapter_18.html#normal-distribution-cis"><i class="fa fa-check"></i><b>18.1</b> Normal distribution CIs</a></li>
<li class="chapter" data-level="18.2" data-path="Chapter_18.html"><a href="Chapter_18.html#binomial-distribution-cis"><i class="fa fa-check"></i><b>18.2</b> Binomial distribution CIs</a></li>
</ul></li>
<li class="chapter" data-level="19" data-path="Chapter_19.html"><a href="Chapter_19.html"><i class="fa fa-check"></i><b>19</b> The t-interval</a></li>
<li class="chapter" data-level="20" data-path="Chapter_20.html"><a href="Chapter_20.html"><i class="fa fa-check"></i><b>20</b> <em>Practical</em>. z- and t- intervals</a>
<ul>
<li class="chapter" data-level="20.1" data-path="Chapter_20.html"><a href="Chapter_20.html#confidence-intervals-with-distraction"><i class="fa fa-check"></i><b>20.1</b> Confidence intervals with distrACTION</a></li>
<li class="chapter" data-level="20.2" data-path="Chapter_20.html"><a href="Chapter_20.html#confidence-intervals-from-z--and-t-scores"><i class="fa fa-check"></i><b>20.2</b> Confidence intervals from z- and t-scores</a></li>
<li class="chapter" data-level="20.3" data-path="Chapter_20.html"><a href="Chapter_20.html#confidence-intervals-for-different-sample-sizes-t--and-z-"><i class="fa fa-check"></i><b>20.3</b> Confidence intervals for different sample sizes (t- and z-)</a></li>
<li class="chapter" data-level="20.4" data-path="Chapter_20.html"><a href="Chapter_20.html#proportion-confidence-intervals"><i class="fa fa-check"></i><b>20.4</b> Proportion confidence intervals</a></li>
<li class="chapter" data-level="20.5" data-path="Chapter_20.html"><a href="Chapter_20.html#another-proportion-confidence-interval"><i class="fa fa-check"></i><b>20.5</b> Another proportion confidence interval</a></li>
</ul></li>
<li class="part"><span><b>VI Hypothesis testing</b></span></li>
<li class="chapter" data-level="" data-path="Week6.html"><a href="Week6.html"><i class="fa fa-check"></i>Part VI Overview</a></li>
<li class="chapter" data-level="21" data-path="Chapter_21.html"><a href="Chapter_21.html"><i class="fa fa-check"></i><b>21</b> What is hypothesis testing?</a>
<ul>
<li class="chapter" data-level="21.1" data-path="Chapter_21.html"><a href="Chapter_21.html#how-ridiculous-is-our-hypothesis"><i class="fa fa-check"></i><b>21.1</b> How ridiculous is our hypothesis?</a></li>
<li class="chapter" data-level="21.2" data-path="Chapter_21.html"><a href="Chapter_21.html#statistical-hypothesis-testing"><i class="fa fa-check"></i><b>21.2</b> Statistical hypothesis testing</a></li>
<li class="chapter" data-level="21.3" data-path="Chapter_21.html"><a href="Chapter_21.html#p-values-false-positives-and-power"><i class="fa fa-check"></i><b>21.3</b> P-values, false positives, and power</a></li>
</ul></li>
<li class="chapter" data-level="22" data-path="Chapter_22.html"><a href="Chapter_22.html"><i class="fa fa-check"></i><b>22</b> The t-test</a>
<ul>
<li class="chapter" data-level="22.1" data-path="Chapter_22.html"><a href="Chapter_22.html#one-sample-t-test"><i class="fa fa-check"></i><b>22.1</b> One sample t-test</a></li>
<li class="chapter" data-level="22.2" data-path="Chapter_22.html"><a href="Chapter_22.html#independent-samples-t-test"><i class="fa fa-check"></i><b>22.2</b> Independent samples t-test</a></li>
<li class="chapter" data-level="22.3" data-path="Chapter_22.html"><a href="Chapter_22.html#paired-sample-t-test"><i class="fa fa-check"></i><b>22.3</b> Paired sample t-test</a></li>
<li class="chapter" data-level="22.4" data-path="Chapter_22.html"><a href="Chapter_22.html#assumptions-of-t-tests"><i class="fa fa-check"></i><b>22.4</b> Assumptions of t-tests</a></li>
<li class="chapter" data-level="22.5" data-path="Chapter_22.html"><a href="Chapter_22.html#non-parametric-alternatives"><i class="fa fa-check"></i><b>22.5</b> Non-parametric alternatives</a>
<ul>
<li class="chapter" data-level="22.5.1" data-path="Chapter_22.html"><a href="Chapter_22.html#wilcoxon-test"><i class="fa fa-check"></i><b>22.5.1</b> Wilcoxon test</a></li>
<li class="chapter" data-level="22.5.2" data-path="Chapter_22.html"><a href="Chapter_22.html#mann-whitney-u-test"><i class="fa fa-check"></i><b>22.5.2</b> Mann-Whitney U test</a></li>
</ul></li>
<li class="chapter" data-level="22.6" data-path="Chapter_22.html"><a href="Chapter_22.html#summary-3"><i class="fa fa-check"></i><b>22.6</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="23" data-path="Chapter_23.html"><a href="Chapter_23.html"><i class="fa fa-check"></i><b>23</b> <em>Practical</em>. Hypothesis testing and t-tests</a>
<ul>
<li class="chapter" data-level="23.1" data-path="Chapter_23.html"><a href="Chapter_23.html#exercise-on-a-simple-one-sample-t-test"><i class="fa fa-check"></i><b>23.1</b> Exercise on a simple one sample t-test</a></li>
<li class="chapter" data-level="23.2" data-path="Chapter_23.html"><a href="Chapter_23.html#exercise-on-a-paired-t-test"><i class="fa fa-check"></i><b>23.2</b> Exercise on a paired t-test</a></li>
<li class="chapter" data-level="23.3" data-path="Chapter_23.html"><a href="Chapter_23.html#wilcoxon-test-1"><i class="fa fa-check"></i><b>23.3</b> Wilcoxon test</a></li>
<li class="chapter" data-level="23.4" data-path="Chapter_23.html"><a href="Chapter_23.html#independent-samples-t-test-1"><i class="fa fa-check"></i><b>23.4</b> Independent samples t-test</a></li>
<li class="chapter" data-level="23.5" data-path="Chapter_23.html"><a href="Chapter_23.html#mann-whitney-u-test-1"><i class="fa fa-check"></i><b>23.5</b> Mann-Whitney U Test</a></li>
</ul></li>
<li class="part"><span><b>VII Analysis of Variance (ANOVA)</b></span></li>
<li class="chapter" data-level="" data-path="Week8.html"><a href="Week8.html"><i class="fa fa-check"></i>Part VII Overview</a></li>
<li class="chapter" data-level="24" data-path="Chapter_24.html"><a href="Chapter_24.html"><i class="fa fa-check"></i><b>24</b> Analysis of variance</a>
<ul>
<li class="chapter" data-level="24.1" data-path="Chapter_24.html"><a href="Chapter_24.html#the-f-distribution"><i class="fa fa-check"></i><b>24.1</b> The F-distribution</a></li>
<li class="chapter" data-level="24.2" data-path="Chapter_24.html"><a href="Chapter_24.html#one-way-anova"><i class="fa fa-check"></i><b>24.2</b> One-way ANOVA</a>
<ul>
<li class="chapter" data-level="24.2.1" data-path="Chapter_24.html"><a href="Chapter_24.html#anova-mean-variance-among-groups"><i class="fa fa-check"></i><b>24.2.1</b> ANOVA mean variance among groups</a></li>
<li class="chapter" data-level="24.2.2" data-path="Chapter_24.html"><a href="Chapter_24.html#anova-mean-variance-within-groups"><i class="fa fa-check"></i><b>24.2.2</b> ANOVA mean variance within groups</a></li>
<li class="chapter" data-level="24.2.3" data-path="Chapter_24.html"><a href="Chapter_24.html#anova-f-statistic-calculation"><i class="fa fa-check"></i><b>24.2.3</b> ANOVA F statistic calculation</a></li>
</ul></li>
<li class="chapter" data-level="24.3" data-path="Chapter_24.html"><a href="Chapter_24.html#assumptions-of-anova"><i class="fa fa-check"></i><b>24.3</b> Assumptions of ANOVA</a></li>
</ul></li>
<li class="chapter" data-level="25" data-path="Chapter_25.html"><a href="Chapter_25.html"><i class="fa fa-check"></i><b>25</b> Multiple comparisons</a></li>
<li class="chapter" data-level="26" data-path="Chapter_26.html"><a href="Chapter_26.html"><i class="fa fa-check"></i><b>26</b> Kruskall-Wallis H test</a></li>
<li class="chapter" data-level="27" data-path="Chapter_27.html"><a href="Chapter_27.html"><i class="fa fa-check"></i><b>27</b> Two-way ANOVA</a></li>
<li class="chapter" data-level="28" data-path="Chapter_28.html"><a href="Chapter_28.html"><i class="fa fa-check"></i><b>28</b> <em>Practical</em>. ANOVA and associated tests</a>
<ul>
<li class="chapter" data-level="28.1" data-path="Chapter_28.html"><a href="Chapter_28.html#one-way-anova-site"><i class="fa fa-check"></i><b>28.1</b> One-way ANOVA (site)</a></li>
<li class="chapter" data-level="28.2" data-path="Chapter_28.html"><a href="Chapter_28.html#one-way-anova-profile"><i class="fa fa-check"></i><b>28.2</b> One-way ANOVA (profile)</a></li>
<li class="chapter" data-level="28.3" data-path="Chapter_28.html"><a href="Chapter_28.html#multiple-comparisons"><i class="fa fa-check"></i><b>28.3</b> Multiple comparisons</a></li>
<li class="chapter" data-level="28.4" data-path="Chapter_28.html"><a href="Chapter_28.html#kruskall-wallis-h-test"><i class="fa fa-check"></i><b>28.4</b> Kruskall-Wallis H test</a></li>
<li class="chapter" data-level="28.5" data-path="Chapter_28.html"><a href="Chapter_28.html#two-way-anova"><i class="fa fa-check"></i><b>28.5</b> Two-way ANOVA</a></li>
</ul></li>
<li class="part"><span><b>VIII Counts and Correlation</b></span></li>
<li class="chapter" data-level="" data-path="Week9.html"><a href="Week9.html"><i class="fa fa-check"></i>Part VIII Overview</a></li>
<li class="chapter" data-level="29" data-path="Chapter_29.html"><a href="Chapter_29.html"><i class="fa fa-check"></i><b>29</b> Frequency and count data</a>
<ul>
<li class="chapter" data-level="29.1" data-path="Chapter_29.html"><a href="Chapter_29.html#the-chi-square-distribution"><i class="fa fa-check"></i><b>29.1</b> The Chi-square distribution</a></li>
<li class="chapter" data-level="29.2" data-path="Chapter_29.html"><a href="Chapter_29.html#chi-squared-goodness-of-fit"><i class="fa fa-check"></i><b>29.2</b> Chi-squared goodness of fit</a></li>
<li class="chapter" data-level="29.3" data-path="Chapter_29.html"><a href="Chapter_29.html#chi-squared-test-of-association"><i class="fa fa-check"></i><b>29.3</b> Chi-squared test of association</a></li>
</ul></li>
<li class="chapter" data-level="30" data-path="Chapter_30.html"><a href="Chapter_30.html"><i class="fa fa-check"></i><b>30</b> Correlation</a>
<ul>
<li class="chapter" data-level="30.1" data-path="Chapter_30.html"><a href="Chapter_30.html#scatterplots"><i class="fa fa-check"></i><b>30.1</b> Scatterplots</a></li>
<li class="chapter" data-level="30.2" data-path="Chapter_30.html"><a href="Chapter_30.html#the-correlation-coefficient"><i class="fa fa-check"></i><b>30.2</b> The correlation coefficient</a>
<ul>
<li class="chapter" data-level="30.2.1" data-path="Chapter_30.html"><a href="Chapter_30.html#pearson-product-moment-correlation-coefficient"><i class="fa fa-check"></i><b>30.2.1</b> Pearson product moment correlation coefficient</a></li>
<li class="chapter" data-level="30.2.2" data-path="Chapter_30.html"><a href="Chapter_30.html#spearman-rank-correlation-coefficient"><i class="fa fa-check"></i><b>30.2.2</b> Spearman rank correlation coefficient</a></li>
</ul></li>
<li class="chapter" data-level="30.3" data-path="Chapter_30.html"><a href="Chapter_30.html#correlation-hypothesis-testing"><i class="fa fa-check"></i><b>30.3</b> Correlation hypothesis testing</a></li>
</ul></li>
<li class="chapter" data-level="31" data-path="Chapter_31.html"><a href="Chapter_31.html"><i class="fa fa-check"></i><b>31</b> <em>Practical</em>. Analysis of counts and correlations</a>
<ul>
<li class="chapter" data-level="31.1" data-path="Chapter_31.html"><a href="Chapter_31.html#survival-goodness-of-fit"><i class="fa fa-check"></i><b>31.1</b> Survival goodness of fit</a></li>
<li class="chapter" data-level="31.2" data-path="Chapter_31.html"><a href="Chapter_31.html#colony-goodness-of-fit"><i class="fa fa-check"></i><b>31.2</b> Colony goodness of fit</a></li>
<li class="chapter" data-level="31.3" data-path="Chapter_31.html"><a href="Chapter_31.html#chi-square-test-of-association"><i class="fa fa-check"></i><b>31.3</b> Chi-Square test of association</a></li>
<li class="chapter" data-level="31.4" data-path="Chapter_31.html"><a href="Chapter_31.html#pearson-product-moment-correlation-test"><i class="fa fa-check"></i><b>31.4</b> Pearson product moment correlation test</a></li>
<li class="chapter" data-level="31.5" data-path="Chapter_31.html"><a href="Chapter_31.html#spearman-rank-correlation-test"><i class="fa fa-check"></i><b>31.5</b> Spearman rank correlation test</a></li>
<li class="chapter" data-level="31.6" data-path="Chapter_31.html"><a href="Chapter_31.html#untidy-goodness-of-fit"><i class="fa fa-check"></i><b>31.6</b> Untidy goodness of fit</a></li>
</ul></li>
<li class="part"><span><b>IX Linear Regression</b></span></li>
<li class="chapter" data-level="" data-path="Week10.html"><a href="Week10.html"><i class="fa fa-check"></i>Part IX Overview</a></li>
<li class="chapter" data-level="32" data-path="Chapter_32.html"><a href="Chapter_32.html"><i class="fa fa-check"></i><b>32</b> Simple linear regression</a>
<ul>
<li class="chapter" data-level="32.1" data-path="Chapter_32.html"><a href="Chapter_32.html#visual-interpretation-of-regression"><i class="fa fa-check"></i><b>32.1</b> Visual interpretation of regression</a></li>
<li class="chapter" data-level="32.2" data-path="Chapter_32.html"><a href="Chapter_32.html#intercepts-slopes-and-residuals"><i class="fa fa-check"></i><b>32.2</b> Intercepts, slopes, and residuals</a></li>
<li class="chapter" data-level="32.3" data-path="Chapter_32.html"><a href="Chapter_32.html#regression-coefficients"><i class="fa fa-check"></i><b>32.3</b> Regression coefficients</a></li>
<li class="chapter" data-level="32.4" data-path="Chapter_32.html"><a href="Chapter_32.html#regression-line-calculation"><i class="fa fa-check"></i><b>32.4</b> Regression line calculation</a></li>
<li class="chapter" data-level="32.5" data-path="Chapter_32.html"><a href="Chapter_32.html#coefficient-of-determination"><i class="fa fa-check"></i><b>32.5</b> Coefficient of determination</a></li>
<li class="chapter" data-level="32.6" data-path="Chapter_32.html"><a href="Chapter_32.html#regression-assumptions"><i class="fa fa-check"></i><b>32.6</b> Regression assumptions</a></li>
<li class="chapter" data-level="32.7" data-path="Chapter_32.html"><a href="Chapter_32.html#regression-hypothesis-testing"><i class="fa fa-check"></i><b>32.7</b> Regression hypothesis testing</a>
<ul>
<li class="chapter" data-level="32.7.1" data-path="Chapter_32.html"><a href="Chapter_32.html#overall-model-significance"><i class="fa fa-check"></i><b>32.7.1</b> Overall model significance</a></li>
<li class="chapter" data-level="32.7.2" data-path="Chapter_32.html"><a href="Chapter_32.html#significance-of-the-intercept"><i class="fa fa-check"></i><b>32.7.2</b> Significance of the intercept</a></li>
<li class="chapter" data-level="32.7.3" data-path="Chapter_32.html"><a href="Chapter_32.html#significance-of-the-slope"><i class="fa fa-check"></i><b>32.7.3</b> Significance of the slope</a></li>
<li class="chapter" data-level="32.7.4" data-path="Chapter_32.html"><a href="Chapter_32.html#simple-regression-output"><i class="fa fa-check"></i><b>32.7.4</b> Simple regression output</a></li>
</ul></li>
<li class="chapter" data-level="32.8" data-path="Chapter_32.html"><a href="Chapter_32.html#prediction-with-linear-models"><i class="fa fa-check"></i><b>32.8</b> Prediction with linear models</a></li>
<li class="chapter" data-level="32.9" data-path="Chapter_32.html"><a href="Chapter_32.html#conclusion"><i class="fa fa-check"></i><b>32.9</b> Conclusion</a></li>
</ul></li>
<li class="chapter" data-level="33" data-path="Chapter_33.html"><a href="Chapter_33.html"><i class="fa fa-check"></i><b>33</b> Multiple regression</a>
<ul>
<li class="chapter" data-level="33.1" data-path="Chapter_33.html"><a href="Chapter_33.html#adjusted-coefficient-of-determination"><i class="fa fa-check"></i><b>33.1</b> Adjusted coefficient of determination</a></li>
</ul></li>
<li class="chapter" data-level="34" data-path="Chapter_34.html"><a href="Chapter_34.html"><i class="fa fa-check"></i><b>34</b> <em>Practical</em>. Using regression</a>
<ul>
<li class="chapter" data-level="34.1" data-path="Chapter_34.html"><a href="Chapter_34.html#predicting-pyrogenic-carbon-from-soil-depth"><i class="fa fa-check"></i><b>34.1</b> Predicting pyrogenic carbon from soil depth</a></li>
<li class="chapter" data-level="34.2" data-path="Chapter_34.html"><a href="Chapter_34.html#predicting-pyrogenic-carbon-from-fire-frequency"><i class="fa fa-check"></i><b>34.2</b> Predicting pyrogenic carbon from fire frequency</a></li>
<li class="chapter" data-level="34.3" data-path="Chapter_34.html"><a href="Chapter_34.html#multiple-regression-depth-and-fire-frequency"><i class="fa fa-check"></i><b>34.3</b> Multiple regression depth and fire frequency</a></li>
<li class="chapter" data-level="34.4" data-path="Chapter_34.html"><a href="Chapter_34.html#large-multiple-regression"><i class="fa fa-check"></i><b>34.4</b> Large multiple regression</a></li>
<li class="chapter" data-level="34.5" data-path="Chapter_34.html"><a href="Chapter_34.html#predicting-temperature-from-fire-frequency"><i class="fa fa-check"></i><b>34.5</b> Predicting temperature from fire frequency</a></li>
</ul></li>
<li class="part"><span><b>X Randomisation approaches</b></span></li>
<li class="chapter" data-level="" data-path="Week11.html"><a href="Week11.html"><i class="fa fa-check"></i>Part X Overview</a></li>
<li class="chapter" data-level="35" data-path="Chapter_35.html"><a href="Chapter_35.html"><i class="fa fa-check"></i><b>35</b> Randomisation</a>
<ul>
<li class="chapter" data-level="35.1" data-path="Chapter_35.html"><a href="Chapter_35.html#summary-of-parametric-hypothesis-testing"><i class="fa fa-check"></i><b>35.1</b> Summary of parametric hypothesis testing</a></li>
<li class="chapter" data-level="35.2" data-path="Chapter_35.html"><a href="Chapter_35.html#randomisation-approach"><i class="fa fa-check"></i><b>35.2</b> Randomisation approach</a></li>
<li class="chapter" data-level="35.3" data-path="Chapter_35.html"><a href="Chapter_35.html#randomisation-for-hypothesis-testing"><i class="fa fa-check"></i><b>35.3</b> Randomisation for hypothesis testing</a></li>
<li class="chapter" data-level="35.4" data-path="Chapter_35.html"><a href="Chapter_35.html#randomisation-assumptions"><i class="fa fa-check"></i><b>35.4</b> Randomisation assumptions</a></li>
<li class="chapter" data-level="35.5" data-path="Chapter_35.html"><a href="Chapter_35.html#bootstrapping"><i class="fa fa-check"></i><b>35.5</b> Bootstrapping</a></li>
<li class="chapter" data-level="35.6" data-path="Chapter_35.html"><a href="Chapter_35.html#monte-carlo"><i class="fa fa-check"></i><b>35.6</b> Monte Carlo</a></li>
<li class="chapter" data-level="35.7" data-path="Chapter_35.html"><a href="Chapter_35.html#randomisation-conclusions"><i class="fa fa-check"></i><b>35.7</b> Randomisation conclusions</a></li>
</ul></li>
<li class="chapter" data-level="36" data-path="Chapter_36.html"><a href="Chapter_36.html"><i class="fa fa-check"></i><b>36</b> <em>Practical</em>. Introduction to R</a>
<ul>
<li class="chapter" data-level="36.1" data-path="Chapter_36.html"><a href="Chapter_36.html#getting-used-to-the-r-interface"><i class="fa fa-check"></i><b>36.1</b> Getting used to the R interface</a></li>
<li class="chapter" data-level="36.2" data-path="Chapter_36.html"><a href="Chapter_36.html#assigning-variables-in-the-r-console"><i class="fa fa-check"></i><b>36.2</b> Assigning variables in the R console</a></li>
<li class="chapter" data-level="36.3" data-path="Chapter_36.html"><a href="Chapter_36.html#some-descriptive-statistics"><i class="fa fa-check"></i><b>36.3</b> Some descriptive statistics</a></li>
<li class="chapter" data-level="36.4" data-path="Chapter_36.html"><a href="Chapter_36.html#bootstrapping-confidence-intervals"><i class="fa fa-check"></i><b>36.4</b> Bootstrapping confidence intervals</a></li>
</ul></li>
<li class="part"><span><b>XI Experimental Design and Statistical Reporting</b></span></li>
<li class="chapter" data-level="" data-path="Week12.html"><a href="Week12.html"><i class="fa fa-check"></i>Part XI Overview</a></li>
<li class="chapter" data-level="37" data-path="Chapter_37.html"><a href="Chapter_37.html"><i class="fa fa-check"></i><b>37</b> Experimental design</a>
<ul>
<li class="chapter" data-level="37.1" data-path="Chapter_37.html"><a href="Chapter_37.html#before-collecting-data"><i class="fa fa-check"></i><b>37.1</b> Before collecting data</a></li>
</ul></li>
<li class="chapter" data-level="38" data-path="Chapter_38.html"><a href="Chapter_38.html"><i class="fa fa-check"></i><b>38</b> Reporting statistics</a>
<ul>
<li class="chapter" data-level="38.1" data-path="Chapter_38.html"><a href="Chapter_38.html#statistical-reporting"><i class="fa fa-check"></i><b>38.1</b> Statistical reporting</a>
<ul>
<li class="chapter" data-level="38.1.1" data-path="Chapter_38.html"><a href="Chapter_38.html#abstract"><i class="fa fa-check"></i><b>38.1.1</b> Abstract</a></li>
<li class="chapter" data-level="38.1.2" data-path="Chapter_38.html"><a href="Chapter_38.html#introduction"><i class="fa fa-check"></i><b>38.1.2</b> Introduction</a></li>
<li class="chapter" data-level="38.1.3" data-path="Chapter_38.html"><a href="Chapter_38.html#methods"><i class="fa fa-check"></i><b>38.1.3</b> Methods</a></li>
<li class="chapter" data-level="38.1.4" data-path="Chapter_38.html"><a href="Chapter_38.html#results"><i class="fa fa-check"></i><b>38.1.4</b> Results</a></li>
<li class="chapter" data-level="38.1.5" data-path="Chapter_38.html"><a href="Chapter_38.html#discussion"><i class="fa fa-check"></i><b>38.1.5</b> Discussion</a></li>
</ul></li>
<li class="chapter" data-level="38.2" data-path="Chapter_38.html"><a href="Chapter_38.html#figures-and-tables"><i class="fa fa-check"></i><b>38.2</b> Figures and tables</a>
<ul>
<li class="chapter" data-level="38.2.1" data-path="Chapter_38.html"><a href="Chapter_38.html#figures"><i class="fa fa-check"></i><b>38.2.1</b> Figures</a></li>
<li class="chapter" data-level="38.2.2" data-path="Chapter_38.html"><a href="Chapter_38.html#tables"><i class="fa fa-check"></i><b>38.2.2</b> Tables</a></li>
</ul></li>
<li class="chapter" data-level="38.3" data-path="Chapter_38.html"><a href="Chapter_38.html#statistical-tests"><i class="fa fa-check"></i><b>38.3</b> Statistical tests</a>
<ul>
<li class="chapter" data-level="38.3.1" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-t-tests"><i class="fa fa-check"></i><b>38.3.1</b> Reporting t-tests</a></li>
<li class="chapter" data-level="38.3.2" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-anova"><i class="fa fa-check"></i><b>38.3.2</b> Reporting ANOVA</a></li>
<li class="chapter" data-level="38.3.3" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-a-main-whitney-u-test"><i class="fa fa-check"></i><b>38.3.3</b> Reporting a Main-Whitney U test</a></li>
<li class="chapter" data-level="38.3.4" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-a-wilcoxon-signed-rank-test"><i class="fa fa-check"></i><b>38.3.4</b> Reporting a Wilcoxon signed-rank test</a></li>
<li class="chapter" data-level="38.3.5" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-chi-square-tests"><i class="fa fa-check"></i><b>38.3.5</b> Reporting Chi-square tests</a></li>
<li class="chapter" data-level="38.3.6" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-correlation-coefficients"><i class="fa fa-check"></i><b>38.3.6</b> Reporting correlation coefficients</a></li>
<li class="chapter" data-level="38.3.7" data-path="Chapter_38.html"><a href="Chapter_38.html#reporting-regressions"><i class="fa fa-check"></i><b>38.3.7</b> Reporting regressions</a></li>
</ul></li>
<li class="chapter" data-level="38.4" data-path="Chapter_38.html"><a href="Chapter_38.html#conclusions"><i class="fa fa-check"></i><b>38.4</b> Conclusions</a></li>
</ul></li>
<li class="chapter" data-level="39" data-path="Chapter_39.html"><a href="Chapter_39.html"><i class="fa fa-check"></i><b>39</b> <em>Practical</em>. Statistical techniques in R</a>
<ul>
<li class="chapter" data-level="39.1" data-path="Chapter_39.html"><a href="Chapter_39.html#working-with-a-data-set"><i class="fa fa-check"></i><b>39.1</b> Working with a data set</a></li>
<li class="chapter" data-level="39.2" data-path="Chapter_39.html"><a href="Chapter_39.html#familiar-statistical-tests-in-r"><i class="fa fa-check"></i><b>39.2</b> Familiar statistical tests in R</a>
<ul>
<li class="chapter" data-level="39.2.1" data-path="Chapter_39.html"><a href="Chapter_39.html#one-way-anova-in-r"><i class="fa fa-check"></i><b>39.2.1</b> One-way ANOVA in R</a></li>
<li class="chapter" data-level="39.2.2" data-path="Chapter_39.html"><a href="Chapter_39.html#two-way-anova-in-r"><i class="fa fa-check"></i><b>39.2.2</b> Two-way ANOVA in R</a></li>
<li class="chapter" data-level="39.2.3" data-path="Chapter_39.html"><a href="Chapter_39.html#chi-square-test-in-r"><i class="fa fa-check"></i><b>39.2.3</b> Chi-square test in R</a></li>
<li class="chapter" data-level="39.2.4" data-path="Chapter_39.html"><a href="Chapter_39.html#correlation-test-in-r"><i class="fa fa-check"></i><b>39.2.4</b> Correlation test in R</a></li>
<li class="chapter" data-level="39.2.5" data-path="Chapter_39.html"><a href="Chapter_39.html#simple-linear-regression-in-r"><i class="fa fa-check"></i><b>39.2.5</b> Simple linear regression in R</a></li>
<li class="chapter" data-level="39.2.6" data-path="Chapter_39.html"><a href="Chapter_39.html#multiple-regression-in-r"><i class="fa fa-check"></i><b>39.2.6</b> Multiple regression in R</a></li>
</ul></li>
<li class="chapter" data-level="39.3" data-path="Chapter_39.html"><a href="Chapter_39.html#statistical-test-assumptions-in-r"><i class="fa fa-check"></i><b>39.3</b> Statistical test assumptions in R</a></li>
</ul></li>
<li class="appendix"><span><b>Appendix</b></span></li>
<li class="chapter" data-level="A" data-path="appendexA.html"><a href="appendexA.html"><i class="fa fa-check"></i><b>A</b> Answers to chapter exercises</a>
<ul>
<li class="chapter" data-level="A.1" data-path="appendexA.html"><a href="appendexA.html#chapter-3"><i class="fa fa-check"></i><b>A.1</b> Chapter 3</a>
<ul>
<li class="chapter" data-level="A.1.1" data-path="appendexA.html"><a href="appendexA.html#exercise-3.1"><i class="fa fa-check"></i><b>A.1.1</b> Exercise 3.1:</a></li>
<li class="chapter" data-level="A.1.2" data-path="appendexA.html"><a href="appendexA.html#exercise-3.2"><i class="fa fa-check"></i><b>A.1.2</b> Exercise 3.2</a></li>
<li class="chapter" data-level="A.1.3" data-path="appendexA.html"><a href="appendexA.html#exercise-3.2-1"><i class="fa fa-check"></i><b>A.1.3</b> Exercise 3.2</a></li>
<li class="chapter" data-level="A.1.4" data-path="appendexA.html"><a href="appendexA.html#exercise-3.4"><i class="fa fa-check"></i><b>A.1.4</b> Exercise 3.4</a></li>
</ul></li>
<li class="chapter" data-level="A.2" data-path="appendexA.html"><a href="appendexA.html#chapter-8"><i class="fa fa-check"></i><b>A.2</b> Chapter 8</a>
<ul>
<li class="chapter" data-level="A.2.1" data-path="appendexA.html"><a href="appendexA.html#exercise-8.1"><i class="fa fa-check"></i><b>A.2.1</b> Exercise 8.1</a></li>
<li class="chapter" data-level="A.2.2" data-path="appendexA.html"><a href="appendexA.html#exercise-8.2"><i class="fa fa-check"></i><b>A.2.2</b> Exercise 8.2</a></li>
<li class="chapter" data-level="A.2.3" data-path="appendexA.html"><a href="appendexA.html#exercise-8.3"><i class="fa fa-check"></i><b>A.2.3</b> Exercise 8.3</a></li>
</ul></li>
<li class="chapter" data-level="A.3" data-path="appendexA.html"><a href="appendexA.html#chapter-14"><i class="fa fa-check"></i><b>A.3</b> Chapter 14</a>
<ul>
<li class="chapter" data-level="A.3.1" data-path="appendexA.html"><a href="appendexA.html#exercise-14.1"><i class="fa fa-check"></i><b>A.3.1</b> Exercise 14.1</a></li>
<li class="chapter" data-level="A.3.2" data-path="appendexA.html"><a href="appendexA.html#exercise-14.2"><i class="fa fa-check"></i><b>A.3.2</b> Exercise 14.2</a></li>
<li class="chapter" data-level="A.3.3" data-path="appendexA.html"><a href="appendexA.html#exercise-13.3"><i class="fa fa-check"></i><b>A.3.3</b> Exercise 13.3</a></li>
<li class="chapter" data-level="A.3.4" data-path="appendexA.html"><a href="appendexA.html#exercise-13.4"><i class="fa fa-check"></i><b>A.3.4</b> Exercise 13.4</a></li>
<li class="chapter" data-level="A.3.5" data-path="appendexA.html"><a href="appendexA.html#exercise-13.5"><i class="fa fa-check"></i><b>A.3.5</b> Exercise 13.5</a></li>
</ul></li>
<li class="chapter" data-level="A.4" data-path="appendexA.html"><a href="appendexA.html#chapter-17"><i class="fa fa-check"></i><b>A.4</b> Chapter 17</a>
<ul>
<li class="chapter" data-level="A.4.1" data-path="appendexA.html"><a href="appendexA.html#exercise-17.1"><i class="fa fa-check"></i><b>A.4.1</b> Exercise 17.1</a></li>
<li class="chapter" data-level="A.4.2" data-path="appendexA.html"><a href="appendexA.html#exercise-17.2"><i class="fa fa-check"></i><b>A.4.2</b> Exercise 17.2</a></li>
<li class="chapter" data-level="A.4.3" data-path="appendexA.html"><a href="appendexA.html#exercise-17.3"><i class="fa fa-check"></i><b>A.4.3</b> Exercise 17.3</a></li>
</ul></li>
<li class="chapter" data-level="A.5" data-path="appendexA.html"><a href="appendexA.html#chapter-20"><i class="fa fa-check"></i><b>A.5</b> Chapter 20</a>
<ul>
<li class="chapter" data-level="A.5.1" data-path="appendexA.html"><a href="appendexA.html#exercise-20.1"><i class="fa fa-check"></i><b>A.5.1</b> Exercise 20.1</a></li>
<li class="chapter" data-level="A.5.2" data-path="appendexA.html"><a href="appendexA.html#exercise-20.2"><i class="fa fa-check"></i><b>A.5.2</b> Exercise 20.2</a></li>
<li class="chapter" data-level="A.5.3" data-path="appendexA.html"><a href="appendexA.html#exercise-20.3"><i class="fa fa-check"></i><b>A.5.3</b> Exercise 20.3</a></li>
<li class="chapter" data-level="A.5.4" data-path="appendexA.html"><a href="appendexA.html#exercise-20.4"><i class="fa fa-check"></i><b>A.5.4</b> Exercise 20.4</a></li>
<li class="chapter" data-level="A.5.5" data-path="appendexA.html"><a href="appendexA.html#exercise-20.5"><i class="fa fa-check"></i><b>A.5.5</b> Exercise 20.5</a></li>
</ul></li>
<li class="chapter" data-level="A.6" data-path="appendexA.html"><a href="appendexA.html#chapter-23"><i class="fa fa-check"></i><b>A.6</b> Chapter 23</a>
<ul>
<li class="chapter" data-level="A.6.1" data-path="appendexA.html"><a href="appendexA.html#exercise-23.1"><i class="fa fa-check"></i><b>A.6.1</b> Exercise 23.1</a></li>
<li class="chapter" data-level="A.6.2" data-path="appendexA.html"><a href="appendexA.html#exercise-23.2"><i class="fa fa-check"></i><b>A.6.2</b> Exercise 23.2</a></li>
<li class="chapter" data-level="A.6.3" data-path="appendexA.html"><a href="appendexA.html#exercise-23.3"><i class="fa fa-check"></i><b>A.6.3</b> Exercise 23.3</a></li>
<li class="chapter" data-level="A.6.4" data-path="appendexA.html"><a href="appendexA.html#exercise-23.4"><i class="fa fa-check"></i><b>A.6.4</b> Exercise 23.4</a></li>
<li class="chapter" data-level="A.6.5" data-path="appendexA.html"><a href="appendexA.html#exercise-23.5"><i class="fa fa-check"></i><b>A.6.5</b> Exercise 23.5</a></li>
</ul></li>
<li class="chapter" data-level="A.7" data-path="appendexA.html"><a href="appendexA.html#chapter-28"><i class="fa fa-check"></i><b>A.7</b> Chapter 28</a>
<ul>
<li class="chapter" data-level="A.7.1" data-path="appendexA.html"><a href="appendexA.html#exercise-28.1"><i class="fa fa-check"></i><b>A.7.1</b> Exercise 28.1</a></li>
<li class="chapter" data-level="A.7.2" data-path="appendexA.html"><a href="appendexA.html#exercise-28.2"><i class="fa fa-check"></i><b>A.7.2</b> Exercise 28.2</a></li>
<li class="chapter" data-level="A.7.3" data-path="appendexA.html"><a href="appendexA.html#exercise-28.3"><i class="fa fa-check"></i><b>A.7.3</b> Exercise 28.3</a></li>
<li class="chapter" data-level="A.7.4" data-path="appendexA.html"><a href="appendexA.html#exercise-28.4"><i class="fa fa-check"></i><b>A.7.4</b> Exercise 28.4</a></li>
</ul></li>
<li class="chapter" data-level="A.8" data-path="appendexA.html"><a href="appendexA.html#chapter-31"><i class="fa fa-check"></i><b>A.8</b> Chapter 31</a>
<ul>
<li class="chapter" data-level="A.8.1" data-path="appendexA.html"><a href="appendexA.html#exercise-31.1"><i class="fa fa-check"></i><b>A.8.1</b> Exercise 31.1</a></li>
<li class="chapter" data-level="A.8.2" data-path="appendexA.html"><a href="appendexA.html#exercise-31.2"><i class="fa fa-check"></i><b>A.8.2</b> Exercise 31.2</a></li>
<li class="chapter" data-level="A.8.3" data-path="appendexA.html"><a href="appendexA.html#exercise-31.3"><i class="fa fa-check"></i><b>A.8.3</b> Exercise 31.3</a></li>
</ul></li>
<li class="chapter" data-level="A.9" data-path="appendexA.html"><a href="appendexA.html#exercise-31.4"><i class="fa fa-check"></i><b>A.9</b> Exercise 31.4</a>
<ul>
<li class="chapter" data-level="A.9.1" data-path="appendexA.html"><a href="appendexA.html#exercise-31.5"><i class="fa fa-check"></i><b>A.9.1</b> Exercise 31.5</a></li>
</ul></li>
<li class="chapter" data-level="A.10" data-path="appendexA.html"><a href="appendexA.html#chapter-34"><i class="fa fa-check"></i><b>A.10</b> Chapter 34</a>
<ul>
<li class="chapter" data-level="A.10.1" data-path="appendexA.html"><a href="appendexA.html#exercise-34.1"><i class="fa fa-check"></i><b>A.10.1</b> Exercise 34.1</a></li>
<li class="chapter" data-level="A.10.2" data-path="appendexA.html"><a href="appendexA.html#exercise-34.2"><i class="fa fa-check"></i><b>A.10.2</b> Exercise 34.2</a></li>
<li class="chapter" data-level="A.10.3" data-path="appendexA.html"><a href="appendexA.html#exercise-34.3"><i class="fa fa-check"></i><b>A.10.3</b> Exercise 34.3</a></li>
<li class="chapter" data-level="A.10.4" data-path="appendexA.html"><a href="appendexA.html#exercise-34.4"><i class="fa fa-check"></i><b>A.10.4</b> Exercise 34.4</a></li>
<li class="chapter" data-level="A.10.5" data-path="appendexA.html"><a href="appendexA.html#exercise-33.5"><i class="fa fa-check"></i><b>A.10.5</b> Exercise 33.5</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="B" data-path="uncertainty_derivation.html"><a href="uncertainty_derivation.html"><i class="fa fa-check"></i><b>B</b> Uncertainty derivation</a></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Fundamental statistical concepts and techniques in the biological and environmental sciences: With jamovi</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="Chapter_36" class="section level1 hasAnchor" number="36">
<h1><span class="header-section-number">Chapter 36</span> <em>Practical</em>. Introduction to R<a href="Chapter_36.html#Chapter_36" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p>Throughout this book, we have used jamovi for statistical analysis.
Jamovi is excellent software for running simple statistical analyses, but it has its limitations.
Jamovi is built upon the programming language R, which is much more powerful and versatile in comparison.
The R programming language is now widely used among scientists for data analysis.
It can be used to analyse and plot data, run computer simulations, or even write slides, papers, or books (this book was written using R).
The R programming language is completely free and open source, as is the popular <a href="https://posit.co/downloads/">Rstudio</a> software for using it.
The R programming language specialises in statistical computing, which is part of the reason for its popularity among scientists.</p>
<p>Another reason for the popularity of R is its versatility, and the ease with which new techniques can be shared.
Imagine that you develop a new method for analysing data.
If you want other researchers to be able to use your method in their research, then you could write your own software from scratch for them to install and use.
But doing this would be very time consuming, and a lot of that time would likely be spent writing the graphical user interface and making sure that your program worked across platforms (e.g., on Windows and Mac).
Worse, once written, there would be no easy way to make your program work with other statistical software should you need to integrate different analyses or visualisation tools (e.g., plotting data).
To avoid all of this, you could instead just present your new method for data analysis and let other researchers write their own code for implementing it.
But not all researchers will have the time or expertise to write their own code.</p>
<p>Instead, R allows researchers to write new tools for data analysis using simple coding scripts.
These scripts are organised into R packages, which can be uploaded by authors to the Comprehensive R Archive Network (CRAN)<a href="#fn88" class="footnote-ref" id="fnref88"><sup>88</sup></a>, then downloaded by users with a single command in R.
This way, there is no need for completely different software to be used for different analyses; all analyses can be written and run in R.</p>
<p>The downside to all of this is that learning R can be a bit daunting at first.
Running analyses is not done by pointing and clicking on icons as in jamovi.
You need to use code.
This practical will start with the very basics and work up to some simple data analyses.
Rather than questions to answer, this practical has tasks for you to try to complete in R.</p>
<div id="getting-used-to-the-r-interface" class="section level2 hasAnchor" number="36.1">
<h2><span class="header-section-number">36.1</span> Getting used to the R interface<a href="Chapter_36.html#getting-used-to-the-r-interface" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>There are two ways that you can use R.
The first way is to download R and Rstudio on your own computer.
Both R and Rstudio are free to download and use, and work on any major operating system (Windows, Mac, and Linux).
To download R, go to the Comprehensive R Archive Network (<a href="https://cran.r-project.org/" class="uri">https://cran.r-project.org/</a>) and follow the instructions for your operating system (OS).
To download Rstudio, go to the Posit website<a href="#fn89" class="footnote-ref" id="fnref89"><sup>89</sup></a> and choose the appropriate download for your operating system.</p>
<p>If you cannot or do not want to download R and Rstudio on your own computer, then you can still use both by going to the Rstudio Cloud (<a href="https://rstudio.cloud/" class="uri">https://rstudio.cloud/</a>) and running Rstudio from a browser such as Firefox or Chrome.
You will need to click the green “Get Started” button and sign up for a free account.
When you open Rstudio either on your own computer or the cloud, you will see several windows open, including a console.
The console will look something like the below.</p>
<pre><code>R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> </code></pre>
<p>If you click to the right of the greater than sign <code>></code>, you can start using R right in the console.
You can use R as a standard calculator here to get a feel for the console.
Try typing something like the below (semi-colons are not actually necessary).
For example, you could add 2 + 5.</p>
<div class="sourceCode" id="cb121"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb121-1"><a href="Chapter_36.html#cb121-1" aria-hidden="true" tabindex="-1"></a><span class="dv">2</span> <span class="sc">+</span> <span class="dv">5</span>; </span></code></pre></div>
<pre><code>[1] 7</code></pre>
<p>Try this yourself.</p>
<blockquote>
<p><strong>Task 1: Add 2 numbers together in R</strong></p>
</blockquote>
<p>You can also multiply in R.</p>
<div class="sourceCode" id="cb123"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb123-1"><a href="Chapter_36.html#cb123-1" aria-hidden="true" tabindex="-1"></a><span class="dv">4</span> <span class="sc">*</span> <span class="dv">4</span>; </span></code></pre></div>
<pre><code>[1] 16</code></pre>
<p>The caret key <code>^</code> is used for exponents</p>
<div class="sourceCode" id="cb125"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb125-1"><a href="Chapter_36.html#cb125-1" aria-hidden="true" tabindex="-1"></a><span class="dv">5</span><span class="sc">^</span><span class="dv">2</span>; </span></code></pre></div>
<pre><code>[1] 25</code></pre>
<p>R will use the correct order of operations (see <a href="Chapter_1.html#order-of-operations">Chapter 1.3</a>) when doing mathematical calculations.
For example, it will know to calculate the exponent before multiplying, and to multiply before adding.</p>
<div class="sourceCode" id="cb127"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb127-1"><a href="Chapter_36.html#cb127-1" aria-hidden="true" tabindex="-1"></a><span class="dv">2</span> <span class="sc">+</span> <span class="dv">4</span> <span class="sc">*</span> <span class="dv">5</span><span class="sc">^</span><span class="dv">2</span>; </span></code></pre></div>
<pre><code>[1] 102</code></pre>
<p>Following the correct order of operations, <span class="math inline">\(5^{2} = 25\)</span>, which is then multiplied by 4 to get <span class="math inline">\(4 \times 25 = 100\)</span>, and we add 2 to get <span class="math inline">\(100 + 2 = 102\)</span>.
We can, however, use parentheses to specify a different order of operations.</p>
<div class="sourceCode" id="cb129"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb129-1"><a href="Chapter_36.html#cb129-1" aria-hidden="true" tabindex="-1"></a>(<span class="dv">2</span> <span class="sc">+</span> <span class="dv">4</span>) <span class="sc">*</span> <span class="dv">5</span><span class="sc">^</span><span class="dv">2</span>; </span></code></pre></div>
<pre><code>[1] 150</code></pre>
<p>Now R will calculate <span class="math inline">\(2 + 4 = 6\)</span> and multiply the 6 by 25 to get an answer of 150.
The R console functions very well as a calculator.
Instead of punching buttons into a hand calculator or mobile phone, an entire equation can be written and placed into the console.
This makes mistakes less likely.
For example, in <a href="Chapter_1.html#order-of-operations">Chapter 1.3</a>, the following equation was presented,</p>
<p><span class="math display">\[x = 3^{2} + 2(1 + 3)^{2} - 6 \times 0.\]</span></p>
<p>To solve this in R, we just need to type the full equation in the console.</p>
<div class="sourceCode" id="cb131"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb131-1"><a href="Chapter_36.html#cb131-1" aria-hidden="true" tabindex="-1"></a><span class="dv">3</span><span class="sc">^</span><span class="dv">2</span> <span class="sc">+</span> <span class="dv">2</span><span class="sc">*</span>(<span class="dv">1</span> <span class="sc">+</span> <span class="dv">3</span>)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> <span class="dv">6</span> <span class="sc">*</span> <span class="dv">0</span>;</span></code></pre></div>
<pre><code>[1] 41</code></pre>
<p>We get the correct answer of 41.
Note that there needed to be an asterisk (<code>*</code>) to indicate multiplication between the 2 and the left parentheses.
This is because parentheses specify specific functions in R.
We will introduce functions next, but first, try the following task.</p>
<blockquote>
<p><strong>Task 2: Use the console to calculate <span class="math inline">\(x = \frac{2^2 + 1}{3^2 + 2}\)</span> (hint, you need to put the top and bottom of the fraction in parentheses, e.g., <code>(2^2 + 1)</code> for the numerator, and use the forward slash <code>/</code> for division).</strong></p>
</blockquote>
<p>You should get an answer of 0.4545455.</p>
<p>As previously mentioned, parentheses specify functions in R.
Functions have specific names such as <code>sqrt</code>, which calculates the square root of anything within the parentheses <code>sqrt()</code>.
If, for example, you wanted to find the square root of some number, you could use the <code>sqrt</code> function below.</p>
<div class="sourceCode" id="cb133"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb133-1"><a href="Chapter_36.html#cb133-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>(<span class="dv">256</span>);</span></code></pre></div>
<pre><code>[1] 16</code></pre>
<p>The console returns the correct answer 16.
Similar functions exist for logarithms (<code>log</code>) and trigonometric functions (e.g., <code>sin</code>, <code>cos</code>).
The parentheses after the word indicate that some function is being called in R.
Try to use the square root function to solve for <span class="math inline">\(x\)</span> in another equation.</p>
<blockquote>
<p><strong>Task 3: Use the console to calculate <span class="math inline">\(\sqrt{3 + 4^2}\)</span>.</strong></p>
</blockquote>
<p>You should get an answer of 4.3588989.</p>
<p>If you type something into the console incorrectly, you do not need to retype it entirely.
You can use the up arrow to scroll through the history of console input.
Try doing that now.</p>
<blockquote>
<p><strong>Task 4: Use the up arrow to find your previous calculation for <span class="math inline">\(\sqrt{3 + 4^2}\)</span>, then change this slightly to calculate <span class="math inline">\(\sqrt{3 + 4^3}\)</span>.</strong></p>
</blockquote>
<p>You should get an answer of 8.1853528.</p>
<p>Functions do not need to be mathematical like the <code>sqrt</code> function.
For example, the <code>getwd</code> function can be used to let you know what directory (i.e., folder) you are working in.</p>
<div class="sourceCode" id="cb135"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb135-1"><a href="Chapter_36.html#cb135-1" aria-hidden="true" tabindex="-1"></a><span class="fu">getwd</span>();</span></code></pre></div>
<pre><code>[1] "/home/brad/Dropbox/teaching/statistics_book/statistics_book"</code></pre>
<p>If we were to save or load a file within R, this is the location on the computer from which R would try to load.
We could also use the <code>setwd</code> function to set a new working directory (type the working directory in quotes inside the parentheses: <code>setwd("folder/subfolder/etc")</code>).
You can also set the working directory in Rstudio by going to the toolbar and clicking ‘Session’ and selecting ‘Set Working Directory’.</p>
</div>
<div id="assigning-variables-in-the-r-console" class="section level2 hasAnchor" number="36.2">
<h2><span class="header-section-number">36.2</span> Assigning variables in the R console<a href="Chapter_36.html#assigning-variables-in-the-r-console" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>In R, we can also assign values to variables using the characters <code><-</code> to make an arrow.
For example, we might want to set <code>var_1</code> equal 10.</p>
<div class="sourceCode" id="cb137"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb137-1"><a href="Chapter_36.html#cb137-1" aria-hidden="true" tabindex="-1"></a>var_1 <span class="ot"><-</span> <span class="dv">10</span>;</span></code></pre></div>
<p>We can now use <code>var_1</code> in the console.
For example, since <code>var_1</code> now equals 10, if we multiply <code>var_1</code> by 5, R calculates <span class="math inline">\(10 \times 5 = 50\)</span>.</p>
<div class="sourceCode" id="cb138"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb138-1"><a href="Chapter_36.html#cb138-1" aria-hidden="true" tabindex="-1"></a>var_1 <span class="sc">*</span> <span class="dv">5</span>; <span class="co"># Multiplying the variable by 5</span></span></code></pre></div>
<pre><code>[1] 50</code></pre>
<p>The correct value of 50 is returned because <code>var_1</code> equals 10. Also note the comment left after the <code>#</code> key.
In R, anything that comes after <code>#</code> on a line is a comment that R ignores.
Comments are ways of explaining in plain words what the code is doing, or drawing attention to important notes about the code.</p>
<blockquote>
<p><strong>Task 5: Assign a new variable to a value of 4 (call it anything you want), then multiply the new variable by itself.</strong></p>
</blockquote>
<p>For Task 5, you should get an output of 16.</p>
<p>When we assign something to a variable like <code>var_1</code>, we are not limited to a single number.
Variables in R can be much more complex.
For example, we can assign a new variable <code>vector_1</code> to an ordered set of 6 different numbers using the <code>c</code> function.
The <code>c</code> function combines values together.</p>
<div class="sourceCode" id="cb140"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb140-1"><a href="Chapter_36.html#cb140-1" aria-hidden="true" tabindex="-1"></a>vector_1 <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">5</span>, <span class="dv">1</span>, <span class="dv">3</span>, <span class="dv">5</span>, <span class="dv">7</span>, <span class="dv">11</span>); <span class="co"># Six numbers</span></span>
<span id="cb140-2"><a href="Chapter_36.html#cb140-2" aria-hidden="true" tabindex="-1"></a>vector_1; <span class="co"># Prints out the vector</span></span></code></pre></div>
<pre><code>[1] 5 1 3 5 7 11</code></pre>
<p>Doing this makes it possible to calculate for all of the values in <code>vector_1</code> at the same time.
We might, for example, want to multiply all of the numbers by 10.</p>
<div class="sourceCode" id="cb142"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb142-1"><a href="Chapter_36.html#cb142-1" aria-hidden="true" tabindex="-1"></a>vector_1 <span class="sc">*</span> <span class="dv">10</span></span></code></pre></div>
<pre><code>[1] 50 10 30 50 70 110</code></pre>
<p>Variables also do not necessarily need to be numbers.
We might assign a new variable <code>phrase_1</code> to a string of letters.
When doing this, the letters need to be enclosed in quotation marks.</p>
<div class="sourceCode" id="cb144"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb144-1"><a href="Chapter_36.html#cb144-1" aria-hidden="true" tabindex="-1"></a>phrase_1 <span class="ot"><-</span> <span class="st">"string of words"</span>;</span>
<span id="cb144-2"><a href="Chapter_36.html#cb144-2" aria-hidden="true" tabindex="-1"></a>phrase_1;</span></code></pre></div>
<pre><code>[1] "string of words"</code></pre>
<p>We can even combine numbers, vectors, and words into a single object as a list using the <code>list</code> function.</p>
<div class="sourceCode" id="cb146"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb146-1"><a href="Chapter_36.html#cb146-1" aria-hidden="true" tabindex="-1"></a>object_1 <span class="ot"><-</span> <span class="fu">list</span>(var_1, vector_1, phrase_1);</span>
<span id="cb146-2"><a href="Chapter_36.html#cb146-2" aria-hidden="true" tabindex="-1"></a>object_1;</span></code></pre></div>
<pre><code>[[1]]
[1] 10
[[2]]
[1] 5 1 3 5 7 11
[[3]]
[1] "string of words"</code></pre>
<p>There are far too many possibilities to introduce everything about how R works.
The best way to get started is to play around and see what works and what does not.
You will not break anything.
Error messages are good because they can help you learn how R works.</p>
<blockquote>
<p><strong>Task 6: Use the R console until you find a new error message.</strong></p>
</blockquote>
<p>Try something new in the R console.
Keep going until you get an error message that you have not yet seen, then move on to the next exercise.</p>
</div>
<div id="some-descriptive-statistics" class="section level2 hasAnchor" number="36.3">
<h2><span class="header-section-number">36.3</span> Some descriptive statistics<a href="Chapter_36.html#some-descriptive-statistics" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Now we can get started with some statistical analyses.
In <a href="Chapter_39.html#Chapter_39">Chapter 39</a> we will learn how to do some familiar analyses with R scripts and data uploaded from CSV files, but for now, we will just type our data directly into the console.
We can use the data from <a href="Chapter_35.html#randomisation-for-hypothesis-testing">Chapter 35.4</a> as an example.
The code below reads in 2 different variables, <code>SO1</code> and <code>SO2</code>.
The numbers are the same ovipositor lengths from the histograms in Figure 34.2 of <a href="Chapter_35.html#randomisation-for-hypothesis-testing">Chapter 35.4</a>.</p>
<div class="sourceCode" id="cb148"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb148-1"><a href="Chapter_36.html#cb148-1" aria-hidden="true" tabindex="-1"></a>SO1 <span class="ot"><-</span> <span class="fu">c</span>(<span class="fl">3.256</span>, <span class="fl">3.133</span>, <span class="fl">3.071</span>, <span class="fl">2.299</span>, <span class="fl">2.995</span>, <span class="fl">2.929</span>, <span class="fl">3.291</span>, <span class="fl">2.658</span>, <span class="fl">3.406</span>, </span>
<span id="cb148-2"><a href="Chapter_36.html#cb148-2" aria-hidden="true" tabindex="-1"></a> <span class="fl">2.976</span>, <span class="fl">2.817</span>, <span class="fl">3.133</span>, <span class="fl">3.000</span>, <span class="fl">3.027</span>, <span class="fl">3.178</span>, <span class="fl">3.133</span>, <span class="fl">3.210</span>);</span>
<span id="cb148-3"><a href="Chapter_36.html#cb148-3" aria-hidden="true" tabindex="-1"></a>SO2 <span class="ot"><-</span> <span class="fu">c</span>(<span class="fl">3.014</span>, <span class="fl">2.790</span>, <span class="fl">2.985</span>, <span class="fl">2.911</span>, <span class="fl">2.914</span>, <span class="fl">2.724</span>, <span class="fl">2.967</span>, <span class="fl">2.745</span>, <span class="fl">2.973</span>, </span>
<span id="cb148-4"><a href="Chapter_36.html#cb148-4" aria-hidden="true" tabindex="-1"></a> <span class="fl">2.560</span>, <span class="fl">2.837</span>, <span class="fl">2.883</span>, <span class="fl">2.668</span>, <span class="fl">3.063</span>, <span class="fl">2.639</span>);</span></code></pre></div>
<p>Copy and paste the code above into the R console.
You should now have 2 new variables, <code>SO1</code> and <code>SO2</code></p>
<blockquote>
<p><strong>Task 7: Type <code>SO1</code> into the R console to print the ovipositor lengths for species SO1, then do the same for <code>SO2</code></strong>.</p>
</blockquote>
<p>We can replicate the histogram from Figure 35.2A in <a href="Chapter_35.html#randomisation-for-hypothesis-testing">Chapter 35.4</a> with the following code.</p>
<div class="sourceCode" id="cb149"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb149-1"><a href="Chapter_36.html#cb149-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(<span class="at">x =</span> SO1, <span class="at">xlab =</span> <span class="st">"SO1 ovipositor length (mm)"</span>, <span class="at">main =</span> <span class="st">""</span>);</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-210"></span>
<img src="bookdown-demo_files/figure-html/unnamed-chunk-210-1.png" alt="A histogram of SO1 ovipositor lengths that is roughly normally distributed" width="672" />
<p class="caption">
Figure 36.1: Ovipositor length distributions for an unnamed species of fig wasps SO1.
</p>
</div>
<p>The bin widths in Figure 36.1 are not the same as Figure 35.2A because there are other options within <code>hist</code> that have not been specified.
Within <code>hist</code> and other functions, these options such as <code>x</code>, <code>xlab</code>, and <code>main</code> are called <em>arguments</em>.
The word ‘argument’ in this case has nothing to do with a disagreement or logical reasoning.
In this case, it just refers to information that is passed in a function.</p>
<blockquote>
<p><strong>Task 8: Make a histogram of SO2 ovipositor lengths. Try using the argument <code>col = "blue"</code> in the <code>hist</code> function to make the histogram bars blue.</strong></p>
</blockquote>
<p>Now we can try collecting some summary statistics for SO1 and SO2.
In the lab practical from <a href="Chapter_14.html#Chapter_14">Chapter 14</a>, we used jamovi to calculate summary statistics.
Table 36.1 below shows how those same summary statistics can be calculated using functions in R, and the output of each function for SO1.</p>
<table>
<caption><span id="tab:unnamed-chunk-211">Table 36.1: </span>R functions and output for summary statistics applied to a variable (SO1) of ovipositor lengths in an unnamed species of nonpollinating fig wasp.</caption>
<thead>
<tr class="header">
<th align="left">Statistic</th>
<th align="left">Function</th>
<th align="left">Output</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">N</td>
<td align="left"><code>length(SO1)</code></td>
<td align="left">17</td>
</tr>
<tr class="even">
<td align="left">Std. deviation</td>
<td align="left"><code>sd(SO1)</code></td>
<td align="left">0.260018</td>
</tr>
<tr class="odd">
<td align="left">Variance</td>
<td align="left"><code>var(SO1)</code></td>
<td align="left">0.067609</td>
</tr>
<tr class="even">
<td align="left">Minimum</td>
<td align="left"><code>min(SO1)</code></td>
<td align="left">2.299</td>
</tr>
<tr class="odd">
<td align="left">Maximum</td>
<td align="left"><code>max(SO1)</code></td>
<td align="left">3.406</td>
</tr>
<tr class="even">
<td align="left">Range</td>
<td align="left"><code>range(SO1)</code></td>
<td align="left">2.299, 3.406</td>
</tr>
<tr class="odd">
<td align="left">IQR</td>
<td align="left"><code>IQR(SO1)</code></td>
<td align="left">0.202</td>
</tr>
<tr class="even">
<td align="left">Mean</td>
<td align="left"><code>mean(SO1)</code></td>
<td align="left">3.030118</td>
</tr>
<tr class="odd">
<td align="left">Median</td>
<td align="left"><code>median(SO1)</code></td>
<td align="left">3.071</td>
</tr>
</tbody>
</table>
<p>Notice that the <code>range</code> function gives the minimum and maximum of SO1, so we need to subtract the latter from the former to get the actual range.</p>
<blockquote>
<p><strong>Task 9: Calculate the summary statistics in Table 35.1 for SO2.</strong></p>
</blockquote>
<p>There is no function for standard error in R.
We could write a custom function to calculate the standard error, but for now we can just use the formula from <a href="Chapter_12.html#the-standard-error">Chapter 12.6</a> to calculate the standard error of SO1,</p>
<p><span class="math display">\[SE = \frac{s}{\sqrt{N}}.\]</span></p>
<p>Since we have the standard deviation (<span class="math inline">\(s\)</span>) and sample size (<span class="math inline">\(N\)</span>) from Table 36.1, we can calculate SE in R,</p>
<div class="sourceCode" id="cb150"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb150-1"><a href="Chapter_36.html#cb150-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sd</span>(SO1) <span class="sc">/</span> <span class="fu">sqrt</span>( <span class="fu">length</span>(SO1) );</span></code></pre></div>
<pre><code>[1] 0.06306363</code></pre>
<p>The code above calculates the standard deviation of SO1 (<code>sd(SO1)</code>), then divides (<code>/</code>) by the square root (<code>sqrt()</code>) of the length of SO1 (<code>length(SO1)</code>).
This can be difficult to read because <code>length(SO1)</code> is enclosed in <code>sqrt()</code>.
But we can break this down step by step to make it easier to read by assigning each component to a new variable.</p>
<div class="sourceCode" id="cb152"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb152-1"><a href="Chapter_36.html#cb152-1" aria-hidden="true" tabindex="-1"></a>SO1_SD <span class="ot"><-</span> <span class="fu">sd</span>(SO1); <span class="co"># Assign the standard deviation</span></span>
<span id="cb152-2"><a href="Chapter_36.html#cb152-2" aria-hidden="true" tabindex="-1"></a>SO1_N <span class="ot"><-</span> <span class="fu">length</span>(SO1); <span class="co"># Assign the N</span></span>
<span id="cb152-3"><a href="Chapter_36.html#cb152-3" aria-hidden="true" tabindex="-1"></a>SO1_SD <span class="sc">/</span> <span class="fu">sqrt</span>(SO1_N); <span class="co"># Do the calculation for SE</span></span></code></pre></div>
<pre><code>[1] 0.06306363</code></pre>
<p>We can do the same for SO2.</p>
<blockquote>
<p><strong>Task 10: Calculate the standard error of SO2 ovipositor lengths.</strong></p>
</blockquote>
<p>With the standard error now calculated, we can also calculate 95 per cent confidence intervals using the formula from <a href="Chapter_18.html#Chapter_18">Chapter 18</a>, just as we did for SO1 in <a href="Chapter_35.html#bootstrapping">Chapter 35.5</a>,</p>
<p><span class="math display">\[LCI = 3.03 - \left(2.120 \times \frac{0.26}{\sqrt{17}}\right),\]</span></p>
<p><span class="math display">\[UCI = 3.03 + \left(2.120 \times \frac{0.26}{\sqrt{17}}\right).\]</span></p>
<p>Note that 3.03 is the mean from Table 36.1, and <span class="math inline">\(0.26/\sqrt{17}\)</span> is the standard error that we just calculated for SO1.
The value 2.120 is the t-score associated with df = 17 - 1, i.e., 16 degrees of freedom (see <a href="Chapter_35.html#bootstrapping">Chapter 35.5</a>).
As in <a href="Chapter_35.html#bootstrapping">Chapter 35.5</a>, we get values of LCI = 2.896 and UCI = 3.164.</p>
<blockquote>
<p><strong>Task 10: Calculate 95 per cent confidence intervals for SO2 ovipositor lengths (hint: the appropriate t value for df = 14 is 2.145 instead of 2.120).</strong></p>
</blockquote>
<p>In the last exercise, we will attempt to bootstrap these confidence intervals using the method introduced in <a href="Chapter_35.html#bootstrapping">Chapter 35.5</a>.</p>
</div>
<div id="bootstrapping-confidence-intervals" class="section level2 hasAnchor" number="36.4">
<h2><span class="header-section-number">36.4</span> Bootstrapping confidence intervals<a href="Chapter_36.html#bootstrapping-confidence-intervals" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Writing resampling and randomisation procedures in R requires some knowledge of coding.
For now, all that you need to do is copy a pre-defined function into R and use it like any other function.
The function is called <code>simpleboot</code>.</p>
<div class="sourceCode" id="cb154"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb154-1"><a href="Chapter_36.html#cb154-1" aria-hidden="true" tabindex="-1"></a>simpleboot <span class="ot"><-</span> <span class="cf">function</span>(x, <span class="at">replicates =</span> <span class="dv">1000</span>, <span class="at">CIs =</span> <span class="fl">0.95</span>){</span>
<span id="cb154-2"><a href="Chapter_36.html#cb154-2" aria-hidden="true" tabindex="-1"></a> alpha <span class="ot"><-</span> <span class="dv">1</span> <span class="sc">-</span> CIs;</span>
<span id="cb154-3"><a href="Chapter_36.html#cb154-3" aria-hidden="true" tabindex="-1"></a> vals <span class="ot"><-</span> <span class="cn">NULL</span>; </span>
<span id="cb154-4"><a href="Chapter_36.html#cb154-4" aria-hidden="true" tabindex="-1"></a> i <span class="ot"><-</span> <span class="dv">0</span>; </span>
<span id="cb154-5"><a href="Chapter_36.html#cb154-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span>(i <span class="sc"><</span> replicates){ </span>
<span id="cb154-6"><a href="Chapter_36.html#cb154-6" aria-hidden="true" tabindex="-1"></a> boot <span class="ot"><-</span> <span class="fu">sample</span>(<span class="at">x =</span> x, <span class="at">size =</span> <span class="fu">length</span>(x), <span class="at">replace =</span> <span class="cn">TRUE</span>); </span>
<span id="cb154-7"><a href="Chapter_36.html#cb154-7" aria-hidden="true" tabindex="-1"></a> strap <span class="ot"><-</span> <span class="fu">mean</span>(boot); </span>
<span id="cb154-8"><a href="Chapter_36.html#cb154-8" aria-hidden="true" tabindex="-1"></a> vals <span class="ot"><-</span> <span class="fu">c</span>(vals, strap); </span>
<span id="cb154-9"><a href="Chapter_36.html#cb154-9" aria-hidden="true" tabindex="-1"></a> i <span class="ot"><-</span> i <span class="sc">+</span> <span class="dv">1</span>; </span>
<span id="cb154-10"><a href="Chapter_36.html#cb154-10" aria-hidden="true" tabindex="-1"></a> } </span>
<span id="cb154-11"><a href="Chapter_36.html#cb154-11" aria-hidden="true" tabindex="-1"></a> vals <span class="ot"><-</span> <span class="fu">sort</span>(<span class="at">x =</span> vals, <span class="at">decreasing =</span> <span class="cn">FALSE</span>); </span>
<span id="cb154-12"><a href="Chapter_36.html#cb154-12" aria-hidden="true" tabindex="-1"></a> lowCI <span class="ot"><-</span> vals[<span class="fu">round</span>((alpha<span class="sc">*</span><span class="fl">0.5</span>)<span class="sc">*</span>replicates)]; </span>
<span id="cb154-13"><a href="Chapter_36.html#cb154-13" aria-hidden="true" tabindex="-1"></a> highCI <span class="ot"><-</span> vals[<span class="fu">round</span>((<span class="dv">1</span><span class="sc">-</span>(alpha<span class="sc">*</span><span class="fl">0.5</span>))<span class="sc">*</span>replicates)]; </span>
<span id="cb154-14"><a href="Chapter_36.html#cb154-14" aria-hidden="true" tabindex="-1"></a> confid <span class="ot"><-</span> <span class="fu">c</span>(lowCI, highCI); </span>
<span id="cb154-15"><a href="Chapter_36.html#cb154-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">list</span>(vals, confid)); </span>
<span id="cb154-16"><a href="Chapter_36.html#cb154-16" aria-hidden="true" tabindex="-1"></a>} </span></code></pre></div>
<p>The <code>simpleboot</code> function takes a variable (<code>x</code>) as an argument, bootstraps mean values <code>replicates</code> times, and produces confidence intervals at a level <code>CIs</code>.
To use it, highlight and copy the entire function, then put it into the R console.
Make sure that every line from <code>simpleboot</code> to the last <code>}</code> is copied.
Once it has been placed into the R console, it can be used just like any other function.
For example, we can run <code>simpleboot</code> and store the output for SO1 values.</p>
<div class="sourceCode" id="cb155"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb155-1"><a href="Chapter_36.html#cb155-1" aria-hidden="true" tabindex="-1"></a>SO1_95s <span class="ot"><-</span> <span class="fu">simpleboot</span>(<span class="at">x =</span> SO1, <span class="at">replicates =</span> <span class="dv">1000</span>, <span class="at">CIs =</span> <span class="fl">0.95</span>);</span></code></pre></div>
<p>The output will include a list of 2 different objects.
The first object <code>SO1_95s[[1]]</code> will be a list of 1000 bootstrapped mean values, sorted from lowest to highest.
The second object <code>SO1_95s[[2]]</code> will be the bootstrapped upper and lower confidence intervals.
First, we can take a look at a histogram of the bootstrapped mean values.</p>
<div class="sourceCode" id="cb156"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb156-1"><a href="Chapter_36.html#cb156-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(<span class="at">x =</span> SO1_95s[[<span class="dv">1</span>]], <span class="at">xlab =</span> <span class="st">"Bootstrapped SO1 means"</span>, <span class="at">main =</span> <span class="st">""</span>);</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-216"></span>
<img src="bookdown-demo_files/figure-html/unnamed-chunk-216-1.png" alt="A histogram bootstrapped mean SO1 values that appears to be roughly normally distributed" width="672" />
<p class="caption">
Figure 36.2: Bootstrapped mean values for 17 ovipositor lengths in an unnamed species of fig wasp collected in Baja, Mexico.
</p>
</div>
<p>We can then print out the lower and upper confidence intervals, which report the value of the 2.5 per cent rank and 97.5 rank bootstrapped means, respectively.</p>
<div class="sourceCode" id="cb157"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb157-1"><a href="Chapter_36.html#cb157-1" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(SO1_95s[[<span class="dv">2</span>]]);</span></code></pre></div>
<pre><code>[1] 2.894941 3.136000</code></pre>
<p>Note that these values are not too far off the values of LCI = 2.896 and UCI = 3.164 calculated in the usual way in the previous exercise.</p>
<blockquote>
<p><strong>Task 11: Use the <code>simpleboot</code> function to calculate 95 per cent confidence intervals for SO2 mean ovipositor lengths.</strong></p>
</blockquote>
<p>The practical in <a href="Chapter_39.html#Chapter_39">Chapter 39</a> will demonstrate how to read CSV files into R and run hypothesis tests, including t-tests, ANOVAs, chi-square tests, correlation tests, and linear regression.</p>
</div>
</div>
<div class="footnotes">
<hr />
<ol start="88">
<li id="fn88"><p><a href="https://cran.r-project.org/">https://cran.r-project.org/</a><a href="Chapter_36.html#fnref88" class="footnote-back">↩︎</a></p></li>
<li id="fn89"><p><a href="https://posit.co/download/rstudio-desktop/#download">https://posit.co/download/rstudio-desktop/#download</a><a href="Chapter_36.html#fnref89" class="footnote-back">↩︎</a></p></li>
</ol>
</div>
</section>
</div>
</div>
</div>
<a href="Chapter_35.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="Week12.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/rstudio/bookdown-demo/edit/master/10-Randomisation.Rmd",
"text": "Edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "subsection"
}
});
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
var src = "true";
if (src === "" || src === "true") src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/latest.js?config=TeX-MML-AM_CHTML";
if (location.protocol !== "file:")
if (/^https?:/.test(src))
src = src.replace(/^https?:/, '');
script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>