-
Notifications
You must be signed in to change notification settings - Fork 0
/
STAT462_Lab3.html
887 lines (791 loc) · 34.8 KB
/
STAT462_Lab3.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Lab 3: Scatterplots</title>
<script src="site_libs/header-attrs-2.11/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/flatly.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>
<style>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;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.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>
<script src="site_libs/kePrint-0.0.1/kePrint.js"></script>
<link href="site_libs/lightable-0.0.1/lightable.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>
<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>
<link rel="stylesheet" href="styles.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
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;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.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: #adb5bd;
}
.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 type="text/javascript">
// 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.tab('show');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
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 -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
.tocify-subheader {
display: inline;
}
.tocify-subheader .tocify-item {
font-size: 0.95em;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-default 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">STAT-462</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="T1_R_Basics.html">Tutorials</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Labs
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="STAT462_22_L1Basics.html">Lab 1:R-Basics</a>
</li>
<li>
<a href="STAT462_Lab2.html">Lab 2: Exploratory Data Analysis (EDA)</a>
</li>
<li>
<a href="STAT462_Lab3.html">Lab 3: Scatterplots</a>
</li>
<li>
<a href="STAT462_Lab4.html">Lab 4: Regression Code showcase</a>
</li>
<li>
<a href="STAT462_Lab5.html">Lab 5: LINE Assumptions</a>
</li>
<li>
<a href="STAT462_Lab6.html">Lab 6: Outliers & Transformations</a>
</li>
<li>
<a href="STAT462_Lab7.html">Lab 7: Multiple Regression</a>
</li>
<li>
<a href="STAT462_Lab8.html">Lab 8: Putting it together</a>
</li>
</ul>
</li>
<li>
<a href="STAT462_LabEXAMPLE.html">LAB EXAMPLE</a>
</li>
<li>
<a href="Worked_questions.html">Worked questions</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Lab 3: Scatterplots</h1>
<h3 class="subtitle"><h5 style="font-style:normal">
STAT-462 - Regression Analysis
</h4></h3>
<h4 class="author"><h5 style="font-style:normal">
Dr Helen Greatrex
</h4></h4>
</div>
<style>
p.comment {
background-color: #DBDBDB;
padding: 10px;
border: 1px solid black;
margin-left: 0px;
border-radius: 5px;
font-style: normal;
}
h1.title {
font-weight: bold;
font-family: Arial;
}
h2.title {
font-family: Arial;
}
</style>
<style type="text/css">
#TOC {
font-size: 12px;
font-family: Arial;
}
</style>
<p><br />
</p>
<div id="learning-objectives" class="section level1">
<h1>Learning objectives</h1>
<p>By the end of this week’s lab, you will be able to:</p>
<ol style="list-style-type: decimal">
<li>Understand YAML code and set up a lab template</li>
<li>Get comfortable de-bugging errors</li>
<li>Conduct some exploratory data analysis</li>
<li>Make better plots and a more professional report</li>
</ol>
<p><br></p>
<p class="comment">
<strong>Assignment 2 is due by midnight Next Wed.</strong> [See here]<a href="https://psu.instructure.com/courses/2174925/assignments/13762818" class="uri">https://psu.instructure.com/courses/2174925/assignments/13762818</a>) I PROVIDE HELP UNTIL THE END OF NEXT WEEK’S LAB (final evening is for your own finishing up).
</p>
<p><br></p>
<div id="i-need-help" class="section level2">
<h2>I need help</h2>
<ol style="list-style-type: decimal">
<li><p>There is a TEAMS discussion for lab help <a href="https://teams.microsoft.com/l/team/19%3aWabo92vghie-p1jKkmYOGJIOPMUExkoPb0JQMb_9dgw1%40thread.tacv2/conversations?groupId=bbc92dcc-56df-48e6-8da3-5cd766908eeb&tenantId=7cf48d45-3ddb-4389-a9c1-c115526eb52e">CLICK HERE</a>. Remember to include a screenshot of the issue and a short description of the problem. Also try googling the error first.</p></li>
<li><p>Every time you re-open R studio check you are using your project file (does it say Lab 3 at the top?).</p></li>
<li><p>EVERY TIME YOU RE-OPEN R-STUDIO YOU NEED TO RE-RUN <strong>ALL</strong> YOUR CODE CHUNKS. The easiest way to do this is to press the “Run All” button (see the Run menu at the top of your script)</p></li>
<li><p><strong>If the labs are causing major problems or your computer hardware is struggling (or you have any other software issue), Talk to Dr Greatrex</strong>. We can fix this and there are other free/cheap options for using R online.</p></li>
</ol>
<p><br></p>
</div>
</div>
<div id="step-1-lab-set-up" class="section level1">
<h1>STEP 1: Lab set up</h1>
<p><br></p>
<div id="a.-get-set-up" class="section level2">
<h2>1a. Get set up</h2>
<p>IF YOU ARE DOING THIS ON YOUR COMPUTER: First, go and look at your STAT-462 folder on your computer. Make sure that everything looks right (e.g. a single sub-folder for each lab containing your project file, your Rmd and your html, along with any datafiles/pics as needed). If so, congrats! If not, chat to Dr G.</p>
<ol style="list-style-type: decimal">
<li>Open R-studio. Go to New Project / New Directory / New Project. Then name your project <strong>Lab3-Project</strong>. Place the location inside your STAT-462 folder. If you are stuck, see <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#21_Projects">Tutorial 2.1</a>.</li>
</ol>
<p><br></p>
<ol start="2" style="list-style-type: decimal">
<li>Set up your template:
<ul>
<li>IF YOU ARE WORKING ON YOUR OWN COMPUTER: Go onto your computer, find your STAT462 folder and make a copy of your lab template .Rmd file. Copy it into your lab 3 folder and rename as Lab 3 & your PSU-e-mail e.g. <em>Lab 3-hlg5155</em>. (you can do this within the R files tab if you wish but probably easier on your computer) <br>>br></li>
<li>IF YOU ARE WORKING ON R-STUDIO CLOUD: In the files tab, there is an upload button. Click that and upload last week’s template that you saved onto your computer. Click the checkbox by it and rename to <em>Lab 3-hlg5155</em> (with your ID). (If you didn’t download a copy of your lab template file, go into your lab 2 project and do so first). <br><br></li>
</ul></li>
<li>Go back to R studio, make sure you are running the Lab 3 project, then go to the files quadrant and click on your lab3 script to open. Update the title etc and make any formatting tweaks you like.</li>
</ol>
<p><br><br></p>
</div>
<div id="c.-load-libraries-and-check-it-all-knits" class="section level2">
<h2>1c. Load libraries and check it all knits</h2>
<p>In the library section of your lab report, add a new code chunk and use this code to load the following libraries. If some don’t exist on your computer or on the cloud, use [Tutorial 2.3] (<a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#23_Adding_a_new_package" class="uri">https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#23_Adding_a_new_package</a>) to install/download them first. To make sure they loaded OK, run the code chunk TWICE. The second time any welcome text will disappear unless there are errors.</p>
<pre class="r"><code>library(tidyverse)
library(dplyr)
library(ggpubr)
library(skimr)
library(ggplot2)
library(plotly)
library(ISLR)
library(equatiomatic)
library(olsrr)
library(Stat2Data)
library(readxl)
library(tmap)</code></pre>
<p>Finally, press knit to check the html works and it looks like this (with your theme)</p>
<p><img src="Figures/Lab3_fig1.png" width="1659" style="display: block; margin: auto;" /></p>
<p><br> <br></p>
</div>
</div>
<div id="step-2-code-showcase" class="section level1">
<h1>STEP 2: Code showcase</h1>
<p><strong>Note, you might want to make a second .Rmd file to practice the tutorials, so you can save your practice but only write up what is needed in your report</strong></p>
<p><br></p>
<div id="a.-markdown---inline-code-and-equations" class="section level2">
<h2>2a. Markdown - inline code and equations</h2>
<p>The best thing about R-Markdown is that you can set up reports to automatically update even in the text. For example imagine underneath a code chunk you want to write that the mean of the data is 23. Instead of typing the number 23, we can add <em>inline code</em> to automatically create it</p>
<p><em>Step A:</em> Work through <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#48_Inline_code">Tutorial 4.8, Inline code</a></p>
<p>Use the tutorial to do the following.</p>
<p><em>Question 1:</em> In the markdown/code showcase section of your lab report, create a hidden code chunk where you find the answer to pi to the power 4, to 4 decimal places. Write a sentence inside your report containing inline code that shares the answer.</p>
<p><br></p>
<p><em>Question 2:</em> Conduct a t-test to find out whether the true mean of this data is significantly less than 13. Hide the test itself and simply write out the concluding summary,using inline code and hidden code chunks.</p>
<pre class="r"><code>testdata <- c(4,6,2,7,8,34,4,65,6,2,3,1,45,5)</code></pre>
<p><em>Step B:</em> Equations</p>
<p>It’s often good to put professional looking equations into your report. We can do this using the $ symbol and with some internet support.</p>
<p>Rather than read my tutorial, see this one: <a href="https://rmd4sci.njtierney.com/math" class="uri">https://rmd4sci.njtierney.com/math</a></p>
<p>I tend to use one of the online LateX maths editors to find the exact commands to make equations and then copy/paste the commands into my markdown For example:</p>
<ul>
<li><a href="https://latexeditor.lagrida.com/" class="uri">https://latexeditor.lagrida.com/</a></li>
<li><a href="https://www.tutorialspoint.com/latex_equation_editor.htm" class="uri">https://www.tutorialspoint.com/latex_equation_editor.htm</a></li>
</ul>
<p><em>Question 3:</em> Explain what the central limit theorem is and why we might use a T distribution instead of a Normal one. Use the tutorials above to make sure your equations are formatted correctly.</p>
<p><br> <br> <br></p>
</div>
</div>
<div id="step-3-data-analysis" class="section level1">
<h1>STEP 3: Data Analysis</h1>
<p>NEW TUTORIALS HAVE APPEARED: SCATTERPLOTS: <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#78_Scatterplots">Tutorial 7.8</a>, CORRELATION PLOTS/CALCULATIONS <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#63_Correlation">Tutorial 6.3</a>, REGRESSION <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#9_Regression_models">Tutorial 9</a></p>
<p>First - ARE YOU USING THE TEMPLATE FROM LAB 2??? IF NOT, YOU WILL LOSE MANY MARKS. GO BACK AND DO STEP 1 OF THIS LAB (and step 1 of lab 2 if you missed it..)</p>
<p>OK What are we doing here? The aim of EVERY LAB, is to get comfortable writing up analyses of a complex dataset for a specific person or user. The modelling might be the same and we follow the same steps, but the context and topic will mean you will need to think hard about what is important in each case.</p>
<p>The overall structure of the data anlysis for <em>every lab</em> will be the same, but each week we will add on a little more. Specifically</p>
<ol style="list-style-type: decimal">
<li>Exploring the data IN THE CONTEXT OF THE STUDY (ALL the points/questions in the first part of the teaching notes : <a href="https://psu.instructure.com/courses/2174925/files/132549205" class="uri">https://psu.instructure.com/courses/2174925/files/132549205</a>). The aim of this is to fully parameterise the study, talking about your response, predictors, sample vs census, object of analysis etc..</li>
<li>Exploratory data analysis of your RESPONSE VARIABLE, because understanding/predicting the response is literally the only aim of a regression analysis.<br />
</li>
<li>A series of models. A model could be very simple (nothing ’ explains’)</li>
</ol>
<div id="our-study" class="section level2">
<h2>Our study</h2>
<p>Next month, your friend is moving to Sindian Dist., in New Taipei City, Taiwan. They want to buy a house and have asked you to figure out what most impacts house price. (this course is normally less house price/penguin heavy! Next week….)</p>
<ol style="list-style-type: decimal">
<li>Download the “Lab03_house.xlsx” dataset from the Lab page on canvas and put it into your Lab 3 folder. Use the read_excel() command to read it in and save it to a variable called house:</li>
</ol>
<pre class="r"><code># This only works if you are running your project
# If it can't find the file, use file.choose() to locate it, as described in homework 3
# Then add in the full location rather than just the file name.
house <- read_excel("Lab03_house.xlsx")</code></pre>
<ol start="2" style="list-style-type: decimal">
<li><p>Explore the dataset (using summaries etc (lab 1 & 2), and by reading more about the data here: <a href="https://archive.ics.uci.edu/ml/datasets/Real+estate+valuation+data+set" class="uri">https://archive.ics.uci.edu/ml/datasets/Real+estate+valuation+data+set</a>). THE AIM OF THIS STUDY IS TO HELP YOUR FRIEND. <br><br> So, describe the dataset to your friend. Use all the hints/questions in the teaching notes: <a href="https://psu.instructure.com/courses/2174925/files/132549205" class="uri">https://psu.instructure.com/courses/2174925/files/132549205</a> For example talking about your response, predictors, sample vs census, object of analysis etc… <br> Make sure to summarise if there any limitations using this specific sample in order to address the aim of the study.</p></li>
<li><p>Finish your the initial description by using a paragraph/sentence similar to the one about penguins in the teaching notes just before EDA.</p></li>
<li><p>Adjust/fill in the template to end of Exploratory Data Analysis (EDA), <strong>focusing only on your response variable for now</strong> (because the aim of the study is to understand the response variable..). Here are the teaching notes</p></li>
</ol>
<p>Our first model will be univariate - we think nothing impacts house prices, so all we have is the histogram. Assume that a Normal distribution can fit the data, with mean(sample_mean) and sd(sample_sd). Adjust the title of your model section to read</p>
<div id="model-1-univariate-model-normal-distribution" class="section level3">
<h3>Model 1: Univariate model: Normal Distribution</h3>
<ol start="4" style="list-style-type: decimal">
<li><p>In model fitting, write a sentence to explain the above, but instead of writing out “mean(sample_mean) and sd(sample_sd)”, use your new equation knowledge and inline text to write out the model more formally. We will talk about this in class. e.g. We will assume a Normal distribution with $~N(_y , _y) $ where <span class="math inline">\(\mu_y = ..\)</span> etc.</p></li>
<li><p>Under check validity, use a Shapiro-Wilk test, a QQplot and a histogram to assess if you think the house price data really is normally distributed. Note, if you created them above, you can refer back to them in the text. Make sure to fully explain any contradictory results to your friend. Finish by summarising whether you believe that your model is valid given the data and whether it is suitable to use this for either confidence intervals or prediction intervals.</p></li>
<li><p>Ignore test skill for now (we will need it later in the course)</p></li>
</ol>
<p>Your friend is impatient and wants you to use the model straight away</p>
<ol start="7" style="list-style-type: decimal">
<li><p>Under “Assess errors on population parameters:”, calculate using R the 99th confidence interval on the population mean and write up the results in your text in full sentences. E.g. according to the central limit theorem, we can assume.. therefore.. etc.</p></li>
<li><p>In the same section, my friend has been told that the average price is 350,000 New Taiwan Dollar/Ping (note the data is in units x 10000). Given your sample, conduct a hypothesis test to assess how likely it is to see your sample result if that statement is likely to be true, with a critical significance of 80% *.<br></p></li>
</ol>
<p><em>Note, here I say “80%” as in the real world, people often mix and match the way they talk about a critical threshold as either the critical p, or the critical 1-p. This is common outside stats textbooks! So this is adding to the ‘real life messiness’ learning objective..” <br> It can be frustrating because it’s not immediately obvious what to choose as your critical threshold.. But remember that hypothesis tests normally look for an unusual outcome so I normally assume if it’s over 50% then they mean 1-p.. Best practice would be to choose either one, but then write a short sentence or two in the report to your friend explaining what the p value means and asking, “did you really mean 80%? because that would mean….</em></p>
<ol start="9" style="list-style-type: decimal">
<li>In the predict new value, find the 99% prediction interval for a brand new house. Given this is it very unusual to see a new house priced at over 700,000 New Taiwan Dollar/Ping? (note the data is in units x 10000). (Help including R output in the Lecture 9 notes)</li>
</ol>
</div>
</div>
<div id="b.-bivariate-model" class="section level2">
<h2>3B. Bivariate model</h2>
<p>Make a new level 1 section called Bivariate model.</p>
<p>We do know ways to improve our model, as we know things that might impact house prices contained in our data. Specifically, our friend has been told that houses might be more expensive in the North.</p>
<ol start="10" style="list-style-type: decimal">
<li>Scatterplot</li>
</ol>
<p>See: SCATTERPLOTS: <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#78_Scatterplots">Tutorial 7.8</a> and REGRESSION <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#9_Regression_models">Tutorial 9</a></p>
<ul>
<li>Look at the dataset and see which column gives you information about North/South (hint Latitude/longitude, <a href="https://www.geographyrealm.com/latitude-longitude/" class="uri">https://www.geographyrealm.com/latitude-longitude/</a>)</li>
<li>Create a scatterplot to assess this, REMEMBER WHICH IS YOUR RESPONSE!</li>
<li>Describe the scatterplot fully as discussed in Homework 5 (or see here: <a href="https://www.khanacademy.org/math/ap-statistics/bivariate-data-ap/scatterplots-correlation/a/describing-scatterplots-form-direction-strength-outliers?modal=1">KHAN SUMMARY:</a> )</li>
<li>Create a Simple Linear Regression model to assess the issue (Regression tutorial)</li>
<li>Extract the equation using equatiomatrix (see the tutorial) and write it below the plot, explaining what the intercept and slope are.</li>
<li>Plot the abline, line of best fit onto a new scatterplot</li>
</ul>
<ol start="11" style="list-style-type: decimal">
<li>Comment on why this might be misleading as an analysis? To help you answer this question, try running this code to further explore the data on a map.</li>
</ol>
<p>DONT RUN IF TMAP NOT WORKING</p>
<pre class="r"><code># Command from the sf library
# ADD THE library(sf) and library(tmap) TO YOUR LIBRARY CODE CHUNK
# Make a spatial version of the data using the Longitude and Latitude columns
house.spatial <- st_as_sf(house,coords=c("Longitude","Latitude"),crs = 4326)
# make interactive, for static set as "plot"
tmap_mode("view")
# Command from the tmap library
# and plot
tm_basemap("Esri.WorldTopoMap") +
qtm(house.spatial, # data
symbols.col="House.Price", # which column for the symbols
symbols.alpha=0.9, # transparency
symbols.size=.2, # how big
symbols.palette="Spectral", #colors from https://colorbrewer2.org
symbols.style="fisher") # color breaks</code></pre>
<ol start="12" style="list-style-type: decimal">
<li>Beyond this, what other confounding variables might there be? Is there a variable that is more important than latitude in predicting house prices in your dataset? Provide evidence to justify your answer. To help you answer this data and answer this question, some useful code includes:</li>
</ol>
<ul>
<li>[A] corrplot(). A quick look at the correlation coefficient between all the variables. We will discuss it more next week. CORRELATION PLOTS/CALCULATIONS <a href="https://psu-spatial.github.io/stat462-2022/T1_R_Basics.html#63_Correlation">Tutorial 6.3</a>,</li>
</ul>
<pre class="r"><code>library(corrplot)
# ADD THAT LIBRARY TO YOUR LIST!
corrplot(cor(house),method="number",type="lower")</code></pre>
<ul>
<li>[B] If you then want to look at three variables together, you can use an interactive plot e.g you can use this code and change the response, y (currently house price), the predictor x (currently latitude) and the colour (currently house.age).</li>
</ul>
<pre class="r"><code># Create a plot
p <- house %>%
ggplot( aes(Latitude,House.Price, col= House.Age)) +
geom_point() +
theme_classic()+
scale_color_gradient(low="blue", high="red")
# and actually plot it
ggplotly(p)</code></pre>
<p><br> <br></p>
</div>
</div>
<div id="step-4-show-me-something-new" class="section level1">
<h1>STEP 4: Show me something new</h1>
<p>Remember that an A is 94%, so you can ignore this section and still easily get an A. But here is your time to shine. Also, if you are struggling in another part of the lab, you can use this to gain back points.</p>
<p><strong>To get the final 4 marks in the lab, you need to show me something new, e.g. you need to go above and beyond the lab questions in some way.</strong></p>
<ul>
<li>You get 2/4 for doing something new in any way BEYOND THE LAB INSTRUCTIONS/CODE</li>
<li>You get 4/4 for something really impressive or multiple small things.</li>
<li>You must tell us in your R script what you did!</li>
</ul>
<p>Here are some ideas:</p>
<ul>
<li>You found a cool new plot from R graph gallery or flowingdata.com and made it work</li>
<li>You did something neat in Markdown such as embedding a pdf</li>
<li>You found a new package/command that did something relevant</li>
<li>You found something cool on data camp and applied it here</li>
<li>You tweaked your mapping/plotting code to be better</li>
</ul>
<p><br> <br></p>
</div>
<div id="submitting-your-lab" class="section level1">
<h1>Submitting your Lab</h1>
<p>Remember to save your work throughout and to spell check your writing (next to the save button).</p>
<p>Now, press the knit button for the final time.</p>
<p>If you have not made any mistakes in the code then R should create a html file in your lab 2 folder which includes your answers. If you look at your lab 1 folder, you should see this there - complete with a very recent time-stamp.</p>
<p>In that folder, double click on the html file. This will open it in your browser. CHECK THAT THIS IS WHAT YOU WANT TO SUBMIT.</p>
<p>If you are on R studio cloud, see Tutorial 1 for how to download your files</p>
<p>Now go to Canvas and submit BOTH your html and your .Rmd file in Lab 2.</p>
<p><img src="Figures/Lab1_Basics_2022_fig1.png" width="1673" /></p>
<p><br></p>
</div>
<div id="grading-rubricchecklist" class="section level1">
<h1>Grading Rubric/checklist</h1>
<p>See the table below for what this means - 100% is hard to get!</p>
<p><strong>HTML FILE SUBMISSION - 8 marks</strong></p>
<p><strong>RMD CODE SUBMISSION - 8 marks</strong></p>
<p><strong>WRITING/CODE STYLE - 10 MARKS</strong></p>
<p>Your code and document is neat and easy to read. LOOK AT YOUR HTML FILE IN YOUR WEB-BROWSER BEFORE YOU SUBMIT. There is also a spell check next to the save button.</p>
<p>You have written your answers below the relevant code chunk in full sentences in a way that is easy to find and grade. For example, you have written in full sentences, it is clear what your answers are referring to. You have used units and explained your workings.</p>
<p><strong>MARKDOWN SHOWCASE: 10 MARKS</strong></p>
<p>You use full sentences and units, You have great Markdown formatting</p>
<p><strong>R-CODE SHOWCASE: 20 MARKS</strong></p>
<p><strong>UNIVARIATE: 20 MARKS</strong></p>
<p><strong>BIVARIATE: 20 MARKS</strong></p>
<p>You have managed to successfully complete all the code challenges</p>
<p><strong>Above and beyond: 4 MARKS</strong></p>
<p>See above for ideas on grading</p>
<p>[100 marks total]</p>
<p>Overall, here is what your lab should correspond to:</p>
<table class=" lightable-classic-2 table table-striped table-hover table-responsive" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;">
Grade
</th>
<th style="text-align:left;">
% Mark
</th>
<th style="text-align:left;">
Rubric
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
A*
</td>
<td style="text-align:left;">
98-100
</td>
<td style="text-align:left;">
Exceptional. Not only was it near perfect, but the graders learned something. THIS IS HARD TO GET.
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
96+
</td>
<td style="text-align:left;">
You went above and beyond
</td>
</tr>
<tr>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
94+:
</td>
<td style="text-align:left;">
Everything asked for with high quality. Class example
</td>
</tr>
<tr>
<td style="text-align:left;">
A-
</td>
<td style="text-align:left;">
90+
</td>
<td style="text-align:left;">
The odd minor mistake, All code done but not written up in full sentences etc. A little less care
</td>
</tr>
<tr>
<td style="text-align:left;">
B+
</td>
<td style="text-align:left;">
87+
</td>
<td style="text-align:left;">
More minor mistakes. Things like missing units, getting the odd question wrong, no workings shown
</td>
</tr>
<tr>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
84+
</td>
<td style="text-align:left;">
Solid work but the odd larger mistake or missing answer. Completely misinterpreted something, that type of thing
</td>
</tr>
<tr>
<td style="text-align:left;">
B-
</td>
<td style="text-align:left;">
80+
</td>
<td style="text-align:left;">
Starting to miss entire/questions sections, or multiple larger mistakes. Still a solid attempt.
</td>
</tr>
<tr>
<td style="text-align:left;">
C+
</td>
<td style="text-align:left;">
77+
</td>
<td style="text-align:left;">
You made a good effort and did some things well, but there were a lot of problems. (e.g. you wrote up the text well, but messed up the code)
</td>
</tr>
<tr>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
70+
</td>
<td style="text-align:left;">
It’s clear you tried and learned something. Just attending labs will get you this much as we can help you get to this stage
</td>
</tr>
<tr>
<td style="text-align:left;">
D
</td>
<td style="text-align:left;">
60+
</td>
<td style="text-align:left;">
You attempt the lab and submit something. Not clear you put in much effort or you had real issues
</td>
</tr>
<tr>
<td style="text-align:left;">
F
</td>
<td style="text-align:left;">
0+
</td>
<td style="text-align:left;">
Didn’t submit, or incredibly limited attempt.
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3,h4",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = false;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>