forked from KimmoVehkalahti/IODS-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter2.html
1194 lines (1058 loc) · 46.4 KB
/
chapter2.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>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="date" content="2020-11-06" />
<title>Chapter 2: Linear regression</title>
<script src="site_libs/header-attrs-2.5/header-attrs.js"></script>
<script src="site_libs/jquery-1.12.4/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/lumen.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<link href="site_libs/anchor-sections-1.0/anchor-sections.css" rel="stylesheet" />
<script src="site_libs/anchor-sections-1.0/anchor-sections.js"></script>
<script src="site_libs/htmlwidgets-1.5.2/htmlwidgets.js"></script>
<link href="site_libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="site_libs/datatables-binding-0.16/datatables.js"></script>
<link href="site_libs/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="site_libs/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="site_libs/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="site_libs/crosstalk-1.1.0.1/css/crosstalk.css" rel="stylesheet" />
<script src="site_libs/crosstalk-1.1.0.1/js/crosstalk.min.js"></script>
<link href="site_libs/font-awesome-5.1.0/css/all.css" rel="stylesheet" />
<link href="site_libs/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<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>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 54px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 59px;
margin-top: -59px;
}
.section h2 {
padding-top: 59px;
margin-top: -59px;
}
.section h3 {
padding-top: 59px;
margin-top: -59px;
}
.section h4 {
padding-top: 59px;
margin-top: -59px;
}
.section h5 {
padding-top: 59px;
margin-top: -59px;
}
.section h6 {
padding-top: 59px;
margin-top: -59px;
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<!-- 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;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
</head>
<body>
<div class="container-fluid main-container">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">My IODS project page</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="index.html">
<span class="fa fa-home"></span>
Introduction
</a>
</li>
<li>
<a href="chapter2.html">
<span class="fa fa-chart-line"></span>
Linear regression
</a>
</li>
<li>
<a href="chapter3.html">
<span class="fa fa-shipping-fast"></span>
Logistic regression
</a>
</li>
<li>
<a href="chapter4.html">
<span class="fa fa-th"></span>
Clustering
</a>
</li>
<li>
<a href="chapter5.html">
<span class="fa fa-sitemap"></span>
Dim reduction
</a>
</li>
<li>
<a href="chapter6.html">
<span class="fa fa-ruler-combined"></span>
Longitudinal data
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Chapter 2: Linear regression</h1>
<h4 class="date"><em>2020-11-06</em></h4>
</div>
<hr />
<p>In the following exercise we inspect an example data set for linear correlations using R. First we inspect the data set and then we select three most promising variables for analysis with multiple linear regression.</p>
<p>You can focus on specific parts of the data analysis by topic below.</p>
<div id="section" class="section level1 tabset tabset-fade tabset-pills">
<h1 class="tabset tabset-fade tabset-pills"></h1>
<div id="data-description" class="section level2">
<h2>1: Data description</h2>
<div id="description-of-data" class="section level3">
<h3>Description of data</h3>
<p>The data set used this exercise has been previously parsed from <a href="http://www.helsinki.fi/~kvehkala/JYTmooc/JYTOPKYS3-data.txt">this</a> file using an R script available <a href="https://github.com/MB-Finski/IODS-project/data">here</a>.</p>
<p>The data consists of students who underwent a statistics course in 2014 to 2015. Their global attitude toward statistics and learning approaches were recorded with the aid of surveys. Finally the exam points for the course were also recorded for each student. A more exhaustive metadata is available <a href="https://www.mv.helsinki.fi/home/kvehkala/JYTmooc/JYTOPKYS3-meta.txt">here</a>.</p>
<p>For an explanation of the individual variables, please, refer to the following:</p>
<table>
<colgroup>
<col width="18%" />
<col width="81%" />
</colgroup>
<thead>
<tr class="header">
<th>Variable name</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><em>gender</em></td>
<td>Gender of the student encoded as “M” or “F”</td>
</tr>
<tr class="even">
<td><em>points</em></td>
<td>Points from the course exam</td>
</tr>
<tr class="odd">
<td><em>attitude</em></td>
<td>Global attitude towards statistics on a scale of 1-5 (higher = better)</td>
</tr>
<tr class="even">
<td><em>age</em></td>
<td>Age of the student</td>
</tr>
<tr class="odd">
<td><em>deep</em></td>
<td>Deep learning approach on a scale of 1-5 (higher = more deep learning approach)</td>
</tr>
<tr class="even">
<td><em>stra</em></td>
<td>Strategic learning approach on a scale of 1-5 (higher = more strategic learning approach)</td>
</tr>
<tr class="odd">
<td><em>surf</em></td>
<td>Superficial learning approach on a scale of 1-5 (higher = more superficial learning approach)</td>
</tr>
</tbody>
</table>
<hr />
</div>
<div id="exploring-the-data-table-structure" class="section level3">
<h3>Exploring the data table structure</h3>
<p>Let’s explore the data set using the str() function:</p>
<pre class="r"><code>#Read the table from the source file
analysisDataset = read.table("https://raw.githubusercontent.com/MB-Finski/IODS-project/master/data/learning2014.txt")
#Print out the basic structure and dimensions of the dataset
#Please note, that dim() is redundant here as str() already prints out the table dimensions
str(analysisDataset)</code></pre>
<pre><code>## 'data.frame': 166 obs. of 7 variables:
## $ gender : chr "F" "M" "F" "M" ...
## $ points : int 25 12 24 10 22 21 21 31 24 26 ...
## $ attitude: num 3.7 3.1 2.5 3.5 3.7 3.8 3.5 2.9 3.8 2.1 ...
## $ age : int 53 55 49 53 49 38 50 37 37 42 ...
## $ deep : num 3.58 2.92 3.5 3.5 3.67 ...
## $ stra : num 3.38 2.75 3.62 3.12 3.62 ...
## $ surf : num 2.58 3.17 2.25 2.25 2.83 ...</code></pre>
<p>As you can see the data consists of 166 observations with 7 variables.</p>
<hr />
</div>
<div id="interactive-data-table" class="section level3">
<h3>Interactive data table</h3>
<p>Below you can explore the whole data set interactively. The code is left visible for the purposes of this course, only.</p>
<pre class="r"><code>#Draw an interactive data table
library(DT)
datatable(analysisDataset,options = list(columnDefs = list(list(
targets = 1:7,
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.toString().length > 5 ?",
"'<span title=\"' + data.toString() + '\">' + data.toString().substr(0, 5) + '...</span>' : data.toString();",
"}")
))),callback = JS('table.page(0).draw(false);'))</code></pre>
<div id="htmlwidget-fd2ebfae374ee42a79c1" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-fd2ebfae374ee42a79c1">{"x":{"filter":"none","data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","17","18","19","20","21","22","23","24","25","26","27","28","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","70","71","72","73","74","75","77","78","79","80","81","82","83","84","85","86","87","88","89","91","92","93","95","96","97","98","99","100","101","103","105","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125","128","129","130","131","132","133","134","136","137","138","139","140","141","142","143","146","147","148","149","150","151","152","153","154","155","156","157","158","159","160","161","162","163","164","165","166","168","169","170","172","173","175","176","177","178","179","180","181","182","183"],["F","M","F","M","M","F","M","F","M","F","M","F","F","F","M","F","F","F","M","F","M","M","F","F","F","F","M","F","F","M","M","F","F","F","M","F","M","M","M","M","F","F","M","F","F","F","M","F","F","F","M","M","M","F","F","F","F","F","M","M","F","F","F","F","F","M","F","F","F","F","F","M","M","M","F","F","M","M","M","M","F","F","M","M","M","F","F","M","F","F","F","M","F","F","F","M","M","M","F","M","F","F","M","F","F","F","F","F","F","F","F","F","F","M","F","M","F","F","M","F","F","F","M","M","F","F","F","F","F","F","F","M","F","F","M","F","F","F","F","F","F","F","M","F","F","F","F","M","F","M","F","F","F","F","M","F","F","F","F","F","F","F","M","F","F","M"],[25,12,24,10,22,21,21,31,24,26,31,31,23,25,21,31,20,22,9,24,28,30,24,9,26,32,32,33,29,30,19,23,19,12,10,11,20,26,31,20,23,12,24,17,29,23,28,31,23,25,18,19,22,25,21,9,28,25,29,33,33,25,18,22,17,25,28,22,26,11,29,22,21,28,33,16,31,22,31,23,26,12,26,31,19,30,12,17,18,19,21,24,28,17,18,17,23,26,28,31,27,25,23,21,27,28,23,21,25,11,19,24,28,21,24,24,20,19,30,22,16,16,19,30,23,19,18,28,21,19,27,24,21,20,28,12,21,28,31,18,25,19,21,16,7,21,17,22,18,25,24,23,23,26,12,32,22,20,21,23,20,28,31,18,30,19],[3.7,3.1,2.5,3.5,3.7,3.8,3.5,2.9,3.8,2.1,3.9,3.8,2.4,3,2.6,4.1,2.6,2.6,1.7,2.7,3.9,3.4,2.7,2.3,3.7,4.4,4.1,3.7,2.5,3,3.4,3.2,2,2.4,4.2,1.6,3.1,3.8,3.8,3.3,1.7,2.5,3.2,3.5,3.2,4.2,3.1,3.9,1.9,2.1,2.5,3.2,3.2,2.6,2.3,3.8,2.8,3.3,4.8,4,4,4.7,2.3,3.1,2.7,4.1,3.4,2.5,2.1,1.4,1.9,3.7,3.2,2.8,4.1,2.5,2.8,3.8,3.1,3.5,3.6,2.6,4.4,4.5,3.2,3.9,2.5,3.3,3.3,3,2.9,3.3,3.3,3.5,3.6,3.7,4.2,3.2,5,4.7,3.6,3.6,2.9,3.5,4,3.5,3.2,2.6,2,2.7,3.2,3.3,3.9,3.3,3,3.7,2.5,2.9,3.9,3.6,2.9,2.1,3.1,4,3.1,2.3,2.8,3.7,2.6,2.4,3,2.8,2.9,2.4,3.1,1.9,2,3.8,3.4,3.7,2.9,2.3,4.1,2.7,3.5,3.4,3.2,3.3,3.3,3.5,3.2,3.1,2.8,1.7,1.9,3.5,2.4,2.1,2.9,1.9,2,4.2,4.1,3.7,3.6,1.8],[53,55,49,53,49,38,50,37,37,42,37,34,34,34,35,33,32,44,29,30,27,29,31,37,26,26,30,33,33,28,26,27,25,31,20,39,38,24,26,25,30,25,30,48,24,40,25,23,25,23,27,25,23,23,23,45,22,23,21,21,21,21,26,25,26,21,23,22,22,22,23,22,23,24,22,23,22,20,22,21,22,23,21,22,29,29,21,28,21,30,21,23,21,21,20,22,21,21,20,22,20,20,24,20,19,21,21,22,25,21,22,25,20,24,20,21,20,20,31,20,22,22,21,22,21,21,21,21,20,21,25,21,24,20,21,20,20,18,21,19,21,20,21,20,21,20,18,22,22,24,19,20,20,17,19,20,20,20,20,19,19,22,35,18,19,21],[3.58333333333333,2.91666666666667,3.5,3.5,3.66666666666667,4.75,3.83333333333333,3.25,4.33333333333333,4,3.58333333333333,3.83333333333333,4.25,3.33333333333333,4.16666666666667,3.66666666666667,4.08333333333333,3.5,4.08333333333333,4,3.91666666666667,4,4,3.66666666666667,3.66666666666667,4.41666666666667,3.91666666666667,3.75,3.25,3.58333333333333,4.91666666666667,3.58333333333333,2.91666666666667,3.66666666666667,4.5,4.08333333333333,3.83333333333333,3.25,2.33333333333333,3.33333333333333,4.08333333333333,2.91666666666667,3.33333333333333,3.83333333333333,3.66666666666667,4.66666666666667,3.75,3.41666666666667,4.16666666666667,2.91666666666667,4.16666666666667,3.58333333333333,2.83333333333333,4,2.91666666666667,3,4.08333333333333,2.91666666666667,3.5,4.33333333333333,4.25,3.41666666666667,3.08333333333333,4.58333333333333,3.41666666666667,3.41666666666667,3.41666666666667,3.58333333333333,1.58333333333333,3.33333333333333,4.33333333333333,4.41666666666667,4.83333333333333,3.08333333333333,3,4.08333333333333,4.08333333333333,3.75,3.08333333333333,4.75,4.25,4.16666666666667,4.41666666666667,3.83333333333333,3.33333333333333,3.16666666666667,3.16666666666667,3.83333333333333,4.25,3.83333333333333,3.66666666666667,3.83333333333333,3.83333333333333,3.83333333333333,3.66666666666667,4.33333333333333,3.75,4.16666666666667,4,4,4.58333333333333,3.66666666666667,3.66666666666667,3.83333333333333,2.58333333333333,3.5,3.08333333333333,4.25,3.16666666666667,3.08333333333333,4.16666666666667,2.25,3.33333333333333,3.08333333333333,2.75,3.25,4,3.58333333333333,4.08333333333333,4.25,3.41666666666667,3.08333333333333,3.5,3.66666666666667,4.25,4.25,3.83333333333333,4.41666666666667,3.5,3.58333333333333,3.66666666666667,2.08333333333333,4.25,3.58333333333333,4,3.33333333333333,3.5,3.16666666666667,3.58333333333333,3.41666666666667,4.25,3.25,4.41666666666667,3.25,3.91666666666667,3.58333333333333,4.5,3.58333333333333,3.66666666666667,2.58333333333333,4.16666666666667,3.25,4.33333333333333,3.91666666666667,2.66666666666667,3.08333333333333,3.75,4.16666666666667,4.16666666666667,3.25,4.08333333333333,2.91666666666667,3.83333333333333,3.16666666666667,3.41666666666667,4.08333333333333],[3.375,2.75,3.625,3.125,3.625,3.625,2.25,4,4.25,3.5,3.625,4.75,3.625,3.5,1.75,3.875,1.375,3.25,3,3.75,2.625,2.375,3.625,2.75,1.75,3.25,4,3.625,2.875,3,1.625,3.25,3.5,3,3.25,1.875,4.375,3.625,2.5,1.25,4,3,2.5,4.875,5,4.375,3.25,4,3.125,2.5,3.125,3.25,2.125,2.75,2.375,3.125,4,4,2.25,3.25,3.625,3.625,2.5,1.875,2,1.875,4,2.875,3.875,2.5,2.75,4.5,3.375,2.625,4.125,2.625,2.25,2.75,3,1.625,1.875,3.375,3.75,2.125,2.375,2.75,3.125,3.5,2.625,3.375,2.25,3,4,3.5,2.625,2.5,3.75,3.625,4.125,4.375,2.625,4,2.75,2.75,1.375,2.25,3.625,3.75,4,3.125,3.25,2.125,2.875,1.5,2.5,3.25,3.625,3.875,3.875,2.375,3,3.375,2.75,4.5,2.625,2.75,3.25,4.125,3.375,2.75,4.125,3.25,2.875,2.875,2.375,3.875,2.125,4,3.25,2.625,2.75,4,3,3.375,3.875,3.25,3.375,4.125,3.5,2,3.625,3.375,2.125,4.625,2.5,2.875,2.75,4,2.375,3.875,3.375,1.75,3,2.625,2.625,3.375],[2.58333333333333,3.16666666666667,2.25,2.25,2.83333333333333,2.41666666666667,1.91666666666667,2.83333333333333,2.16666666666667,3,2.66666666666667,2.41666666666667,2.25,2.75,2.33333333333333,2.33333333333333,2.91666666666667,2.5,3.75,2.75,2.33333333333333,2.41666666666667,3,2.41666666666667,2.83333333333333,3.16666666666667,3,2,3.5,3.75,2.5,2.08333333333333,2.41666666666667,2.58333333333333,1.58333333333333,2.83333333333333,1.83333333333333,2.41666666666667,3.25,3.41666666666667,3.41666666666667,3.16666666666667,3.5,2.66666666666667,2.41666666666667,3.58333333333333,2.08333333333333,3.75,2.91666666666667,2.91666666666667,2.41666666666667,3,3.41666666666667,2.91666666666667,3.25,3.25,2.33333333333333,3.25,2.5,1.75,2.25,2.08333333333333,2.83333333333333,2.83333333333333,2.41666666666667,2.25,2.83333333333333,2.25,1.83333333333333,2.91666666666667,2.91666666666667,2.08333333333333,2.33333333333333,2.41666666666667,2.75,3.25,1.75,2.58333333333333,3.33333333333333,2.83333333333333,2.5,2.41666666666667,2.41666666666667,2.58333333333333,3,2,3.41666666666667,2.83333333333333,2.25,2.75,3.91666666666667,2.33333333333333,2.75,2.75,2.91666666666667,2.08333333333333,3.66666666666667,2.83333333333333,3.41666666666667,1.58333333333333,2.91666666666667,3,2.91666666666667,2.66666666666667,3,2.75,3.08333333333333,2.5,2.33333333333333,3,3,4,3.25,3.5,3.5,3.83333333333333,2.91666666666667,2.16666666666667,1.66666666666667,2.08333333333333,2.83333333333333,3.41666666666667,3.33333333333333,2.58333333333333,2.83333333333333,3.33333333333333,3,2.58333333333333,2.41666666666667,3.58333333333333,2.08333333333333,4.33333333333333,2.66666666666667,3,2.66666666666667,2.16666666666667,2.66666666666667,2.25,2.66666666666667,3.33333333333333,3.5,2.75,2,2.83333333333333,3.5,2.5,3.16666666666667,3.08333333333333,2.91666666666667,3.16666666666667,2.5,3.83333333333333,2.25,3.41666666666667,3.75,3,2.58333333333333,3.33333333333333,2.83333333333333,3,2.83333333333333,3.16666666666667,2.75,3.41666666666667,3,2.66666666666667]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>gender<\/th>\n <th>points<\/th>\n <th>attitude<\/th>\n <th>age<\/th>\n <th>deep<\/th>\n <th>stra<\/th>\n <th>surf<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"columnDefs":[{"targets":[1,2,3,4,5,6,7],"render":"function(data, type, row, meta) {\nreturn type === 'display' && data.toString().length > 5 ?\n'<span title=\"' + data.toString() + '\">' + data.toString().substr(0, 5) + '...<\/span>' : data.toString();\n}"},{"className":"dt-right","targets":[2,3,4,5,6,7]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\ntable.page(0).draw(false);\n}"},"evals":["options.columnDefs.0.render","callback"],"jsHooks":[]}</script>
</div>
</div>
<div id="overview-of-data" class="section level2">
<h2>2: Overview of data</h2>
<p>Now we wish to perform exploratory (visual) analysis on the data to determine which factors might predict success in the exam among students.</p>
<p>Below you can see a summary table of the data:</p>
<hr />
<pre class="r"><code>library(gtsummary)
#Print a summary table of the data with gender as the contrast. Also add an "overall" column
tbl_summary(analysisDataset,by = gender) %>% add_overall() </code></pre>
<style>html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
}
#ydubhduiik .gt_table {
display: table;
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
color: #333333;
font-size: 16px;
font-weight: normal;
font-style: normal;
background-color: #FFFFFF;
width: auto;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #A8A8A8;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #A8A8A8;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
}
#ydubhduiik .gt_heading {
background-color: #FFFFFF;
text-align: center;
border-bottom-color: #FFFFFF;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#ydubhduiik .gt_title {
color: #333333;
font-size: 125%;
font-weight: initial;
padding-top: 4px;
padding-bottom: 4px;
border-bottom-color: #FFFFFF;
border-bottom-width: 0;
}
#ydubhduiik .gt_subtitle {
color: #333333;
font-size: 85%;
font-weight: initial;
padding-top: 0;
padding-bottom: 4px;
border-top-color: #FFFFFF;
border-top-width: 0;
}
#ydubhduiik .gt_bottom_border {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#ydubhduiik .gt_col_headings {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#ydubhduiik .gt_col_heading {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 6px;
padding-left: 5px;
padding-right: 5px;
overflow-x: hidden;
}
#ydubhduiik .gt_column_spanner_outer {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
padding-top: 0;
padding-bottom: 0;
padding-left: 4px;
padding-right: 4px;
}
#ydubhduiik .gt_column_spanner_outer:first-child {
padding-left: 0;
}
#ydubhduiik .gt_column_spanner_outer:last-child {
padding-right: 0;
}
#ydubhduiik .gt_column_spanner {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 6px;
overflow-x: hidden;
display: inline-block;
width: 100%;
}
#ydubhduiik .gt_group_heading {
padding: 8px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
}
#ydubhduiik .gt_empty_group_heading {
padding: 0.5px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: middle;
}
#ydubhduiik .gt_from_md > :first-child {
margin-top: 0;
}
#ydubhduiik .gt_from_md > :last-child {
margin-bottom: 0;
}
#ydubhduiik .gt_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
margin: 10px;
border-top-style: solid;
border-top-width: 1px;
border-top-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
overflow-x: hidden;
}
#ydubhduiik .gt_stub {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #D3D3D3;
padding-left: 12px;
}
#ydubhduiik .gt_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#ydubhduiik .gt_first_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
}
#ydubhduiik .gt_grand_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#ydubhduiik .gt_first_grand_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-top-style: double;
border-top-width: 6px;
border-top-color: #D3D3D3;
}
#ydubhduiik .gt_striped {
background-color: rgba(128, 128, 128, 0.05);
}
#ydubhduiik .gt_table_body {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#ydubhduiik .gt_footnotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#ydubhduiik .gt_footnote {
margin: 0px;
font-size: 90%;
padding: 4px;
}
#ydubhduiik .gt_sourcenotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#ydubhduiik .gt_sourcenote {
font-size: 90%;
padding: 4px;
}
#ydubhduiik .gt_left {
text-align: left;
}
#ydubhduiik .gt_center {
text-align: center;
}
#ydubhduiik .gt_right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#ydubhduiik .gt_font_normal {
font-weight: normal;
}
#ydubhduiik .gt_font_bold {
font-weight: bold;
}
#ydubhduiik .gt_font_italic {
font-style: italic;
}
#ydubhduiik .gt_super {
font-size: 65%;
}
#ydubhduiik .gt_footnote_marks {
font-style: italic;
font-size: 65%;
}
</style>
<div id="ydubhduiik" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;"><table class="gt_table">
<thead class="gt_col_headings">
<tr>
<th class="gt_col_heading gt_columns_bottom_border gt_left" rowspan="1" colspan="1"><strong>Characteristic</strong></th>
<th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1"><strong>Overall</strong>, N = 166<sup class="gt_footnote_marks">1</sup></th>
<th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1"><strong>F</strong>, N = 110<sup class="gt_footnote_marks">1</sup></th>
<th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1"><strong>M</strong>, N = 56<sup class="gt_footnote_marks">1</sup></th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_left">points</td>
<td class="gt_row gt_center">23 (19, 28)</td>
<td class="gt_row gt_center">23 (19, 26)</td>
<td class="gt_row gt_center">24 (20, 28)</td>
</tr>
<tr>
<td class="gt_row gt_left">attitude</td>
<td class="gt_row gt_center">3.20 (2.60, 3.70)</td>
<td class="gt_row gt_center">2.95 (2.50, 3.58)</td>
<td class="gt_row gt_center">3.40 (3.10, 3.90)</td>
</tr>
<tr>
<td class="gt_row gt_left">age</td>
<td class="gt_row gt_center">22 (21, 27)</td>
<td class="gt_row gt_center">22 (20, 26)</td>
<td class="gt_row gt_center">24 (21, 29)</td>
</tr>
<tr>
<td class="gt_row gt_left">deep</td>
<td class="gt_row gt_center">3.67 (3.33, 4.08)</td>
<td class="gt_row gt_center">3.67 (3.27, 4.08)</td>
<td class="gt_row gt_center">3.79 (3.40, 4.08)</td>
</tr>
<tr>
<td class="gt_row gt_left">stra</td>
<td class="gt_row gt_center">3.19 (2.62, 3.62)</td>
<td class="gt_row gt_center">3.25 (2.66, 3.75)</td>
<td class="gt_row gt_center">3.00 (2.38, 3.53)</td>
</tr>
<tr>
<td class="gt_row gt_left">surf</td>
<td class="gt_row gt_center">2.83 (2.42, 3.17)</td>
<td class="gt_row gt_center">2.83 (2.50, 3.15)</td>
<td class="gt_row gt_center">2.62 (2.31, 3.17)</td>
</tr>
</tbody>
<tfoot>
<tr class="gt_footnotes">
<td colspan="4">
<p class="gt_footnote">
<sup class="gt_footnote_marks">
<em>1</em>
</sup>
Statistics presented: Median (IQR)
<br />
</p>
</td>
</tr>
</tfoot>
</table></div>
<hr />
<div id="data-table-interpretation" class="section level3">
<h3>Data table interpretation</h3>
<p>From the summary table we can see that there are potential differences in attitude between the sexes as well as the mean age. However, the median points for each gender are nearly identical. As far as learning strategies are considered, females may have a slight emphasis on strategic learning. There are considerably less males enrolled in the study.</p>
<hr />
</div>
<div id="visual-inspection-of-data" class="section level3">
<h3>Visual inspection of data</h3>
<p>For the visual inspection of data, instead of printing out a rather complex scatter plot matrix including all variables at once, I chose to have separate graphs for each variable.</p>
<p>Below you can see a convenience function that I wrote for creating the individual graphs.</p>
<pre class="r"><code>library(ggplot2)
library(ggExtra)
library(ggpubr)
#A convenience function for creating informative scatter plots.
createScatterPlot <- function(predictor,displayName){
#Use custom color scheme for the graphs.
plotColors <- c("F" = "red", "M" = "blue", "Combined" = "black")
#Create the plot with gender as contrast and place the legend at the bottom to save horizontal space.
scatterPlot <- ggplot(analysisDataset, aes(x = predictor, y = points,col = gender, shape=gender,colour=plotColors))+theme(legend.position="bottom")
#Add scatterplot points and prevent point stacking with jitter. Also suppress the separate legend for the gender specific point shapes.
scatterPlot <- scatterPlot + geom_point(position = position_jitter(width = 0.5, height = 0.5))+guides(shape=FALSE)
#Draw the regression lines for both groups (male and female) and print the respective Pearson correlation coefficients
scatterPlot <- scatterPlot + geom_smooth(method="lm", se=FALSE)+stat_cor(method = "pearson", p.accuracy = 0.001, r.accuracy = 0.01, position = position_nudge(x=0,y=4.4))
#Change the aesthetics mappings a little bit to print a regression line for data in both groups
scatterPlot <- scatterPlot + geom_smooth(mapping=aes(predictor,points,colour = "Combined"),method = "lm", se=FALSE, data = analysisDataset,inherit.aes =FALSE)
#Print the Pearson correlation coefficient for both groups. Also adjust the text position so that it doesn't overlap with the previously printed text.
scatterPlot <- scatterPlot + stat_cor(mapping=aes(predictor,points,colour = "Combined"),method = "pearson", p.accuracy = 0.001, r.accuracy = 0.01,inherit.aes = FALSE,position = position_nudge(x=0,y=2))
#Print the x- and y-axis labels and suppress the superfluous legend label
scatterPlot <- scatterPlot + labs(x = displayName,y = "Exam points",colour = "")
#Apply our custom color scheme and readable data labels
scatterPlot <- scatterPlot + scale_color_manual(values =plotColors, labels=c("Combined","Female", "Male"))
#Apply a title for the graph
scatterPlot <- scatterPlot + ggtitle(paste(displayName, "versus exam points", sep = " "))
#Add marginal boxplots for visualizing outliers, distribution, and group differences
scatterPlot <- ggMarginal(p=scatterPlot,type="boxplot",size = 6,groupColour = TRUE, groupFill = TRUE)
#Print the plot.
scatterPlot
}</code></pre>
<hr />
<p>Here you can inspect each graph under its corresponding tab.</p>
<hr />
</div>
<div id="section-1" class="section level3 tabset tabset-fade">
<h3 class="tabset tabset-fade"></h3>
<div id="attitude" class="section level4">
<h4><strong>Attitude</strong></h4>
<pre class="r"><code>#Draw the plot using the previously created convenience function
createScatterPlot(analysisDataset$attitude, displayName="Attitude")</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-6-1.png" width="100%" /></p>
<hr />
<div id="interpretation" class="section level5">
<h5>Interpretation</h5>
<p>Based on this graph, there seems to be a considerable positive correlation between attitude and exam points. Seemingly there may also be minor differences in the distribution of attitude between genders. This should be taken into account if/when any difference is observed between the genders in exam points. Fairly normal distribution for both variables across genders.</p>
</div>
</div>
<div id="age" class="section level4">
<h4><strong>Age</strong></h4>
<pre class="r"><code>createScatterPlot(analysisDataset$age,displayName="Age")</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-7-1.png" width="100%" /></p>
<hr />
<div id="interpretation-1" class="section level5">
<h5>Interpretation</h5>
<p>No significant correlations here. The two outliers in the male group cause a trending result which is sure to vanish by excluding these outliers. The distribution is reminiscent of a chi-squared distribution with zero near 18, which is understandable.</p>
<p>Most parametric methods that assume symmetric normal distributions are actually remarkably robust against this type of distributions so I would be more concerned with the outliers than the assymetry of the distribution.</p>
</div>
</div>
<div id="gender" class="section level4">
<h4><strong>Gender</strong></h4>
<pre class="r"><code>#For a class variable like the gender we want something a little bit different
#Create a box plot with gender vs exam points
boxPlot <- ggplot(analysisDataset, aes(x = gender, y = points, color=gender, fill=gender))+theme(legend.position="none")
boxPlot <- boxPlot + geom_boxplot(outlier.colour="black", outlier.shape=16, outlier.size=2, notch=FALSE)
#Adjust outline color
boxPlot <- boxPlot + scale_color_manual(values=c("black","black"))
#Adjust fill color
boxPlot <- boxPlot + scale_fill_manual(values=c("red","blue"))
#Set proper lables for both axes
boxPlot <- boxPlot + labs(x = "Gender",y = "Exam points", fill = "")
#Set the graph title
boxPlot <- boxPlot + ggtitle("Gender versus exam points")
#Print the plot
boxPlot</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-8-1.png" width="100%" /></p>
<hr />
<div id="interpretation-2" class="section level5">
<h5>Interpretation</h5>
<p>Based on a visual inspection, there’s likely no major differences in exam points based on gender. Fairly symmetrical distributions.</p>
</div>
</div>
<div id="deep-learning" class="section level4">
<h4><strong>Deep learning</strong></h4>
<pre class="r"><code>createScatterPlot(analysisDataset$deep, displayName = "Deep learning")</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-9-1.png" width="100%" /></p>
<hr />
<div id="interpretation-3" class="section level5">
<h5>Interpretation</h5>
<p>No significant correlation here. Normal distributions.</p>
</div>
</div>
<div id="superficial-learning" class="section level4">
<h4><strong>Superficial learning</strong></h4>
<pre class="r"><code>createScatterPlot(analysisDataset$surf,displayName="Superficial learning")</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-10-1.png" width="100%" /></p>
<hr />
<div id="interpretation-4" class="section level5">
<h5>Interpretation</h5>
<p>Overall trending negative correlation. Fairly normal distributions.</p>
</div>
</div>
<div id="strategic-learning" class="section level4">
<h4><strong>Strategic learning</strong></h4>
<pre class="r"><code>createScatterPlot(analysisDataset$stra,displayName="Strategic learning")</code></pre>
<p><img src="chapter2_files/figure-html/unnamed-chunk-11-1.png" width="100%" /></p>
<hr />
<div id="interpretation-5" class="section level5">
<h5>Interpretation</h5>
<p>Overall trending positive correlation. Fairly normal distributions.</p>
</div>
</div>
</div>