forked from sdesabbata/granolarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreproducibility.html
488 lines (437 loc) · 39.3 KB
/
reproducibility.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>6 Reproducibility | Geographic data science reproducible teaching resource in R Practical session materials</title>
<meta name="description" content="Geographic data science reproducible teaching resource in RPractical session materials" />
<meta name="generator" content="bookdown 0.14 and GitBook 2.6.7" />
<meta property="og:title" content="6 Reproducibility | Geographic data science reproducible teaching resource in R Practical session materials" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="6 Reproducibility | Geographic data science reproducible teaching resource in R Practical session materials" />
<meta name="author" content="Stefano De Sabbata" />
<meta name="date" content="2020-01-15" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="data-wrangling-pt-2.html"/>
<link rel="next" href="exploratory-analysis.html"/>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Preface</a><ul>
<li class="chapter" data-level="0.1" data-path="index.html"><a href="index.html#session-info"><i class="fa fa-check"></i><b>0.1</b> Session info</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="introduction-to-r.html"><a href="introduction-to-r.html"><i class="fa fa-check"></i><b>1</b> Introduction to R</a><ul>
<li class="chapter" data-level="1.1" data-path="introduction-to-r.html"><a href="introduction-to-r.html#the-r-programming-language"><i class="fa fa-check"></i><b>1.1</b> The R programming language</a><ul>
<li class="chapter" data-level="1.1.1" data-path="introduction-to-r.html"><a href="introduction-to-r.html#using-rstudio"><i class="fa fa-check"></i><b>1.1.1</b> Using RStudio</a></li>
</ul></li>
<li class="chapter" data-level="1.2" data-path="introduction-to-r.html"><a href="introduction-to-r.html#interpreting-values"><i class="fa fa-check"></i><b>1.2</b> Interpreting values</a></li>
<li class="chapter" data-level="1.3" data-path="introduction-to-r.html"><a href="introduction-to-r.html#variables"><i class="fa fa-check"></i><b>1.3</b> Variables</a></li>
<li class="chapter" data-level="1.4" data-path="introduction-to-r.html"><a href="introduction-to-r.html#basic-types"><i class="fa fa-check"></i><b>1.4</b> Basic types</a><ul>
<li class="chapter" data-level="1.4.1" data-path="introduction-to-r.html"><a href="introduction-to-r.html#numeric"><i class="fa fa-check"></i><b>1.4.1</b> Numeric</a></li>
<li class="chapter" data-level="1.4.2" data-path="introduction-to-r.html"><a href="introduction-to-r.html#logical"><i class="fa fa-check"></i><b>1.4.2</b> Logical</a></li>
<li class="chapter" data-level="1.4.3" data-path="introduction-to-r.html"><a href="introduction-to-r.html#character"><i class="fa fa-check"></i><b>1.4.3</b> Character</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="introduction-to-r.html"><a href="introduction-to-r.html#tidyverse"><i class="fa fa-check"></i><b>1.5</b> Tidyverse</a><ul>
<li class="chapter" data-level="1.5.1" data-path="introduction-to-r.html"><a href="introduction-to-r.html#stringr"><i class="fa fa-check"></i><b>1.5.1</b> stringr</a></li>
<li class="chapter" data-level="1.5.2" data-path="introduction-to-r.html"><a href="introduction-to-r.html#the-pipe-operator"><i class="fa fa-check"></i><b>1.5.2</b> The pipe operator</a></li>
</ul></li>
<li class="chapter" data-level="1.6" data-path="introduction-to-r.html"><a href="introduction-to-r.html#coding-style"><i class="fa fa-check"></i><b>1.6</b> Coding style</a></li>
<li class="chapter" data-level="1.7" data-path="introduction-to-r.html"><a href="introduction-to-r.html#exercise-1.1"><i class="fa fa-check"></i><b>1.7</b> Exercise 1.1</a></li>
<li class="chapter" data-level="1.8" data-path="introduction-to-r.html"><a href="introduction-to-r.html#exercise-1.2"><i class="fa fa-check"></i><b>1.8</b> Exercise 1.2</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="data-types.html"><a href="data-types.html"><i class="fa fa-check"></i><b>2</b> Data types</a><ul>
<li class="chapter" data-level="2.1" data-path="data-types.html"><a href="data-types.html#vectors"><i class="fa fa-check"></i><b>2.1</b> Vectors</a></li>
<li class="chapter" data-level="2.2" data-path="data-types.html"><a href="data-types.html#filtering"><i class="fa fa-check"></i><b>2.2</b> Filtering</a></li>
<li class="chapter" data-level="2.3" data-path="data-types.html"><a href="data-types.html#factors"><i class="fa fa-check"></i><b>2.3</b> Factors</a></li>
<li class="chapter" data-level="2.4" data-path="data-types.html"><a href="data-types.html#exercise-2.1"><i class="fa fa-check"></i><b>2.4</b> Exercise 2.1</a></li>
<li class="chapter" data-level="2.5" data-path="data-types.html"><a href="data-types.html#matrices-and-arrays"><i class="fa fa-check"></i><b>2.5</b> Matrices and arrays</a></li>
<li class="chapter" data-level="2.6" data-path="data-types.html"><a href="data-types.html#exercise-2.2"><i class="fa fa-check"></i><b>2.6</b> Exercise 2.2</a></li>
<li class="chapter" data-level="2.7" data-path="data-types.html"><a href="data-types.html#lists"><i class="fa fa-check"></i><b>2.7</b> Lists</a></li>
<li class="chapter" data-level="2.8" data-path="data-types.html"><a href="data-types.html#data-frames"><i class="fa fa-check"></i><b>2.8</b> Data frames</a></li>
<li class="chapter" data-level="2.9" data-path="data-types.html"><a href="data-types.html#exercise-2.3"><i class="fa fa-check"></i><b>2.9</b> Exercise 2.3</a></li>
<li class="chapter" data-level="2.10" data-path="data-types.html"><a href="data-types.html#solutions"><i class="fa fa-check"></i><b>2.10</b> Solutions</a><ul>
<li class="chapter" data-level="2.10.1" data-path="data-types.html"><a href="data-types.html#exercise-2.1-1"><i class="fa fa-check"></i><b>2.10.1</b> Exercise 2.1</a></li>
<li class="chapter" data-level="2.10.2" data-path="data-types.html"><a href="data-types.html#exercise-2.2-1"><i class="fa fa-check"></i><b>2.10.2</b> Exercise 2.2</a></li>
<li class="chapter" data-level="2.10.3" data-path="data-types.html"><a href="data-types.html#exercise-2.3-1"><i class="fa fa-check"></i><b>2.10.3</b> Exercise 2.3</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="3" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html"><i class="fa fa-check"></i><b>3</b> Control structures and Functions</a><ul>
<li class="chapter" data-level="3.1" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#conditional-structures"><i class="fa fa-check"></i><b>3.1</b> Conditional structures</a></li>
<li class="chapter" data-level="3.2" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#loops"><i class="fa fa-check"></i><b>3.2</b> Loops</a><ul>
<li class="chapter" data-level="3.2.1" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#conditional-loops"><i class="fa fa-check"></i><b>3.2.1</b> Conditional Loops</a></li>
<li class="chapter" data-level="3.2.2" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#deterministic-loops"><i class="fa fa-check"></i><b>3.2.2</b> Deterministic Loops</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#function-definition"><i class="fa fa-check"></i><b>3.3</b> Function definition</a></li>
<li class="chapter" data-level="3.4" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#exercise-6.1"><i class="fa fa-check"></i><b>3.4</b> Exercise 6.1</a></li>
<li class="chapter" data-level="3.5" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#data-checking"><i class="fa fa-check"></i><b>3.5</b> Data Checking</a></li>
<li class="chapter" data-level="3.6" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#exercise-6.2"><i class="fa fa-check"></i><b>3.6</b> Exercise 6.2</a></li>
<li class="chapter" data-level="3.7" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#solutions-1"><i class="fa fa-check"></i><b>3.7</b> Solutions</a><ul>
<li class="chapter" data-level="3.7.1" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#exercise-6.1-1"><i class="fa fa-check"></i><b>3.7.1</b> Exercise 6.1</a></li>
<li class="chapter" data-level="3.7.2" data-path="control-structures-and-functions.html"><a href="control-structures-and-functions.html#exercise-6.2-1"><i class="fa fa-check"></i><b>3.7.2</b> Exercise 6.2</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html"><i class="fa fa-check"></i><b>4</b> Data wrangling Pt. 1</a><ul>
<li class="chapter" data-level="4.1" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#working-with-rstudio"><i class="fa fa-check"></i><b>4.1</b> Working with RStudio</a><ul>
<li class="chapter" data-level="4.1.1" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#r-projects"><i class="fa fa-check"></i><b>4.1.1</b> R Projects</a></li>
<li class="chapter" data-level="4.1.2" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#r-scripts"><i class="fa fa-check"></i><b>4.1.2</b> R Scripts</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#install-libraries"><i class="fa fa-check"></i><b>4.2</b> Install libraries</a></li>
<li class="chapter" data-level="4.3" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#data-manipulation"><i class="fa fa-check"></i><b>4.3</b> Data manipulation</a><ul>
<li class="chapter" data-level="4.3.1" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#summarise"><i class="fa fa-check"></i><b>4.3.1</b> Summarise</a></li>
<li class="chapter" data-level="4.3.2" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#select-and-filter"><i class="fa fa-check"></i><b>4.3.2</b> Select and filter</a></li>
<li class="chapter" data-level="4.3.3" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#mutate"><i class="fa fa-check"></i><b>4.3.3</b> Mutate</a></li>
<li class="chapter" data-level="4.3.4" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#arrange"><i class="fa fa-check"></i><b>4.3.4</b> Arrange</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#data-manipulation-example"><i class="fa fa-check"></i><b>4.4</b> Data manipulation example</a></li>
<li class="chapter" data-level="4.5" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#exercise-3.1"><i class="fa fa-check"></i><b>4.5</b> Exercise 3.1</a></li>
<li class="chapter" data-level="4.6" data-path="data-wrangling-pt-1.html"><a href="data-wrangling-pt-1.html#solutions-2"><i class="fa fa-check"></i><b>4.6</b> Solutions</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html"><i class="fa fa-check"></i><b>5</b> Data wrangling Pt. 2</a><ul>
<li class="chapter" data-level="5.1" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#table-manipulation"><i class="fa fa-check"></i><b>5.1</b> Table manipulation</a><ul>
<li class="chapter" data-level="5.1.1" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#long-and-wide-formats"><i class="fa fa-check"></i><b>5.1.1</b> Long and wide formats</a></li>
<li class="chapter" data-level="5.1.2" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#join"><i class="fa fa-check"></i><b>5.1.2</b> Join</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#read-and-write-data"><i class="fa fa-check"></i><b>5.2</b> Read and write data</a></li>
<li class="chapter" data-level="5.3" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#data-wrangling-example"><i class="fa fa-check"></i><b>5.3</b> Data wrangling example</a><ul>
<li class="chapter" data-level="5.3.1" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#re-shaping"><i class="fa fa-check"></i><b>5.3.1</b> Re-shaping</a></li>
<li class="chapter" data-level="5.3.2" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#join-1"><i class="fa fa-check"></i><b>5.3.2</b> Join</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#exercise-3.1-1"><i class="fa fa-check"></i><b>5.4</b> Exercise 3.1</a></li>
<li class="chapter" data-level="5.5" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#exercise-3.2"><i class="fa fa-check"></i><b>5.5</b> Exercise 3.2</a></li>
<li class="chapter" data-level="5.6" data-path="data-wrangling-pt-2.html"><a href="data-wrangling-pt-2.html#solutions-3"><i class="fa fa-check"></i><b>5.6</b> Solutions</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="reproducibility.html"><a href="reproducibility.html"><i class="fa fa-check"></i><b>6</b> Reproducibility</a><ul>
<li class="chapter" data-level="6.1" data-path="reproducibility.html"><a href="reproducibility.html#markdown"><i class="fa fa-check"></i><b>6.1</b> Markdown</a><ul>
<li class="chapter" data-level="6.1.1" data-path="reproducibility.html"><a href="reproducibility.html#r-markdown"><i class="fa fa-check"></i><b>6.1.1</b> R Markdown</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="reproducibility.html"><a href="reproducibility.html#exercise-5.1"><i class="fa fa-check"></i><b>6.2</b> Exercise 5.1</a></li>
<li class="chapter" data-level="6.3" data-path="reproducibility.html"><a href="reproducibility.html#exercise-5.2"><i class="fa fa-check"></i><b>6.3</b> Exercise 5.2</a></li>
<li class="chapter" data-level="6.4" data-path="reproducibility.html"><a href="reproducibility.html#git"><i class="fa fa-check"></i><b>6.4</b> Git</a><ul>
<li class="chapter" data-level="6.4.1" data-path="reproducibility.html"><a href="reproducibility.html#git-and-rstudio"><i class="fa fa-check"></i><b>6.4.1</b> Git and RStudio</a></li>
<li class="chapter" data-level="6.4.2" data-path="reproducibility.html"><a href="reproducibility.html#cloning-granolarr"><i class="fa fa-check"></i><b>6.4.2</b> Cloning granolarr</a></li>
</ul></li>
<li class="chapter" data-level="6.5" data-path="reproducibility.html"><a href="reproducibility.html#exercise-5.3"><i class="fa fa-check"></i><b>6.5</b> Exercise 5.3</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html"><i class="fa fa-check"></i><b>7</b> Exploratory analysis</a><ul>
<li class="chapter" data-level="7.1" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#introduction"><i class="fa fa-check"></i><b>7.1</b> Introduction</a></li>
<li class="chapter" data-level="7.2" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#gglot2-recap"><i class="fa fa-check"></i><b>7.2</b> GGlot2 recap</a></li>
<li class="chapter" data-level="7.3" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#data-visualisation"><i class="fa fa-check"></i><b>7.3</b> Data visualisation</a><ul>
<li class="chapter" data-level="7.3.1" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#distributions"><i class="fa fa-check"></i><b>7.3.1</b> Distributions</a></li>
<li class="chapter" data-level="7.3.2" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#relationships"><i class="fa fa-check"></i><b>7.3.2</b> Relationships</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#exercise-7.1"><i class="fa fa-check"></i><b>7.4</b> Exercise 7.1</a></li>
<li class="chapter" data-level="7.5" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#exploratory-statistics"><i class="fa fa-check"></i><b>7.5</b> Exploratory statistics</a><ul>
<li class="chapter" data-level="7.5.1" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#descriptive-statistics"><i class="fa fa-check"></i><b>7.5.1</b> Descriptive statistics</a></li>
</ul></li>
<li class="chapter" data-level="7.6" data-path="exploratory-analysis.html"><a href="exploratory-analysis.html#exercise-7.2"><i class="fa fa-check"></i><b>7.6</b> Exercise 7.2</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="regression-analysis.html"><a href="regression-analysis.html"><i class="fa fa-check"></i><b>8</b> Regression analysis</a><ul>
<li class="chapter" data-level="8.1" data-path="regression-analysis.html"><a href="regression-analysis.html#introduction-1"><i class="fa fa-check"></i><b>8.1</b> Introduction</a></li>
<li class="chapter" data-level="8.2" data-path="regression-analysis.html"><a href="regression-analysis.html#anova"><i class="fa fa-check"></i><b>8.2</b> ANOVA</a><ul>
<li class="chapter" data-level="8.2.1" data-path="regression-analysis.html"><a href="regression-analysis.html#example"><i class="fa fa-check"></i><b>8.2.1</b> Example</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="regression-analysis.html"><a href="regression-analysis.html#simple-regression"><i class="fa fa-check"></i><b>8.3</b> Simple regression</a><ul>
<li class="chapter" data-level="8.3.1" data-path="regression-analysis.html"><a href="regression-analysis.html#example-1"><i class="fa fa-check"></i><b>8.3.1</b> Example</a></li>
<li class="chapter" data-level="8.3.2" data-path="regression-analysis.html"><a href="regression-analysis.html#checking-assumptions"><i class="fa fa-check"></i><b>8.3.2</b> Checking assumptions</a></li>
<li class="chapter" data-level="8.3.3" data-path="regression-analysis.html"><a href="regression-analysis.html#how-to-report"><i class="fa fa-check"></i><b>8.3.3</b> How to report</a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="regression-analysis.html"><a href="regression-analysis.html#multiple-regression"><i class="fa fa-check"></i><b>8.4</b> Multiple regression</a><ul>
<li class="chapter" data-level="8.4.1" data-path="regression-analysis.html"><a href="regression-analysis.html#example-2"><i class="fa fa-check"></i><b>8.4.1</b> Example</a></li>
</ul></li>
<li class="chapter" data-level="8.5" data-path="regression-analysis.html"><a href="regression-analysis.html#exercise-9.1"><i class="fa fa-check"></i><b>8.5</b> Exercise 9.1</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="geodemographic-classification.html"><a href="geodemographic-classification.html"><i class="fa fa-check"></i><b>9</b> Geodemographic classification</a><ul>
<li class="chapter" data-level="9.1" data-path="geodemographic-classification.html"><a href="geodemographic-classification.html#introduction-2"><i class="fa fa-check"></i><b>9.1</b> Introduction</a></li>
</ul></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Geographic data science reproducible teaching resource in R<br/>Practical session materials</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="reproducibility" class="section level1">
<h1><span class="header-section-number">6</span> Reproducibility</h1>
<p><em><a href="https://stefanodesabbata.com">Stefano De Sabbata</a></em></p>
<p><a href="https://github.com/sdesabbata/granolarr">This work</a> is licensed under the <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU General Public License v3.0</a>. Contains public sector information licensed under the <a href="http://www.nationalarchives.gov.uk/doc/open-government-licence">Open Government Licence v3.0</a>.</p>
<div id="markdown" class="section level2">
<h2><span class="header-section-number">6.1</span> Markdown</h2>
<p>A essential tool used in creating these materials is <a href="https://rmarkdown.rstudio.com/">RMarkdown</a> That is an R library that allows you to create scripts that mix the Markdown mark-up language and R, to create dynamic documents. RMarkdown script can be compiled, at which point, the Markdown notation is interpreted to create the output files, while the R code is executed and the output incorporated in the document.</p>
<p>For instance the following markdown code</p>
<pre class="mark"><code>[This is a link to the University of Leicester](http://le.ac.uk) and **this is in bold**.</code></pre>
<p>is rendered as</p>
<p><a href="http://le.ac.uk">This is a link to the University of Leicester</a> and <strong>this is in bold</strong>.</p>
<p>The core Markdown notation used in this session is presented below. A full RMarkdown <em>cheatsheet</em> is available <a href="https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf">here</a>.</p>
<pre class="mark"><code># Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
**bold**
*italics*
[This is a link to the University of Leicester](http://le.ac.uk)
- Example list
- Main folder
- Analysis
- Data
- Utils
- Other bullet point
- And so on
- and so forth
1. These are
1. Numeric bullet points
2. Number two
2. Another number two
3. This is number three</code></pre>
<div id="r-markdown" class="section level3">
<h3><span class="header-section-number">6.1.1</span> R Markdown</h3>
<p>R code can be embedded in RMarkdown documents as in the example below. That results in the code chunk be displayed within the document (as <em>echo=TRUE</em> is specified), followed by the output from the execution of the same code.</p>
<pre><code>```{r, echo=TRUE}
a_number <- 0
a_number <- a_number + 1
a_number <- a_number + 1
a_number <- a_number + 1
a_number
```</code></pre>
<div class="sourceCode" id="cb278"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb278-1" data-line-number="1">a_number <-<span class="st"> </span><span class="dv">0</span></a>
<a class="sourceLine" id="cb278-2" data-line-number="2">a_number <-<span class="st"> </span>a_number <span class="op">+</span><span class="st"> </span><span class="dv">1</span></a>
<a class="sourceLine" id="cb278-3" data-line-number="3">a_number <-<span class="st"> </span>a_number <span class="op">+</span><span class="st"> </span><span class="dv">1</span></a>
<a class="sourceLine" id="cb278-4" data-line-number="4">a_number <-<span class="st"> </span>a_number <span class="op">+</span><span class="st"> </span><span class="dv">1</span></a>
<a class="sourceLine" id="cb278-5" data-line-number="5">a_number</a></code></pre></div>
<pre><code>## [1] 3</code></pre>
</div>
</div>
<div id="exercise-5.1" class="section level2">
<h2><span class="header-section-number">6.2</span> Exercise 5.1</h2>
<p>Create a new R project named <em>Practical_301</em> as the directory name. Create an RMarkdown document in RStudio by selecting <em>File > New File > R Markdown …</em> – this might prompt RStudio to update some packages. On the RMarkdown document creation menu, specify “Practical 05” as title and your name as the author, and select <em>PDF</em> as default output format.</p>
<p>The new document should contain the core document information, as in the example below, plus some additional content that simply explains how RMarkdown works.</p>
<pre><code>---
title: "Practical 05"
author: "A. Student"
date: "7 October 2018"
output: pdf_document
---</code></pre>
<p>Delete the contents below the document information and copy the following text below the document information.</p>
<pre><code># Pipe example
This is my first [RMarkdown](https://rmarkdown.rstudio.com/) document.
```{r, echo=TRUE}
library(tidyverse)
```
The code uses the pipe operator:
- takes 2 as input
- calculates the square root
- rounds the value
- keeping only two digits
```{r, echo=TRUE}
2 %>%
sqrt() %>%
round(digits = 2)
```</code></pre>
<p>The option <code>echo=TRUE</code> tells RStudio to include the code in the output document, along with the output of the computation. If <code>echo=FALSE</code> is specified, the code will be omitted. If the option <code>message=FALSE</code> and <code>warning=FALSE</code> are added, messages and warnings from R are not displayed in the output document.</p>
<p>Save the document by selecting <em>File > Save</em> from the main menu. Enter <em>Square_root</em> as file name and click <em>Save</em>. The file is saved using the <em>Rmd</em> (RMarkdown) extension.</p>
<p>Click on the <em>Knit</em> button on the bar above the editor panel (top-left area) in RStudio, on the left side. Check the resulting <em>pdf</em> document. Try adding some of your own code (e.g., using some of the examples above) and Markdown text, and compile the document again.</p>
</div>
<div id="exercise-5.2" class="section level2">
<h2><span class="header-section-number">6.3</span> Exercise 5.2</h2>
<p>Create an analysis document based on RMarkdown for each one of the two analyses seen in the practical sessions 3 and 4. For each of the two analyses, within their respective R projects, first, create an RMarkdown document. Then, add the code from the related R script. Finally add additional content such as title, subtitles, and most importantly, some text describing the data used, how the analysis has been done, and the result obtained. Make sure you add appropriate links to the data sources, as available in the practical session materials.</p>
</div>
<div id="git" class="section level2">
<h2><span class="header-section-number">6.4</span> Git</h2>
<p>Git is a free and opensource version control system. It is commonly used through a server, where a master copy of a project is kept, but it can also be used locally. Git allows storing versions of a project, thus providing file synchronisation, consistency, history browsing, and the creation of multiple branches. For a detailed introduction to Git, please refer to the <a href="https://git-scm.com/book">Pro Git book, written by Scott Chacon and Ben Straub</a>.</p>
<p>As illustrated in the image below, when working with a git repository, the most common approach is to first check-out the latest version from the main repository before start working on any file. Once a series of edits have been made, the edits to stage are selected and then committed in a permanent snapshot. One or more commits can then be pushed to the main repository.</p>
<div class="figure">
<img src="Images/git_three_stages.png" alt="by Scott Chacon and Ben Straub, licensed under CC BY-NC-SA 3.0" style="width:80.0%" />
<p class="caption"><a href="https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F">by Scott Chacon and Ben Straub</a>, licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA 3.0</a></p>
</div>
<div id="git-and-rstudio" class="section level3">
<h3><span class="header-section-number">6.4.1</span> Git and RStudio</h3>
<p>In RStudio Server, in the <em>Files</em> tab of the bottom-left panel, click on <em>Home</em> to make sure you are in your home folder – if you are working on your own computer, create a folder for granolarr wherever most convenient. Click on <em>New Folder</em> and enter <em>Repos</em> (short for repositories) in the prompt dialogue, to create a folder named <em>Repos</em>.</p>
<p>Create a GitHub account at <a href="https://github.com/">github.com</a>, if you don’t have one, and create a new repository named <em>my-granolarr</em>, following the instructions available on the <a href="https://help.github.com/en/articles/creating-a-new-repository">GitHub help pages</a>. Make sure you tick the box next to <em>Initialize this repository with a README</em>, which adds a <code>README.md</code> markdown file to your repository.</p>
<p>Once the repository has been created, GitHub will take you to the repository page. Copy the link to the repository <code>.git</code> file by clicking on the green <em>Clone or download</em> button and copying the <code>https</code> URL there available. Back to RStudio Server, select <em>File > New Project…</em> from the top menu and select <em>Version Control</em> and then <em>Git</em> from the <em>New Project</em> panel. Paste the copied URL in the <em>Repository URL</em> field, select the <em>Repos</em> folder created above as folder for <em>Create project as subdirectory of</em>, and click <em>Create Project</em>. RStudio might ask you for your GitHub username and password at this point.</p>
<div class="figure">
<img src="Images/git_clone_my-granolarr.png" alt="Cloning my-granolarr as R project in RStudio" style="width:60.0%" />
<p class="caption">Cloning my-granolarr as R project in RStudio</p>
</div>
<p>Before continuing, you need to record your identity with the Git system installed on the RStudio Server, for it to be able to communicate with the GitHub’s server. Open the <em>Terminal</em> tab in RStudio (if not visible, select <em>Tools > Terminal > New Terminal</em> from the top menu). First, paste the command below substituting <code>[email protected]</code> with your university email (make sure to maintain the double quotes) and press the return button.</p>
<pre><code>git config --global user.email "[email protected]"</code></pre>
<p>Then, paste the command below substituting <code>Your Name</code> with your name (make sure to maintain the double quotes) and press the return button.</p>
<pre><code>git config --global user.name "Your Name"</code></pre>
<p>RStudio should have now switched to a new R project linked to you <em>my-granolarr</em> repository. In the RStudio <em>File</em> tab in the bottom-right panel, navigate to the file created for the exercises above, select the files and copy them in the folder of the new project (in the <em>File</em> tab, <em>More > Copy To…</em>).</p>
<p>Check the now available <em>Git</em> tab on the top-right panel, and you should see at least the newly copied files marked as untracked. Tick the checkboxes in the <em>Staged</em> column to stage the files, then click on the <em>Commit</em> button.</p>
<p>In the newly opened panel <em>Commit</em> window, the top-left section shows the files, and the bottom section shows the edits. Write <code>My first commit</code> in the <em>Commit message</em> section in the top-right, and click the <em>Commit</em> button. A pop-up should notify the completed commit. Close both the pop-up panel, and click the <em>Push</em> button on the top-right of the <em>Commit</em> window. Another pop-up panel should ask you for your GitHub username and password and then show the executed push operation. Close both the pop-up panel and the <em>Commit</em> window.</p>
<p>Congratulations, you have completed your first commit! Check the repository page on GitHub. If you reload the page, the top bar should show <em>2 commits</em> on the left and your files should now be visible in the file list below. If you click on <em>2 commits</em>, you can see the commit history, including both the initial commit that created the repository and the commit you just completed.</p>
</div>
<div id="cloning-granolarr" class="section level3">
<h3><span class="header-section-number">6.4.2</span> Cloning granolarr</h3>
<p>You can follow the steps listed below to clone the granolarr repository.</p>
<ol style="list-style-type: decimal">
<li><p>Create a folder named <code>Repos</code> in your home directory. If you are working on RStudio Server, in the <em>Files</em> panel, click on the <code>Home</code> button (second bar, next to the house icon), then click on <code>New Folder</code>, enter the name <code>Repos</code> and click <code>Ok</code>.</p></li>
<li><p>In RStudio or RStudio Server select <code>File > New Project...</code></p></li>
<li><p>Select <code>Version Control</code> and then <code>Git</code> (you might need to set up Git first if you are working on your own computer)</p></li>
<li><p>Copy <code>https://github.com/sdesabbata/granolarr.git</code> in the <code>Repository URL</code> field and select the Repos folder for the field <code>Create project as subdirectory of</code>, and click on <code>Create Project</code>.</p></li>
<li><p>Have a look around</p></li>
<li><p>Click on the project name <code>granolarr</code> on the top-left of the interface and select <code>Close Project</code> to close the project.</p></li>
</ol>
<p>As granolarr is a public repository, you can clone it, edit it as you wish and push it to your own copy of the repository. However, contributing your edits to the original repository would require a few further steps. Check out the <a href="https://help.github.com/en/articles/committing-changes-to-a-pull-request-branch-created-from-a-fork">GitHub help pages</a> if you are interested.</p>
</div>
</div>
<div id="exercise-5.3" class="section level2">
<h2><span class="header-section-number">6.5</span> Exercise 5.3</h2>
<p>Create a new repository for an R project exploring the presence of the different living arrangements in Leicester among both the different categories of the 2011 Output Area Classification and deciles of Index of Multiple Deprivations. Create the repository, clone it to RStudio Server as a new R project, and copy the required data in the project folder. Create an RMarkdown document and write your analysis, including:</p>
<ul>
<li>an introduction to the data and the aims of the project;</li>
<li>a justification of the analysis methods;</li>
<li>the code and related results;</li>
<li>and a discussion of the results within the same document.</li>
</ul>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="data-wrangling-pt-2.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="exploratory-analysis.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"google": false,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "google", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "subsection"
}
});
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
var src = "true";
if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
if (location.protocol !== "file:")
if (/^https?:/.test(src))
src = src.replace(/^https?:/, '');
script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>