-
Notifications
You must be signed in to change notification settings - Fork 5
/
tutorials.html
1327 lines (1228 loc) · 172 KB
/
tutorials.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
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="R-Girls" />
<meta name="progressive" content="false" />
<meta name="allow-skip" content="false" />
<title>Math Lessons</title>
<!-- HEAD_CONTENT -->
<!-- highlightjs -->
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<!-- taken from https://github.com/rstudio/rmarkdown/blob/67b7f5fc779e4cfdfd0f021d3d7745b6b6e17149/inst/rmd/h/default.html#L296-L362 -->
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<script>
$(document).ready(function () {
window.buildTabsets("section-TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open')
});
});
</script>
<!-- end tabsets -->
<link rel="stylesheet" href="css/custom.css" type="text/css" />
</head>
<body>
<div class="pageContent band">
<div class="bandContent page">
<div class="topics">
<div id="section-generating-sequences-part-1" class="section level2">
<h2>Generating Sequences Part 1</h2>
<div id="section-lesson-objectives" class="section level3">
<h3>Lesson objectives</h3>
<ul>
<li>Generating sequences using R code</li>
</ul>
</div>
<div id="section-packages-used-in-this-lesson" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
</ul>
</div>
<div id="section-success-criteria" class="section level3">
<h3>Success criteria</h3>
<ul>
<li>Generate different sequences using R code</li>
</ul>
</div>
<div id="section-keywords" class="section level3">
<h3>Keywords</h3>
<ul>
<li>sequence</li>
<li>term = the numbers in the sequence</li>
<li>nth term</li>
</ul>
</div>
<div id="section-worked-example-1" class="section level3">
<h3>Worked Example 1</h3>
<p>First we will tell R to generate a sequence.</p>
This is how you generate a sequence of numbers from 1 to 100 where the terms increase by 1.
<div class="tutorial-exercise" data-label="chunk11" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>seq(from=1,to=100,by=1)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Use the above example R code in chunk1 to generate the following sequences. Remember to edit the numbers in the code.</p>
<div id="section-activity-1-questions" class="section level4">
<h4>Activity 1 Questions</h4>
<p>Q1 Generate a sequence from 1 to 100 where the terms increase by 10</p>
<div class="tutorial-exercise" data-label="chunk21" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- c(0, 0.5, 0)
y <- c(0, 0, 1.5)
plot(x,y,axes=F, ylab='', xlab='', xlim=c(-0.3,2), ylim=c(-0.3,2))
polygon(x, y, col = 'deeppink')
text(0.2,-0.1, "b=14cm")
text(-0.2,0.5, "a=20cm")
text(0.5,0.5, "c")</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q2 Generate a sequence from 5 to 95 where the terms increase by 5.
<div class="tutorial-exercise" data-label="chunk31" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q3 Generate a sequence from 3 to 399 where the terms increase by 4.
<div class="tutorial-exercise" data-label="chunk41" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q4 Generate a sequence from 1 to 9 where the terms increase by 3.
<div class="tutorial-exercise" data-label="chunk51" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-worked-example-2" class="section level3">
<h3>Worked Example 2</h3>
<p>Now we will generate a sequence that starts from a number and goes up to the nth term, where the nth term is for example 10.</p>
For example a sequence from 1 where the terms go up by 1 till the 10th term.
<div class="tutorial-exercise" data-label="chunk61" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>seq(from=1, length.out=10, by=1)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Use the above example R code in chunk6 to generate the following sequences.</p>
<p>Knit your document after each question to check your sequence.</p>
<div id="section-activity-2-questions" class="section level4">
<h4>Activity 2 Questions</h4>
<p>Q1 Generate a sequence from 1 where the terms go up by 4 up to the 100th term</p>
<div class="tutorial-exercise" data-label="chunk71" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q2 Generate a sequence from 5 where the terms go up by 10 up to the 89th term
<div class="tutorial-exercise" data-label="chunk81" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q3 Generate a sequence from 3 where the terms go up by 3 up to the 33rd term
<div class="tutorial-exercise" data-label="chunk91" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-worked-example-3" class="section level3">
<h3>Worked Example 3</h3>
<p>So the terms have increased by a particular number, but we can also decrease by a number and produce a backward sequence.</p>
<p>For example, we can sequence from 100 to 1 by -1</p>
<div class="tutorial-exercise" data-label="chunk101" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>seq(from=100, to=1, by=-1)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Use the above example R code in chunk10 to answer the following questions.</p>
<p>Knit your document after each question to check your sequence is correct.</p>
<div id="section-activity-3-questions" class="section level4">
<h4>Activity 3 Questions</h4>
Q1 Generate a sequence that goes down from 50 to 0 where the terms go down by 5.
<div class="tutorial-exercise" data-label="chunk111" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q2 Generate a sequence from 10 to -10 where the terms go down by 1.
<div class="tutorial-exercise" data-label="chunk121" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q3 Generate a sequence that goes down from 20 to 10 where the terms go down by 2.
<div class="tutorial-exercise" data-label="chunk141" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
</div>
<div id="section-generating-sequences-part-2" class="section level2">
<h2>Generating Sequences Part 2</h2>
<div id="section-lesson-objectives-1" class="section level3">
<h3>Lesson objectives</h3>
<ul>
<li>Investigating sequences</li>
</ul>
</div>
<div id="section-packages-used-in-this-lesson-1" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
</ul>
</div>
<div id="section-success-criteria-1" class="section level3">
<h3>Success criteria</h3>
<ul>
<li>Find the relationship between the terms</li>
<li>Does a number lie in a sequence</li>
<li>Find a missing term in the sequence</li>
</ul>
</div>
<div id="section-keywords-1" class="section level3">
<h3>Keywords</h3>
<ul>
<li>sequence</li>
<li>term</li>
<li>nth term</li>
</ul>
<div id="section-worked-example-1-1" class="section level4">
<h4>Worked Example 1</h4>
<p>This is how you find the difference between the terms in a sequence.</p>
<p>The sequence is 3, 7, 11, 15.</p>
<p>Knit your document to see the sequence generated by the R code in chunk1.</p>
<div class="tutorial-exercise" data-label="chunk1" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- c(3,7,11,15)
diff(x)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>The R code tells you the difference between each number in the sequence.</p>
<div id="section-activity-1-questions-1" class="section level5">
<h5>Activity 1 Questions</h5>
<p>Now use the above example R code in chunk1 to find the difference between the terms in the following sequences</p>
<p>Knit the document after each question to see the answer. Check your answer.</p>
Q1 2,7,12,17,22
<div class="tutorial-exercise" data-label="chunk2" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q2 3,9,15,21,27
<div class="tutorial-exercise" data-label="chunk3" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
Q3 1,4,10,19,31
<div class="tutorial-exercise" data-label="chunk4" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-worked-example-2-1" class="section level4">
<h4>Worked Example 2</h4>
<p>Now we will see if a number lies in a sequence.</p>
<p>First we will generate the first 20 terms of the sequence 3,7,11,15 and then we will see if the numbers 55 and 56 lie in the sequence. The computer will generate the sequence and if it finds the number it will report it below the sequence. If it does not find it then it will say numeric (0).</p>
<div class="tutorial-exercise" data-label="chunk5" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(from=3, length.out=20, by=4)
x
x[x==55]
x[x==56]</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Use the above example R code in chunk5 to answer the following questions.</p>
<p>Remember to tell R how many terms you want it to generate by editing the length.out number. Remember to tell R what numbers to look for in the sequence by editing the x== numbers.</p>
<div id="section-activity-2-questions-1" class="section level5">
<h5>Activity 2 Questions</h5>
<p>Q1 Generate the first 100 terms of the sequence 3,7,11,15 and see if the numbers 117 and 395 lie in the sequence. Do they?</p>
<div class="tutorial-exercise" data-label="chunk6" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-worked-example-3-1" class="section level4">
<h4>Worked Example 3</h4>
<p>Now we will find the missing number in a sequence. Our sequence is 4, ?, 16, 22. Term 2 is missing. So we generate the sequence based on what we know which is that the difference between 16 and 22 is 6. The computer will put in the missing term.</p>
<div class="tutorial-exercise" data-label="chunk7" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>seq(from=4, to=22, by=6)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Answer: The missing term is 10.</p>
<p>Use the above example R code to answer the following questions.</p>
<p>Remember to knit to see your results.</p>
<div id="section-activity-3-questions-1" class="section level5">
<h5>Activity 3 Questions</h5>
<p>Q1 What is the missing term in the sequence 3,12,?,30.</p>
<div class="tutorial-exercise" data-label="chunk8" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
</div>
</div>
<div id="section-using-pythagoras-theorem" class="section level2">
<h2>Using Pythagoras’ Theorem</h2>
<div id="section-lesson-objective" class="section level3">
<h3>Lesson Objective</h3>
<p>Use Pythagoras’ Theorem to find the lengths of missing sides of a right angle triangle</p>
</div>
<div id="section-packages-used-in-this-lesson-2" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
</ul>
</div>
<div id="section-success-criteria-2" class="section level3">
<h3>Success criteria</h3>
<p>Write the R code to work out the missing side</p>
<p>Calculate the missing side</p>
</div>
<div id="section-keywords-2" class="section level3">
<h3>Keywords</h3>
<ul>
<li>Pythagoras theorem</li>
<li>Length of a side</li>
<li>Hypotenuse</li>
<li>square</li>
<li>square root</li>
</ul>
<div id="section-worked-example-1-finding-the-hypotenuse" class="section level4">
<h4>Worked Example 1: Finding the hypotenuse</h4>
<p>First knit the document so that you can see images of the triangles and the formulae you will be working with.</p>
<p>This is a worked example for you to follow.</p>
<p>The formula to find c is: <span class="math display">\[c = \sqrt{a^2 + b^2}\]</span></p>
<p>Check how the formula is written in the output .</p>
<p>Run the R code in chunk1 by clicking on the little arrow to the right of the code chunk. This will draw you the triangle that you are working with below the code chunk.</p>
<div class="tutorial-exercise" data-label="chunk21" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- c(0, 0.5, 0)
y <- c(0, 0, 1.5)
plot(x,y,axes=F, ylab='', xlab='', xlim=c(-0.3,2), ylim=c(-0.3,2))
polygon(x, y, col = 'deeppink')
text(0.2,-0.1, "b=14cm")
text(-0.2,0.5, "a=20cm")
text(0.5,0.5, "c")</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>The length of side c is missing.</p>
<p>The R code in chunk2 below works out the missing side c. Click on the little arrow on the right of the chunk to run the code.</p>
<p>The answer will be shown below the code chunk.</p>
<div class="tutorial-exercise" data-label="chunk22" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>a <- 20
b <- 14
c <- sqrt(a^2+b^2)
c</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>The length of <span class="math inline">\(c = r round(c,2)\)</span> cm</p>
<p>The inline code above tells R to round c to 2 decimal places. Knit the document to check this.</p>
</div>
<div id="section-activity1-your-turn" class="section level4">
<h4>Activity1: Your turn</h4>
<p>Run R code chunk3. This will draw you the triangle with the length of side c missing.</p>
<div class="tutorial-exercise" data-label="chunk23" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- c(0, 0.5, 0.5)
y <- c(0, 0, 1.5)
plot(x,y,axes=F, ylab='', xlab='', xlim=c(-0.3,2), ylim=c(-0.3,2))
polygon(x, y, col = 'deeppink')
text(0.2,-0.1, "b=4cm")
text(0.7,0.5, "a=15cm")
text(0.1,0.5, "c")</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Write your own code in chunk4 to find length c in the triangle where a = 15 cm and b = 4 cm.</p>
<p>Use the code in chunk2 to help you.</p>
<div class="tutorial-exercise" data-label="chunk24" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-worked-example-2-2" class="section level4">
<h4>Worked Example 2</h4>
<p>Use Pythagoras’ theorem to find one of the other sides.</p>
<p>So find the length of side a when b = 14 cm and c = 25 cm.</p>
<p>Knit the document to see the formula and triangle.</p>
<p>The formula to find the length of side a is: <span class="math display">\[a= \sqrt{c^2 - b^2}\]</span></p>
<p>The code in chunk5 will draw the triangle for you.</p>
<div class="tutorial-exercise" data-label="chunk25" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- c(0, 0.8, 0)
y <- c(0, 0, 1.5)
plot(x,y,axes=F, ylab='', xlab='', xlim=c(-0.3,2), ylim=c(-0.3,2))
polygon(x, y, col = 'deeppink')
text(0.4,-0.1, "b=14cm")
text(-0.2,0.5, "a")
text(0.6,0.9, "c=25cm")</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>The code in Chunk6 calculates the length of side a when b and c are known.</p>
<p>Run the code by clicking on the little arrow on the right of the code.</p>
<div class="tutorial-exercise" data-label="chunk26" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>b <- 14
c <- 25
a <- sqrt(c^2-b^2)
a</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>The length of a = r round(a,2) cm.</p>
</div>
<div id="section-activity2-your-turn" class="section level4">
<h4>Activity2: Your turn</h4>
<p>Use the R code from the above examples to help you find the missing sides in the table below</p>
<table>
<thead>
<tr class="header">
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>36</td>
<td></td>
<td>81</td>
</tr>
<tr class="even">
<td></td>
<td>9</td>
<td>49</td>
</tr>
<tr class="odd">
<td>10</td>
<td>10</td>
<td></td>
</tr>
</tbody>
</table>
<p>Find length b when a=36 and c=81</p>
<div class="tutorial-exercise" data-label="chunk27" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Answer b =</p>
<p>Find length a when b=9 and c=49</p>
<div class="tutorial-exercise" data-label="chunk28" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>a</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Find length c when a=10 and b=10</p>
<div class="tutorial-exercise" data-label="chunk29" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>c </code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-extension" class="section level3">
<h3>Extension</h3>
<p>Can you round your answers from code chunks 7, 8 and 9 to 2 decimal places? Use the space below and knit the document to see if you have been successful.</p>
<div class="tutorial-exercise" data-label="chunk30" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
<div id="section-finding-the-equation---part-1" class="section level2">
<h2>Finding the Equation - Part 1</h2>
<div id="section-lesson-objectives-2" class="section level3">
<h3>Lesson objectives</h3>
<ul>
<li>Plotting straight line graphs <span class="math inline">\(y=mx+c\)</span></li>
</ul>
</div>
<div id="section-packages-used-in-this-lesson-3" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
</ul>
</div>
<div id="section-success-criteria-3" class="section level3">
<h3>Success criteria</h3>
<ul>
<li>Plot a straight line graph <span class="math inline">\(y = mx+c\)</span></li>
<li>Compare graphs</li>
</ul>
</div>
<div id="section-keywords-3" class="section level3">
<h3>Keywords</h3>
<ul>
<li>slope</li>
<li>gradient = m</li>
<li>intercept = c</li>
<li>x-axis</li>
<li>y-axis</li>
</ul>
<div id="section-worked-example-1-2" class="section level4">
<h4>Worked Example 1</h4>
<p>This is a worked example for you to follow.</p>
<p>We will show you how to plot the line graph for <span class="math inline">\(y=2x + 5\)</span>.</p>
<div class="tutorial-exercise" data-label="chunk16" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(from=-4, to=4, by=1) # sequence the x-axis from -4 to 4
y <- 2*x+5
mydata <- tibble (x,y)
ggplot(mydata) +
aes(x,y) +
geom_line (col='red')+
geom_vline (xintercept = 0, col='black')+
geom_hline (yintercept = 0, col='black')</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Now close the image by clicking on the X to the right of the graph</p>
</div>
<div id="section-activity1" class="section level4">
<h4>Activity1:</h4>
<p>Write your own code to draw the following graphs.</p>
<p>Use code chunk1 from the example above to help you.</p>
<ol style="list-style-type: decimal">
<li>y = 2x (in code chunk2)</li>
<li>y = 3x + 10 (in code chunk3)</li>
<li>y = 5x + 2.5 (in code chunk4)</li>
</ol>
<div class="tutorial-exercise" data-label="chunk26" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>b <- 14
c <- 25
a <- sqrt(c^2-b^2)
a</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<div class="tutorial-exercise" data-label="chunk36" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<div class="tutorial-exercise" data-label="chunk46" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code># we can calculate the five number summary like this
summary(y) # five number summary but also provides the mean
IQR(y) # inter-quartile range</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-worked-example-2-3" class="section level4">
<h4>Worked Example 2</h4>
<p>Drawing more than one line on a graph helps us to compare the lines and see what is the same and what is different. Here is a worked example for four different lines.</p>
<ol style="list-style-type: decimal">
<li>y=3x+0</li>
<li>y=3x+1</li>
<li>y=3x+2</li>
<li>y=3x+3</li>
</ol>
<div class="tutorial-exercise" data-label="chunk56" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(-4, 4) # sequence from -4 to 4
y1 <- 3*x+0
y2 <- 3*x+1
y3 <- 3*x+2
y4 <- 3*x+3
mydata <- tibble (x,y1,y2,y3,y4)
ggplot(mydata) +
geom_line (aes(x=x, y=y1), col='red')+
geom_line (aes(x=x, y=y2), col='blue')+
geom_line (aes(x=x, y=y3), col='green')+
geom_line (aes(x=x, y=y4), col='grey') +
geom_vline (xintercept = 0, col='black')+
geom_hline (yintercept = 0, col='black')</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Question: From the graph what looks the same and what looks different about these lines?</p>
<p>Answer:</p>
</div>
<div id="section-activity2" class="section level4">
<h4>Activity2:</h4>
<p>Draw the following lines on a graph</p>
<ol style="list-style-type: decimal">
<li>y=1x+5</li>
<li>y=2x+5</li>
<li>y=3x+5</li>
<li>y=4x+5</li>
</ol>
<p>Use code chunk5 from the example above to help you. Remember to update the R code with the new lines.</p>
<p>Run the code. Knit the document.</p>
<div class="tutorial-exercise" data-label="chunk66" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Question: What is the same and what is different about the lines?</p>
<div class="tutorial-exercise" data-label="chunk66" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
</div>
<div id="section-finding-the-equation---part-2" class="section level2">
<h2>Finding the Equation - Part 2</h2>
<div id="section-lesson-objectives-3" class="section level3">
<h3>Lesson objectives</h3>
<p>Plotting and finding the equations of straight line graphs <span class="math inline">\(y=mx+c\)</span></p>
</div>
<div id="section-packages-used-in-this-lesson-4" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
</ul>
</div>
<div id="section-success-criteria-4" class="section level3">
<h3>Success criteria</h3>
<ul>
<li>Plot a straight line graph <span class="math inline">\(y = mx+c\)</span></li>
<li>Plot straight line graphs <span class="math inline">\(y = mx+c\)</span> with different intercepts</li>
<li>Plot a straight line graph <span class="math inline">\(y = mx+c\)</span> with a negative gradient</li>
<li>Find the equations of straight line graphs</li>
</ul>
</div>
<div id="section-keywords-4" class="section level3">
<h3>Keywords</h3>
<ul>
<li>slope</li>
<li>gradient</li>
<li>intercept</li>
<li>x-axis</li>
<li>y-axis</li>
</ul>
<div id="section-worked-example-1-3" class="section level4">
<h4>Worked Example 1</h4>
<p>This is a worked example for you to follow.</p>
<p>We will show you how to plot the line graph for y=2x + 5.</p>
<div class="tutorial-exercise" data-label="chunk13" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(from=-4, to=4, by=1) # sequence the x-axis from -4 to 4
y <- 2*x+5
mydata <- tibble (x,y)
ggplot(mydata) +
aes(x,y) +
geom_point () +
geom_line (col='red')+
geom_vline (xintercept = 0, col='black')+
geom_hline (yintercept = 0, col='black')</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-worked-example-2-4" class="section level4">
<h4>Worked Example 2</h4>
<p>We will now see what happens when you change the intercept c to a negative value.</p>
<ol style="list-style-type: decimal">
<li>y=3x+5</li>
<li>y=3x-5</li>
</ol>
<p>Run the code in chunk2 by clicking on the little arrow on the right of the code chunk.</p>
<div class="tutorial-exercise" data-label="chunk55" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(-4, 4) # sequence from -4 to 4
y1 <- 3*x+5
y2 <- 3*x-5
mydata <- tibble (x,y1,y2,y)
ggplot(mydata) +
geom_line (aes(x=x, y=y1), col='red')+
geom_line (aes(x=x, y=y2), col='blue')+
geom_vline (xintercept = 0, col='black')+
geom_hline (yintercept = 0, col='black')</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Question: What is the same and what is different about these lines?</p>
<p>Knit your document and check the output.</p>
</div>
<div id="section-activity-1" class="section level4">
<h4>Activity 1</h4>
<p>Draw these lines on a graph. Use the R code from chunk2 to help you. Remember to update the code with these new lines.</p>
<ol style="list-style-type: decimal">
<li>y=x+10</li>
<li>y=x-10</li>
</ol>
<div class="tutorial-exercise" data-label="chunk33" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Question: What is the same and what is different about these lines?</p>
</div>
<div id="section-activity-2" class="section level4">
<h4>Activity 2</h4>
<p>Now we will investigate m (the gradient). Draw these lines on a graph. Use R code from chunk2 to help you.</p>
<p>Run the code and knit the document.</p>
<ol style="list-style-type: decimal">
<li>y=-2x+5</li>
<li>y= 2x+5</li>
</ol>
<div class="tutorial-exercise" data-label="chunk43" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>y <- c(29,21,16,25,21,19,18,30,21,21,12,26,19,21,20,19,30,29,16,21,18,18,27,18,20)
boxplot(y, xlab="Times (mins)", horizontal=T)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Question: What is the same and what is different about these lines?</p>
</div>
<div id="section-activity-3-answer-the-following-questions" class="section level4">
<h4>Activity 3 Answer the following questions</h4>
<div class="tutorial-exercise" data-label="chunk53" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>cat ("Q1 In the equation y=mx+c, what happens when you change c?")
cat ("Q2 What happens when you change m?")</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-activity-4-work-out-the-equation-from-a-line-graph" class="section level4">
<h4>Activity 4: Work out the equation from a line graph</h4>
<p>Write down the equations of the following four lines on the graph below.</p>
<p>Knit the document to get a good view of the graph.</p>
<div class="tutorial-exercise" data-label="chunk63" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x <- seq(-10, 10)
y <- x
ggplot() +
aes(x,y)+
geom_blank()+
geom_abline(slope=1, intercept=0, col='red')+
geom_abline(slope=-1, intercept=2.5, col='cyan')+
geom_abline(slope=2, intercept=10, col='blue')+
geom_abline(slope=0, intercept=5, col='orange')+
geom_vline (xintercept=0, col='black')+
geom_hline (yintercept=0, col='black')</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
</div>
</div>
<div id="section-representing-data-with-boxplots" class="section level2">
<h2>Representing Data with boxplots</h2>
<div id="section-lesson-objectives-4" class="section level3">
<h3>Lesson objectives</h3>
<ul>
<li>To understand how to visualise the shape of data using box plots<br />
</li>
<li>To produce box plots and the related five number summary<br />
</li>
<li>To interpret box plots<br />
</li>
</ul>
</div>
<div id="section-packages-used-in-this-lesson-5" class="section level3">
<h3>Packages used in this lesson:</h3>
<ul>
<li><code>tidyverse</code></li>
<li><code>astsa</code></li>
</ul>
</div>
<div id="section-success-criteria-5" class="section level3">
<h3>Success criteria</h3>
<ul>
<li>Draw a box plot using R code</li>
<li>Produce a five number summary using R code</li>
<li>Read data from a box plot</li>
<li>Compare two box plots</li>
</ul>
</div>
<div id="section-keywords-5" class="section level3">
<h3>Keywords</h3>
<p>box plot, minimum, maximum, lower quartile, median, upper quartile, five number summary, inter-quartile range, range</p>
</div>
<div id="section-what-is-a-box-plot" class="section level3">
<h3>What is a box plot</h3>
<p>A box plot is a way to show the shape or distribution of a set of data. It shows five useful features of the data, known as the five number summary.</p>
<p>Minimum - the smallest value Maximum - the largest value<br />
Median - the middle or 50% value<br />
Lower quartile - the value half way between the minimum and the median or 25% value<br />
Upper quartile - the value half way between the median and the maximum or 75% value<br />
</p>
<p>The difference between the upper and lower quartile is known as the inter-quartile range (IQR)</p>
</div>
<div id="section-worked-example-1-4" class="section level3">
<h3>Worked Example 1</h3>
<p>Zaynab keeps a record of her journey times to school each morning. The times are to the nearest minute:</p>
<p>29,21,16,25,21,19,18,30,21,21,12,26,19,21,20,19,30,29,16,21,18,18,27,18,20</p>
<p>Let us draw a box plot and obtain the five number summary and the inter-quartile range (IQR). We will do this in three steps.</p>
<p>The R code in chunk1 tells R to store all the times into a variable called y and then to use these times to draw a box plot of the data.</p>
<div class="tutorial-exercise" data-label="chunk43" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>y <- c(29,21,16,25,21,19,18,30,21,21,12,26,19,21,20,19,30,29,16,21,18,18,27,18,20)
boxplot(y, xlab="Times (mins)", horizontal=T)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>To help us read values from the box plot it is useful to have gridlines on the plot.<br />
Here is a simple trick to get gridlines on the plot.</p>
<p>The code in chunk2 tells R to use the numbers it store in variable y to draw a box plot and then to add grid lines.</p>
<p>Click on the little arrow on the right of the code chunk. The box plot will be drawn below the chunk.</p>
<div class="tutorial-exercise" data-label="chunk45" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code># we can calculate the five number summary like this
boxplot(y, xlab="Times (mins)", horizontal=T)
Grid()
boxplot(y, xlab="Times (mins)", horizontal=T, add=T)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>We can also get R to calculate the five number summary for us.</p>
<div class="tutorial-exercise" data-label="chunk46" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code># we can calculate the five number summary like this
summary(y) # five number summary but also provides the mean
IQR(y) # inter-quartile range</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-activity-1-1" class="section level3">
<h3>Activity 1:</h3>
<p>Produce a box plot, the five number summary and IQR of the following data</p>
<p>Aisha records the length of time spent by each member of her class on their last English homework assignment.</p>
<p>The times are recorded to the nearest minute.</p>
<p>85,124,55,140,120,61,95,105,118,180,55,78,130,112,70,126,60,90,115,60,142,100,105,65,100,75</p>
<p>Use the R code in chunk1 to help you draw the box plot. Remember to replace the example data with the new dataset.</p>
<div class="tutorial-exercise" data-label="chunk47" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Now use the code in chunk2 to add grid lines to your box plot</p>
<div class="tutorial-exercise" data-label="chunk48" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Now calculate the five number summary using code in chunk3</p>
<div class="tutorial-exercise" data-label="chunk49" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
</div>
<div id="section-worked-example-2-5" class="section level3">
<h3>Worked Example 2</h3>
<p>Below are the percentage exam marks out of 100 for Maths and English.</p>
<p>Maths (%): 98,79,51,54,62,61,56,87,70,60,93,51,52,54,68</p>
<p>English (%): 37,50,58,45,93,47,47,45,38,61,65,46,97,99,54</p>
<p>Produce two box plots side by side</p>
<div class="tutorial-exercise" data-label="chunk59" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>maths <- c(98,79,51,54,62,61,56,87,70,60,93,51,52,54,68)
english <- c(37,50,58,45,93,47,47,45,38,61,65,46,97,99,54)
boxplot(maths, english, xlab="Marks%", names=c("Maths", "English"), horizontal=T)
Grid()
boxplot(maths, english, xlab="Marks%", names=c("Maths", "English"), horizontal=T, add=T)
summary(maths)
summary(english)
IQR(maths)
IQR(english)</code></pre>
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<p>Write down the five number summaries below</p>
<p>What are the inter-quartile ranges</p>
</div>
<div id="section-activity-2-1" class="section level3">
<h3>Activity 2:</h3>
<p>Below are the heights of boys and girls of a similar age.</p>
<p>Boys (cm): 181,157,159,179,186,159,178,162,137,184,140,173,176</p>
<p>Girls (cm): 172,151,176,159,139,179,178,162,134,166,164,172,170</p>
<p>Produce two box plots side by side with a grid and answer the following questions.</p>
<p>Remember to replace the example data with the new information (boys, girls, heights, data)</p>
<div class="tutorial-exercise" data-label="chunk67" data-caption="Code" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<script type="application/json" data-opts-chunk="1">{"fig.width":6.5,"fig.height":4,"fig.retina":2,"fig.align":"default","fig.keep":"high","fig.show":"asis","out.width":624,"warning":true,"error":false,"message":true,"exercise.df_print":"paged","exercise.checker":"NULL"}</script>
</div>
<div id="section-questions" class="section level4">
<h4>Questions</h4>
<p>Are the statements below True or False - and explain why</p>
<ol style="list-style-type: decimal">
<li><p>The girls are taller on average</p></li>
<li><p>Half the girls are over 165 cm tall</p></li>
<li><p>The girls show less spread in height</p></li>
<li><p>The boys show less spread in height</p></li>
<li><p>The shortest person is a girl</p></li>
<li><p>The tallest person is a boy</p></li>
<li><p>Half the boys are over 172 cm tall</p></li>
<li><p>Half the girls are under 165cm tall</p></li>
</ol>
<script type="application/shiny-prerendered" data-context="server-start">
library(learnr)
library(tidyverse)
library(tibble)
library(fontawesome)
library(astsa)
library(grid)
knitr::opts_chunk$set(echo = FALSE)
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::register_http_handlers(session, metadata = NULL)
</script>
<script type="application/shiny-prerendered" data-context="server">
session$onSessionEnded(function() {
learnr:::session_stop_event(session)
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk11-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk11-code-editor`)), session)
output$`tutorial-exercise-chunk11-output` <- renderUI({
`tutorial-exercise-chunk11-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk21-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk21-code-editor`)), session)
output$`tutorial-exercise-chunk21-output` <- renderUI({
`tutorial-exercise-chunk21-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk31-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk31-code-editor`)), session)
output$`tutorial-exercise-chunk31-output` <- renderUI({
`tutorial-exercise-chunk31-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk41-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk41-code-editor`)), session)
output$`tutorial-exercise-chunk41-output` <- renderUI({
`tutorial-exercise-chunk41-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk51-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk51-code-editor`)), session)
output$`tutorial-exercise-chunk51-output` <- renderUI({
`tutorial-exercise-chunk51-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk61-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk61-code-editor`)), session)
output$`tutorial-exercise-chunk61-output` <- renderUI({
`tutorial-exercise-chunk61-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk71-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk71-code-editor`)), session)
output$`tutorial-exercise-chunk71-output` <- renderUI({
`tutorial-exercise-chunk71-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk81-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk81-code-editor`)), session)
output$`tutorial-exercise-chunk81-output` <- renderUI({
`tutorial-exercise-chunk81-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk91-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk91-code-editor`)), session)
output$`tutorial-exercise-chunk91-output` <- renderUI({
`tutorial-exercise-chunk91-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk101-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk101-code-editor`)), session)
output$`tutorial-exercise-chunk101-output` <- renderUI({
`tutorial-exercise-chunk101-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk111-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk111-code-editor`)), session)
output$`tutorial-exercise-chunk111-output` <- renderUI({
`tutorial-exercise-chunk111-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk121-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk121-code-editor`)), session)
output$`tutorial-exercise-chunk121-output` <- renderUI({
`tutorial-exercise-chunk121-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk141-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk141-code-editor`)), session)
output$`tutorial-exercise-chunk141-output` <- renderUI({
`tutorial-exercise-chunk141-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk1-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk1-code-editor`)), session)
output$`tutorial-exercise-chunk1-output` <- renderUI({
`tutorial-exercise-chunk1-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-chunk2-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-chunk2-code-editor`)), session)
output$`tutorial-exercise-chunk2-output` <- renderUI({