-
Notifications
You must be signed in to change notification settings - Fork 24
/
an-introduction-to-spatial-data-analysis-and-statistics-a-course-in-r.html
488 lines (386 loc) · 20.4 KB
/
an-introduction-to-spatial-data-analysis-and-statistics-a-course-in-r.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 lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 1 An Introduction to Spatial Data Analysis and Statistics: A Course in R | README.knit</title>
<meta name="description" content="" />
<meta name="generator" content="bookdown 0.24.4 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 1 An Introduction to Spatial Data Analysis and Statistics: A Course in R | README.knit" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 1 An Introduction to Spatial Data Analysis and Statistics: A Course in R | README.knit" />
<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" />
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">Spatial Analysis in R</a></li>
<li class="divider"></li>
<li class="chapter" data-level="1" data-path=""><a href="#an-introduction-to-spatial-data-analysis-and-statistics-a-course-in-r"><i class="fa fa-check"></i><b>1</b> An Introduction to Spatial Data Analysis and Statistics: A Course in R</a>
<ul>
<li class="chapter" data-level="1.1" data-path=""><a href="#introduction"><i class="fa fa-check"></i><b>1.1</b> Introduction</a></li>
<li class="chapter" data-level="1.2" data-path=""><a href="#resources-for-students-and-instructors"><i class="fa fa-check"></i><b>1.2</b> Resources for Students and Instructors</a>
<ul>
<li class="chapter" data-level="1.2.1" data-path=""><a href="#presentation-slides"><i class="fa fa-check"></i><b>1.2.1</b> Presentation slides</a></li>
<li class="chapter" data-level="1.2.2" data-path=""><a href="#template-repository-for-projects"><i class="fa fa-check"></i><b>1.2.2</b> Template repository for projects</a></li>
<li class="chapter" data-level="1.2.3" data-path=""><a href="#examples-of-projects"><i class="fa fa-check"></i><b>1.2.3</b> Examples of projects</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path=""><a href="#contributing"><i class="fa fa-check"></i><b>1.3</b> Contributing</a></li>
<li class="chapter" data-level="1.4" data-path=""><a href="#reproducing-the-book"><i class="fa fa-check"></i><b>1.4</b> Reproducing the book</a></li>
<li class="chapter" data-level="1.5" data-path=""><a href="#the-book-in-binder"><i class="fa fa-check"></i><b>1.5</b> The book in binder</a></li>
<li class="chapter" data-level="1.6" data-path=""><a href="#the-book-in-a-docker-container"><i class="fa fa-check"></i><b>1.6</b> The book in a Docker container</a></li>
<li class="chapter" data-level="1.7" data-path=""><a href="#reproducing-this-readme"><i class="fa fa-check"></i><b>1.7</b> Reproducing this README</a></li>
<li class="chapter" data-level="1.8" data-path=""><a href="#citations"><i class="fa fa-check"></i><b>1.8</b> Citations</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/paezha/spatial-analysis-R" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./"></a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<!--bookdown:title:end-->
<!--bookdown:title:start-->
<div id="an-introduction-to-spatial-data-analysis-and-statistics-a-course-in-r" class="section level1" number="1">
<h1><span class="header-section-number">Chapter 1</span> An Introduction to Spatial Data Analysis and Statistics: A Course in R</h1>
<!-- badges: start -->
<p><a href="https://github.com/paezha/spatial-analysis-r/graphs/contributors"><img src="https://img.shields.io/github/contributors/paezha/spatial-analysis-r?color=2b9348" alt="GitHub all contributors" /></a>
[<img src="https://img.shields.io/github/commit-activity/y/paezha/spatial-analysis-r" alt="GitHub commit activity" />
<a href="https://mybinder.org/v2/gh/paezha/spatial-analysis-r/main?urlpath=rstudio"><img src="http://mybinder.org/badge_logo.svg" alt="Launch Rstudio Binder" /></a>
<a href="https://zenodo.org/badge/latestdoi/391072865"><img src="https://zenodo.org/badge/391072865.svg" alt="DOI" /></a>
<!-- badges: end --></p>
<div id="introduction" class="section level2" number="1.1">
<h2><span class="header-section-number">1.1</span> Introduction</h2>
<p>This repository hosts the code underlying the book <em>An Introduction to Spatial Data Analysis and Statistics: A Course in R</em>, by <a href="https://www.science.mcmaster.ca/ees/component/comprofiler/userprofile/paezha.html">Antonio Paez</a>:</p>
<blockquote>
<p>Paez A (2021). An Introduction to Spatial Data Analysis and Statistics: A Course in R. McMaster Invisible Press. ISBN: 978-1-7778515-0-7</p>
</blockquote>
<p>The book is free to read online at <a href="https://paezha.github.io/spatial-analysis-r" class="uri">https://paezha.github.io/spatial-analysis-r</a>.</p>
</div>
<div id="resources-for-students-and-instructors" class="section level2" number="1.2">
<h2><span class="header-section-number">1.2</span> Resources for Students and Instructors</h2>
<div id="presentation-slides" class="section level3" number="1.2.1">
<h3><span class="header-section-number">1.2.1</span> Presentation slides</h3>
<p>I have created a set of presentation slides in mentimeter for each substantive chapter in the book. I use these as mini-lectures in a <a href="https://en.wikipedia.org/wiki/Flipped_classroom">flipped classroom</a> format in my course, but they can be used as a template for creating longer presentations or lectures.</p>
<table>
<thead>
<tr class="header">
<th>Chapter</th>
<th>Mentimeter Slides</th>
<th>Static pdf file</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Chapter 3</td>
<td><a href="https://www.mentimeter.com/s/de73cd678c3af6b487f2f06eee44cad7/966186ab94da/edit">Introduction to Mapping</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 5</td>
<td><a href="https://www.mentimeter.com/s/0fbd2c03bf23a9da5fbac902278644fe/ee9058215205/edit">Mapping in <code>R</code> Continued</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 7</td>
<td><a href="https://www.mentimeter.com/s/59484637c743e96b6810c5e48b2cf405/d1152a9e811c/edit">Maps as Processes</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 9</td>
<td><a href="https://www.mentimeter.com/s/2db531a235490f7d66a0077f2c4f0930/df1cd6ccccbb/edit">Point Pattern Analysis I</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 11</td>
<td><a href="https://www.mentimeter.com/s/100f17f481ed1f28dd98112492533ba6/389b8ed12832/edit">Point Pattern Analysis II</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 13</td>
<td><a href="https://www.mentimeter.com/s/8495ddf8551f0083017726a9f68cfa5b/4e5c29e8c78e/edit">Point Pattern Analysis III</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 15</td>
<td><a href="https://www.mentimeter.com/s/587258400bd04521b52585f27296a799/57f84401a6a6/edit">Point Pattern Analysis IV</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 17</td>
<td><a href="https://www.mentimeter.com/s/fe385c8dbd256f2645507290f579b15c/2056e80d53e4/edit">Point Pattern Analysis V</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 19</td>
<td><a href="https://www.mentimeter.com/s/cab8fcae7e9b2cd1f447f79b5349dd23/d939ca4b33e9/edit">Area Data I</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 21</td>
<td><a href="https://www.mentimeter.com/s/c8442809151f00d4ac7e4a300bdf707a/20932ed527b6/edit">Area Data II</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 23</td>
<td><a href="https://www.mentimeter.com/s/175ee004df6fb9452837023e02b2960b/96666c58d803/edit">Area Data III</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 25</td>
<td><a href="https://www.mentimeter.com/s/516dae79f2558cd948da3de61b1c2b54/b7bb868b80d0/edit">Area Data IV</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 27</td>
<td><a href="https://www.mentimeter.com/s/32ee96ef3aaf83559b779f3fb88fc209/341e94b74b69/edit">Area Data V</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 29</td>
<td><a href="https://www.mentimeter.com/s/13eade97c82235b94c73d6dec6ef34a7/10a4634c3a9d/edit">Area Data VI</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 31</td>
<td><a href="https://www.mentimeter.com/s/57b95c57c9a4b75e91d91adb8b6e5faa/330c2ca0d567/edit">Spatially Continuous Data I</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 33</td>
<td><a href="https://www.mentimeter.com/s/b40aa86207d96711a40c73397bd36d08/f8248b9e8ecd/edit">Spatially Continuous Data II</a></td>
<td>pdf</td>
</tr>
<tr class="odd">
<td>Chapter 35</td>
<td><a href="https://www.mentimeter.com/s/d651523809c79353767df82bc7ba4d2f/d8e42a7811ed/edit">Spatially Continuous Data III</a></td>
<td>pdf</td>
</tr>
<tr class="even">
<td>Chapter 37</td>
<td><a href="https://www.mentimeter.com/s/78b3ec0313be43abe9995fe4c3447dd2/07a125804a15/edit">Spatially Continuous Data IV</a></td>
<td>pdf</td>
</tr>
</tbody>
</table>
</div>
<div id="template-repository-for-projects" class="section level3" number="1.2.2">
<h3><span class="header-section-number">1.2.2</span> Template repository for projects</h3>
<p>I created a <a href="https://github.com/paezha/ES4GA3-Sample-Repository">template repository</a> to help students get started with the use of GitHub and R Markdown for collaborative work on term projects. In my own course adoption of this workflow is completely optional. Not every student/group has the inclination/time to adopt this approach, but those who do produce very professional-looking reports and learn valuable skills.</p>
</div>
<div id="examples-of-projects" class="section level3" number="1.2.3">
<h3><span class="header-section-number">1.2.3</span> Examples of projects</h3>
<p>There will be some examples of projects in this <a href="https://github.com/paezha/student-projects">repository</a>.</p>
</div>
</div>
<div id="contributing" class="section level2" number="1.3">
<h2><span class="header-section-number">1.3</span> Contributing</h2>
<p>An advantage of an Open Educational Resource compared to traditional publishing (besides it being free!) is that it is a live, ongoing project, for as long as anyone cares for it. If you are using this resource, I would encourage you to contribute to improve it, by:</p>
<ul>
<li>suggesting improvements to the text, e.g. clarifying unclear sentences, fixing typos (see guidance from <a href="https://yihui.name/en/2013/06/fix-typo-in-documentation/">Yihui Xie</a>);</li>
<li>proposing changes to the code, e.g. to do things in a more efficient way; and</li>
<li>making requests to develop content (see the project’s <a href="https://github.com/paezha/spatial-analysis-r/issues">issue tracker</a>).</li>
</ul>
<!-- Need to check what the style is
See [our-style.md](https://github.com/Robinlovelace/geocompr/blob/master/our-style.md) for the book's style.
-->
<p>Many thanks to all contributors to the book so far via GitHub (this list will update automatically): <a href="https://github.com/Robinlovelace">Robinlovelace</a>.</p>
<!-- Need to figure out what this is
During the project we aim to contribute 'upstream' to the packages that make geocomputation with R possible.
This impact is recorded in [`our-impact.csv`](https://github.com/Robinlovelace/geocompr/blob/master/our-impact.csv).
-->
</div>
<div id="reproducing-the-book" class="section level2" number="1.4">
<h2><span class="header-section-number">1.4</span> Reproducing the book</h2>
<p>TODO
<!--
To ease reproducibility, we created the `geocompkg` package.
Installing it from GitHub will install all the R packages needed build the book (you will a computer with necessary [system dependencies](https://github.com/r-spatial/sf#installing) and the [**remotes**](https://github.com/r-lib/remotes/) package installed):
```r
install.packages("remotes")
remotes::install_github("geocompr/geocompkg")
```
You need a recent version of the GDAL, GEOS, PROJ and UDUNITS libraries installed for this to work on Mac and Linux. See the **sf** package's [README](https://github.com/r-spatial/sf) for information on that.
Once the dependencies have been installed you should be able to build and view a local version the book with:
```r
bookdown::render_book("index.Rmd") # to build the book
browseURL("_book/index.html") # to view it
```
<!-- The code associated with each chapter is saved in the `code/chapters/` folder. -->
<!-- `source("code/chapters/07-transport.R")` runs run the code chunks in chapter 7, for example. -->
<!-- These R scripts are generated with the follow command which wraps `knitr::purl()`: --></p>
</div>
<div id="the-book-in-binder" class="section level2" number="1.5">
<h2><span class="header-section-number">1.5</span> The book in binder</h2>
<p>I think I got the binder to work.</p>
<p><a href="https://mybinder.org/v2/gh/paezha/spatial-analysis-r/main?urlpath=rstudio"><img src="http://mybinder.org/badge_logo.svg" alt="Launch Rstudio Binder" /></a></p>
<!--
For many people the quickest way to get started with Geocomputation with R is in your web browser via Binder.
To see an interactive RStudio Server instance click on the following button, which will open [mybinder.org](https://mybinder.org/v2/gh/robinlovelace/geocompr/master?urlpath=rstudio) with an R installation that has all the dependencies needed to reproduce the book:
#You can also have a play with the repo in RStudio Cloud by clicking on this link (requires log-in):
-->
</div>
<div id="the-book-in-a-docker-container" class="section level2" number="1.6">
<h2><span class="header-section-number">1.6</span> The book in a Docker container</h2>
<p>TODO
<!--
To ease reproducibility we have made Docker images available, at [geocompr/geocompr](https://hub.docker.com/r/geocompr/geocompr/) on DockerHub.
These images allow you to explore Geocomputation with R in a virtual machine that has up-to-date dependencies.
After you have [installed docker](https://www.docker.com/community-edition#/download) and set-it up on [your computer](https://docs.docker.com/install/linux/linux-postinstall/) you can start RStudio Server without a password (see the [Rocker project](https://www.rocker-project.org/use/managing_users/) for info on how to add a password and other security steps for public-facing servers):
```sh
docker run -p 8787:8787 -e DISABLE_AUTH=TRUE geocompr/geocompr
```
If it worked you should be able to open-up RStudio server by opening a browser and navigating to
http://localhost:8787/ resulting in an up-to-date version of R and RStudio running in a container.
Start a plain R session running:
```sh
docker run -it geocompr/geocompr R
```
See the [geocompr/docker](https://github.com/geocompr/docker#geocomputation-with-r-in-docker) repo for details, including how to share volumes between your computer and the Docker image, for using geographic R packages on your own data and for information on available tags.
--></p>
</div>
<div id="reproducing-this-readme" class="section level2" number="1.7">
<h2><span class="header-section-number">1.7</span> Reproducing this README</h2>
<p>TODO</p>
<!--
To reduce the book's dependencies, scripts to be run infrequently to generate input for the book are run on creation of this README.
The additional packages required for this can be installed as follows:
```r
source("code/extra-pkgs.R")
```
With these additional dependencies installed, you should be able to run the following scripts, which create content for the book, that we've removed from the main book build to reduce package dependencies and the book's build time:
```r
source("code/cranlogs.R")
source("code/sf-revdep.R")
source("code/08-urban-animation.R")
source("code/08-map-pkgs.R")
```
Note: the `.Rproj` file is configured to build a website not a single page.
To reproduce this [README](https://github.com/Robinlovelace/geocompr/blob/master/README.Rmd) use the following command:
```r
rmarkdown::render("README.Rmd", output_format = "github_document", output_file = "README.md")
```
<!-- ## Book statistics -->
<!-- An indication of the book's progress over time is illustrated below (to be updated roughly every week as the book progresses). -->
<!--
<!-- Book statistics: estimated number of pages per chapter over time. -->
</div>
<div id="citations" class="section level2" number="1.8">
<h2><span class="header-section-number">1.8</span> Citations</h2>
<p>TODO</p>
<!--
To cite packages used in this book we use code from [Efficient R Programming](https://csgillespie.github.io/efficientR/):
```r
# geocompkg:::generate_citations()
```
This generates .bib and .csv files containing the packages.
The current of packages used can be read-in as follows:
```r
#pkg_df = readr::read_csv("extdata/package_list.csv")
```
Other citations are stored online using Zotero.
If you would like to add to the references, please use Zotero, join the [open group](https://www.zotero.org/groups/418217/energy-and-transport) add your citation to the open [geocompr library](https://www.zotero.org/groups/418217/energy-and-transport/items/collectionKey/9K6FRP6N).
We use the following citation key format:
```
[auth:lower]_[veryshorttitle:lower]_[year]
```
This can be set from inside Zotero desktop with the Better Bibtex plugin installed (see [github.com/retorquere/zotero-better-bibtex](https://github.com/retorquere/zotero-better-bibtex)) by selecting the following menu options (with the shortcut `Alt+E` followed by `N`), and as illustrated in the figure below:
```
Edit > Preferences > Better Bibtex
```
![](figures/zotero-settings.png)
Zotero settings: these are useful if you want to add references.
We use Zotero because it is a powerful open source reference manager that integrates well with the **citr** package.
As described in the GitHub repo [Robinlovelace/rmarkdown-citr-demo](https://github.com/Robinlovelace/rmarkdown-citr-demo).
## References
```r
# remotes::install_github("gadenbuie/regexplain")
# regexplain::regexplain_file("extdata/package_list.csv")
#pattern = " \\[[^\\}]*\\]" # perl=TRUE
#pkg_df$Title = gsub(pattern = pattern, replacement = "", x = pkg_df$Title, perl = TRUE)
#knitr::kable(pkg_df)
```
-->
</div>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/paezha/spatial-analysis-R/edit/main/%s",
"text": "Edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"search": false,
"toc": {
"collapse": "subsection"
}
});
});
</script>
</body>
</html>