-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.tex
11242 lines (9549 loc) · 512 KB
/
index.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
letterpaper,
DIV=11,
numbers=noendperiod,
oneside]{scrreprt}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[left=1in,marginparwidth=2.0666666666667in,textwidth=4.1333333333333in,marginparsep=0.3in]{geometry}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{5}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
\setlength{\parsep}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1
\setlength{\leftmargin}{\cslhangindent}
\setlength{\itemindent}{-1\cslhangindent}
\fi
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
\KOMAoption{captions}{tableheading}
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\@ifpackageloaded{fontawesome5}{}{\usepackage{fontawesome5}}
\definecolor{quarto-callout-color}{HTML}{909090}
\definecolor{quarto-callout-note-color}{HTML}{0758E5}
\definecolor{quarto-callout-important-color}{HTML}{CC1914}
\definecolor{quarto-callout-warning-color}{HTML}{EB9113}
\definecolor{quarto-callout-tip-color}{HTML}{00A047}
\definecolor{quarto-callout-caution-color}{HTML}{FC5300}
\definecolor{quarto-callout-color-frame}{HTML}{acacac}
\definecolor{quarto-callout-note-color-frame}{HTML}{4582ec}
\definecolor{quarto-callout-important-color-frame}{HTML}{d9534f}
\definecolor{quarto-callout-warning-color-frame}{HTML}{f0ad4e}
\definecolor{quarto-callout-tip-color-frame}{HTML}{02b875}
\definecolor{quarto-callout-caution-color-frame}{HTML}{fd7e14}
\makeatother
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{sidenotes}{}{\usepackage{sidenotes}}
\@ifpackageloaded{marginnote}{}{\usepackage{marginnote}}
\makeatother
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={Spatial Modelling for Data Scientists},
pdfauthor={Francisco Rowe, Dani Arribas-Bel},
colorlinks=true,
linkcolor={blue},
filecolor={Maroon},
citecolor={Blue},
urlcolor={Blue},
pdfcreator={LaTeX via pandoc}}
\title{Spatial Modelling for Data Scientists}
\author{Francisco Rowe, Dani Arribas-Bel}
\date{2024-02-16}
\begin{document}
\maketitle
\renewcommand*\contentsname{Table of contents}
{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\bookmarksetup{startatroot}
\chapter*{Welcome}\label{welcome}
\addcontentsline{toc}{chapter}{Welcome}
\markboth{Welcome}{Welcome}
This is the website for \textbf{Spatial Modeling for Data Scientists
2023/24}. This is a course taught by Professor Francisco Rowe at the
University of Liverpool, United Kingdom. The course materials were
developed by Professor Francisco Rowe and Professor Dani Arribas-Bel.
You will learn how to analyse and model different types of spatial data
as well as gaining an understanding of the various challenges arising
from manipulating such data.
The website is licensed under the
\href{https://creativecommons.org/licenses/by-nc-nd/4.0/}{Attribution-NonCommercial-NoDerivatives
4.0 International} License. A compilation of this web course is hosted
as a GitHub repository that you can access:
\begin{itemize}
\tightlist
\item
As a
\href{https://github.com/GDSL-UL/san/archive/master.zip}{download} of
a \texttt{.zip} file that contains all the materials.
\item
As an \href{https://gdsl-ul.github.io/san/}{html website}.
\item
As a
\href{https://gdsl-ul.github.io/san/spatial_analysis_notes.pdf}{pdf
document}
\item
As a \href{https://github.com/GDSL-UL/san}{GitHub repository}.
\end{itemize}
\section*{Contact}\label{contact}
\addcontentsline{toc}{section}{Contact}
\markright{Contact}
\begin{quote}
Francisco Rowe - \texttt{F.Rowe-Gonzalez\ {[}at{]}\ liverpool.ac.uk}\\
Professor of Population Data Science\\
Office 507, Roxby Building,\\
University of Liverpool - 74 Bedford St S,\\
Liverpool, L69 7ZT,\\
United Kingdom.
\end{quote}
\bookmarksetup{startatroot}
\chapter{Overview}\label{overview}
Access to all materials, including lecture notes, computational
notebooks and datasets, is centralised through the use of the course
website available in the following url:
\begin{quote}
\url{https://gdsl-ul.github.io/san/}
\end{quote}
The module handbook, including the assessment description, criteria and
module programme, and videos for each teaching week can be accessed via
the module Canvas site:
\begin{quote}
\href{https://liverpool.instructure.com}{ENS453 Spatial Modelling for
Data Scientists}
\end{quote}
\section{Aims}\label{aims}
This module aims to provides students with a range of techniques for
analysing and modelling spatial data:
\begin{itemize}
\tightlist
\item
build upon the more general research training delivered via companion
modules on \emph{Data Collection and Data Analysis}, both of which
have an aspatial focus;
\item
highlight a number of key social issues that have a spatial dimension;
\item
explain the specific challenges faced when attempting to analyse
spatial data;
\item
introduce a range of analytical techniques and approaches suitable for
the analysis of spatial data; and,
\item
enhance practical skills in using \emph{R} software packages to
implement a wide range of spatial analytical tools.
\end{itemize}
\section{Learning Outcomes}\label{learning-outcomes}
By the end of the module, students should be able to:
\begin{itemize}
\tightlist
\item
identify some key sources of spatial data and resources of spatial
analysis and modelling tools;
\item
explain the advantages of taking spatial structure into account when
analysing spatial data;
\item
apply a range of computer-based techniques for the analysis of spatial
data, including mapping, correlation, kernel density estimation,
regression, multi-level models, geographically-weighted regression,
spatial interaction models and spatial econometrics;
\item
apply appropriate analytical strategies to tackle the key
methodological challenges facing spatial analysis -- spatial
autocorrelation, heterogeneity, and ecological fallacy; and,
\item
select appropriate analytical tools for analysing specific spatial
data sets to address emerging social issues facing the society.
\end{itemize}
\section{Feedback}\label{feedback}
\begin{itemize}
\item
\emph{Formal assessment of two computational essays}. Written
assignment-specific feedback will be provided within three working
weeks of the submission deadline. Comments will offer an understanding
of the mark awarded and identify areas which can be considered for
improvement in future assignments.
\item
\emph{Verbal face-to-face feedback}. Immediate face-to-face feedback
will be provided during lecture, discussion and clinic sessions in
interaction with staff. This will take place in all live sessions
during the semester.
\item
\emph{Online forum}. Asynchronous written feedback will be provided
via an online forum maintained by the module lead. Students are
encouraged to contribute by asking and answering questions relating to
the module content. Staff will monitor the forum Monday to Friday
9am-5pm, but it will be open to students to make contributions at all
times.
\end{itemize}
\section{Computational Environment}\label{computational-environment}
To reproduce the code in the book, you need the following software
packages:
\begin{itemize}
\tightlist
\item
R-4.3.1
\item
RStudio 2023.09.0+463
\item
Quarto 1.3.450
\item
the list of libraries in the next section
\end{itemize}
To check your version of:
\begin{itemize}
\tightlist
\item
R and libraries run \texttt{sessionInfo()}
\item
RStudio click \texttt{help} on the menu bar and then \texttt{About}
\item
Quarto check the \texttt{version} file in the quarto folder on your
computer.
\end{itemize}
To install and update:
\begin{itemize}
\tightlist
\item
R, download the appropriate version from
\href{https://cran.r-project.org}{The Comprehensive R Archive Network
(CRAN)}
\item
RStudio, download the appropriate version from
\href{https://posit.co/download/rstudio-desktop/}{Posit}
\item
Quarto, download the appropriate version from
\href{https://quarto.org/docs/get-started/}{the Quarto website}
\end{itemize}
\subsection{Dependency list}\label{sec-dependencies}
The list of libraries used in this book is provided below:
\begin{itemize}
\tightlist
\item
\texttt{arm}
\item
\texttt{car}
\item
\texttt{corrplot}
\item
\texttt{devtools}
\item
\texttt{FRK}
\item
\texttt{gghighlight}
\item
\texttt{ggplot2}
\item
\texttt{ggmap}
\item
\texttt{GISTools}
\item
\texttt{gridExtra}
\item
\texttt{gstat}
\item
\texttt{hexbin}
\item
\texttt{jtools}
\item
\texttt{kableExtra}
\item
\texttt{knitr}
\item
\texttt{lme4}
\item
\texttt{lmtest}
\item
\texttt{lubridate}
\item
\texttt{MASS}
\item
\texttt{merTools}
\item
\texttt{plyr}
\item
\texttt{RColorBrewer}
\item
\texttt{rgdal}
\item
\texttt{sf}
\item
\texttt{sjPlot}
\item
\texttt{sp}
\item
\texttt{spgwr}
\item
\texttt{spatialreg}
\item
\texttt{spacetime}
\item
\texttt{stargazer}
\item
\texttt{tidyverse}
\item
\texttt{tmap}
\item
\texttt{tufte}
\item
\texttt{viridis}
\item
\texttt{basemapR}
\end{itemize}
Copy, paste and run the code below in your console. Ensure all packages
are installed on your computer.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# package names}
\NormalTok{packages }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}
\StringTok{"arm"}\NormalTok{,}
\StringTok{"car"}\NormalTok{,}
\StringTok{"corrplot"}\NormalTok{,}
\StringTok{"devtools"}\NormalTok{,}
\StringTok{"FRK"}\NormalTok{,}
\StringTok{"gghighlight"}\NormalTok{,}
\StringTok{"ggplot2"}\NormalTok{,}
\StringTok{"ggmap"}\NormalTok{,}
\StringTok{"gridExtra"}\NormalTok{,}
\StringTok{"gstat"}\NormalTok{,}
\StringTok{"hexbin"}\NormalTok{,}
\StringTok{"jtools"}\NormalTok{,}
\StringTok{"kableExtra"}\NormalTok{,}
\StringTok{"knitr"}\NormalTok{,}
\StringTok{"lme4"}\NormalTok{,}
\StringTok{"lmtest"}\NormalTok{,}
\StringTok{"lubridate"}\NormalTok{,}
\StringTok{"MASS"}\NormalTok{,}
\StringTok{"merTools"}\NormalTok{,}
\StringTok{"plyr"}\NormalTok{,}
\StringTok{"RColorBrewer"}\NormalTok{,}
\StringTok{"sf"}\NormalTok{,}
\StringTok{"sjPlot"}\NormalTok{,}
\StringTok{"sp"}\NormalTok{,}
\StringTok{"spgwr"}\NormalTok{,}
\StringTok{"spatialreg"}\NormalTok{,}
\StringTok{"spacetime"}\NormalTok{,}
\StringTok{"stargazer"}\NormalTok{,}
\StringTok{"tidyverse"}\NormalTok{,}
\StringTok{"tmap"}\NormalTok{,}
\StringTok{"tufte"}\NormalTok{,}
\StringTok{"viridis"}
\NormalTok{)}
\CommentTok{\# install packages not yet installed}
\NormalTok{installed\_packages }\OtherTok{\textless{}{-}}\NormalTok{ packages }\SpecialCharTok{\%in\%} \FunctionTok{rownames}\NormalTok{(}\FunctionTok{installed.packages}\NormalTok{())}
\ControlFlowTok{if}\NormalTok{ (}\FunctionTok{any}\NormalTok{(installed\_packages }\SpecialCharTok{==} \ConstantTok{FALSE}\NormalTok{)) \{}
\FunctionTok{install.packages}\NormalTok{(packages[}\SpecialCharTok{!}\NormalTok{installed\_packages])}
\NormalTok{\}}
\CommentTok{\# packages loading}
\FunctionTok{invisible}\NormalTok{(}\FunctionTok{lapply}\NormalTok{(packages, library, }\AttributeTok{character.only =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
::: column-margin ::: callout-note To install the library
\texttt{basemapR}, you need to install from source by running:
\texttt{library(devtools)}\strut \\
\texttt{install\_github(\textquotesingle{}Chrisjb/basemapR\textquotesingle{})}
::: ::: column-margin
\section{Assessment}\label{assessment}
The final module mark is composed of the \emph{two computational
essays}. Together they are designed to cover the materials introduced in
the entirety of content covered during the semester. A computational
essay is an essay whose narrative is supported by code and computational
results that are included in the essay itself. Each teaching week, you
will be required to address a set of questions relating to the module
content covered in that week, and to use the material that you will
produce for this purpose to build your computational essay.
\textbf{Assignment 1 (50\%)} refer to the set of questions at the end of
Chapter~\ref{sec-chp4}, Chapter~\ref{sec-chp5} and
Chapter~\ref{sec-chp6}. You are required to use your responses to build
your computational essay. Each chapter provides more specific guidance
of the tasks and discussion that you are required to consider in your
assignment.
\textbf{Assignment 2 (50\%)} refer to the set of questions at the end of
Chapter~\ref{sec-chp7}, Chapter~\ref{sec-chp8}, Chapter~\ref{sec-chp9}
and Chapter~\ref{sec-chp10}. You are required to use your responses to
build your computational essay. Each chapter provides more specific
guidance of the tasks and discussion that you are required to consider
in your assignment.
\subsection{Format Requirements}\label{format-requirements}
Both assignments will have the same requirements:
\begin{itemize}
\tightlist
\item
Maximum word count: 2,000 words, excluding figures and references.
\item
Up to three maps, plot or figures (a figure may include more than one
map and/or plot and will only count as one but needs to be integrated
in the figure)
\item
Up to two tables.
\end{itemize}
Assignments need to be prepared in ``\emph{Quarto Document}'' format
(i.e.~qmd extension) and then converted into a self-contained HTML file
that will then be submitted via Turnitin. The document should only
display content that will be assessed. Intermediate steps do not need to
be displayed. Messages resulting from loading packages, attaching data
frames, or similar messages do not need to be included as output code.
Useful resources to customise your R notebook can be found on
\href{https://quarto.org/docs/guide/}{Quarto's website}.
Two Quarto Document templates will be available via
\href{https://canvas.liverpool.ac.uk/courses/60454}{the module Canvas
site}.
Submission is electronic only via Turnitin on Canvas.
\subsection{Marking criteria}\label{marking-criteria}
The Standard Environmental Sciences School marking criteria apply, with
a stronger emphasis on evidencing the use of regression models, critical
analysis of results and presentation standards. In addition to these
general criteria, the code and outputs (i.e.~tables, maps and plots)
contained within the notebook submitted for assessment will be assessed
according to the extent of documentation and evidence of expertise in
changing and extending the code options illustrated in each chapter.
Specifically, the following criteria will be applied:
\begin{itemize}
\tightlist
\item
\textbf{0-15}: no documentation and use of default options.
\item
\textbf{16-39}: little documentation and use of default options.
\item
\textbf{40-49}: some documentation, and use of default options.
\item
\textbf{50-59}: extensive documentation, and edit of some of the
options provided in the notebook (e.g.~change north arrow location).
\item
\textbf{60-69}: extensive well organised and easy to read
documentation, and evidence of understanding of options provided in
the code (e.g.~tweaking existing options).
\item
\textbf{70-79}: all above, plus clear evidence of code design skills
(e.g.~customising graphics, combining plots (or tables) into a single
output, adding clear axis labels and variable names on graphic
outputs, etc.).
\item
\textbf{80-100}: all as above, plus code containing novel
contributions that extend/improve the functionality the code was
provided with (e.g.~comparative model assessments, novel methods to
perform the task, etc.).
\end{itemize}
\bookmarksetup{startatroot}
\chapter{Spatial Data}\label{spatial_data}
This Chapter seeks to present and describe distinctive attributes of
spatial data, and discuss some of the main challenges in analysing and
modelling these data. Spatial data is a term used to describe any data
associating a given variable attribute to a specific location on the
Earth's surface.
\section{Spatial Data types}\label{spatial-data-types}
Different classifications of spatial data types exist. Knowing the
structure of the data at hand is important as specific analytical
methods would be more appropriate for particular data types. We will use
a particular classification involving four data types: lattice/areal
data, point data, flow data and trajectory data (Fig. 1). This is not a
exhaustive list but it is helpful to motivate the analytical and
modelling methods that we cover in this book.
\begin{figure}[H]
{\centering \includegraphics{figs/ch1/datatypes.png}
}
\caption{Fig. 1. Data Types. Area / Lattice data source: Önnerfors et
al. (2019). Point data source: Tao et al. (2018). Flow data source: Rowe
and Patias (2020). Trajectory data source: Kwan and Lee (2004).}
\end{figure}%
\emph{Lattice/Areal Data}. These data correspond to records of attribute
values (such as population counts) for a fixed geographical area. They
may comprise regular shapes (such as grids or pixels) or irregular
shapes (such as states, counties or travel-to-work areas). Raster data
are a common source of regular lattice/areal area, while censuses are
probably the most common form of irregular lattice/areal area. Point
data within an area can be aggregated to produce lattice/areal data.
\emph{Point Data}. These data refer to records of the geographic
location of an discrete event, or the number of occurrences of
geographical process at a given location. As displayed in Fig. 1,
examples include the geographic location of bus stops in a city, or the
number of boarding passengers at each bus stop.
\emph{Flow Data}. These data refer to records of measurements for a pair
of geographic point locations. or pair of areas. These data capture the
linkage or spatial interaction between two locations. Migration flows
between a place of origin and a place of destination is an example of
this type of data.
\emph{Trajectory Data}. These data record geographic locations of moving
objects at various points in time. A trajectory is composed of a single
string of data recording the geographic location of an object at various
points in time and each record in the string contains a time stamp.
These data are complex and can be classified into explicit trajectory
data and implicit trajectory data. The former refer to well-structured
data and record positions of objects continuously and intensively at
uniform time intervals, such as GPS data. The latter is less structured
and record data in relatively time point intervals, including
sensor-based, network-based and signal-based data (Kong et al. 2018).
In this course, we cover analytical and modelling approaches for point,
lattice/areal and flow data. While we do not explicitly analyse
trajectory data, various of the analytical approaches described in this
book can be extended to incorporate time, and can be applied to model
these types of data. In Chapter~\ref{sec-chp10}, we describe approaches
to analyse and model spatio-temporal data. These same methods can be
applied to trajectory data.
\section{Hierarchical Structure of
Data}\label{hierarchical-structure-of-data}
The hierarchical organisation is a key feature of spatial data. Smaller
geographical units are organised within larger geographical units. You
can find the hierarchical representation of UK Statistical Geographies
on the
\href{https://geoportal.statistics.gov.uk/search?collection=Document&sort=name&tags=all(DOC_HRSG\%2CDEC_2020)}{Office
for National Statistics website}. In the bottom part of the output
below, we can observe a spatial data frame for Liverpool displaying the
hierarchical structure of census data (from the smallest to the
largest): Output Areas (OAs), Lower Super Output Areas (LSOAs), Middle
Super Output Areas (MSOAs) and Local Authority Districts (LADs). This
hierarchical structure entails that units in smaller geographies are
nested within units in larger geographies, and that smaller units can be
aggregated to produce large units.
\begin{verbatim}
Simple feature collection with 6 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 335071.6 ymin: 389876.7 xmax: 339426.9 ymax: 394479
Projected CRS: Transverse_Mercator
OA_CD LSOA_CD MSOA_CD LAD_CD geometry
1 E00176737 E01033761 E02006932 E08000012 MULTIPOLYGON (((335106.3 38...
2 E00033515 E01006614 E02001358 E08000012 MULTIPOLYGON (((335810.5 39...
3 E00033141 E01006546 E02001365 E08000012 MULTIPOLYGON (((336738 3931...
4 E00176757 E01006646 E02001369 E08000012 MULTIPOLYGON (((335914.5 39...
5 E00034050 E01006712 E02001375 E08000012 MULTIPOLYGON (((339325 3914...
6 E00034280 E01006761 E02001366 E08000012 MULTIPOLYGON (((338198.1 39...
\end{verbatim}
Next we quickly go through the components of the output above. The first
line indicates the type of feature and the number of rows (features) and
columns (fields) in the data frame, except for the geometry. The second
and third lines identify the type of geometry and dimension. The fourth
line \texttt{bbox} stands for bounding box and display the min and max
coordinates containing the Liverpool area in the data frame. The fifth
line \texttt{projected\ CRS} indicates the coordinate reference system
projection. If you would like to learn more about the various components
of spatial data frames, please see the \emph{R} \texttt{sf} package
vignette on
\href{https://r-spatial.github.io/sf/articles/sf1.html}{Simple
Features}.
\section{Key Challenges}\label{key-challenges}
Major challenges exist when working with spatial data. Below we explore
some of the key longstanding problems data scientists often face when
working with geographical data.
\subsection{Modifible Area Unit Problem
(MAUP)}\label{modifible-area-unit-problem-maup}
The Modifible Area Unit Problem (MAUP) represents a challenge that has
troubled geographers for decades (Openshaw 1981). Two aspects of the
MAUP are normally recognised in empirical analysis relating to
\emph{scale} and \emph{zonation}. Fig. 2 illustrates these issues
\begin{itemize}
\item
\emph{Scale} refers to the idea that a geographical area can be
divided into geographies with differing numbers of spatial units.
\item
\emph{Zonation} refers to the idea that a geographical area can be
divided into the same number of units in a variety of ways.
\end{itemize}
\begin{figure}[H]
{\centering \includegraphics{figs/ch1/maup.png}
}
\caption{Fig. 2. MAUP effect. (a) scale effect; and, (b) zonation
effect. Source: Loidl et al. (2016).}
\end{figure}%
The MAUP is a critical issue as it can impact our analysis and thus any
conclusions we can infer from our results (e.g. A. S. Fotheringham and
Wong 1991). There is no agreed systematic approach on how to handle the
effects of the MAUP. Some have suggested to perform analyses based on
different existing geographical scales, and assess the consistency of
the results and identify potential sources of change. The issue with
such approach is that results from analysis at different scales are
likely to differ because distinct dimensions of a geographic process may
be captured at different scales. For example, in migration studies,
smaller geographies may be more suitable to capture residential mobility
over short distances, while large geographies may be more suitable to
capture long-distance migration. And it is well documented that these
types of moves are driven by different factors. While residential
mobility tends to be driven by housing related reasons, long-distance
migration is more closely related to employment-related motives
(Niedomysl 2011).
An alternative approach is to use the smallest geographical system
available and create random aggregations at various geographical scales,
to directly quantify the extent of scale and zonation. This approach has
shown promising results in applications to study internal migration
flows (Stillwell, Daras, and Bell 2018). Another approach involves the
production of ``meaningful'' or functional geographies that can more
appropriately capture the process of interest. There is an active area
of work defining functional labour markets (Casado-Díaz,
Martínez-Bernabéu, and Rowe 2017), urban areas (Daniel Arribas-Bel,
Garcia-López, and Viladecans-Marsal 2021) and various forms of
geodemographic classifications (A. D. Singleton and Spielman 2013;
Patias, Rowe, and Cavazzi 2019) . However there is the recognition that
none of the existing approaches resolve the effects of the MAUP and
recently it has been suggested that the most plausible `solution' would
be to ignore the MAUP (Wolf et al. 2020).
\subsection{Ecological Fallacy}\label{ecological-fallacy}
Ecological fallacy is an error in the interpretation of statistical data
based on aggregate information. Specifically it refers to inferences
made about the nature of specific individuals based solely on statistics
aggregated for a given group. It is about thinking that relationships
observed for groups necessarily hold for individuals. A key example is
Robinson (1950) who illustrates this problem exploring the difference
between ecological correlations and individual correlations. He looked
at the relationship between country of birth and literacy. Robinson
(1950) used the percent of foreign-born population and percent of
literate population for the 48 states in the United States in 1930. The
ecological correlation based on these data was 0.53. This suggests a
positive association between foreign birth and literacy, and could be
interpreted as foreign born individuals being more likely to be literate
than native-born individuals. Yet, the correlation based on individual
data was negative -0.11 which indicates the opposite. The main point
emerging from this example is to carefully interpret analysis based on
spatial data and avoid making inferences about individuals from these
data.
\subsection{Spatial Dependence}\label{spatial-dependence}
Spatial dependence refers to the spatial relationship of a variable's
values for a pair of locations at a certain distance apart, so that
these values are more similar (or less similar) than expected for
randomly associated pairs of observations (Anselin 1988). For example,
we could think of observed patterns of ethnic segregation in an area are
a result of spillover effects of pre-existing patterns of ethnic
segregation in neighbouring areas. Chapter~\ref{sec-chp5} will
illustrate approach to explicitly incorporate spatial dependence in
regression analysis.
\subsection{Spatial Heterogeneity}\label{spatial-heterogeneity}
Spatial heterogeneity refers to the uneven distribution of a variable's
values across space. Concentration of deprivation or unemployment across
an area are good examples of spatial heterogeneity. We illustrate
various ways to visualise, explore and measure the spatial distribution
of data in multiple chapters. We also discuss on potential modelling
approaches to capture spatial heterogeneity in Chapter~\ref{sec-chp5},
Chapter~\ref{sec-chp7} and Chapter~\ref{sec-chp10}.
\subsection{Spatial nonstationarity}\label{spatial-nonstationarity}
Spatial nonstationarity refers to variations in the relationship between
an outcome variable and a set of predictor variables across space. In a
modelling context, it relates to a situation in which a simple
``global'' model is inappropriate to explain the relationships between a
set of variables. The geographical nature of the model must be modified
to reflect local structural relationships within the data. For example,
ethinic segregation has been positively associated with employment
outcomes in some countries pointing to networks in pre-existing
communities facilitating access to the local labour market. Inversely
ethinic segregation has been negatively associated with employment
outcomes pointing to lack of integration into the broader local
community. We illustrate various modelling approaches to capture spatial
nonstationarity in Chapter~\ref{sec-chp8} and Chapter~\ref{sec-chp9}.
\bookmarksetup{startatroot}
\chapter{Data Wrangling}\label{sec-chp3}
In this chapter, we will cover the fundamentals of the concepts and
functions that you will need to know to navigate this book. We will
introduce key concepts and functions relating to what computational
notebooks are and how they work. We will also cover basic R functions
and data types, including the use of factors. Additionally, we will
offer a basic understanding of the manipulation and mapping of spatial
data frames using commonly used libraries such as \texttt{tidyverse},
\texttt{sf}, \texttt{ggplot} and \texttt{tmap}.
If you are already familiar with R, R computational notebooks and data
types, you may want to jump to Section \hyperref[sec_readdata]{Read
Data} and start from there. This section describes how to read and
manipulate data using \texttt{sf} and \texttt{tidyverse} functions,
including \texttt{mutate()}, \texttt{\%\textgreater{}\%} (known as pipe
operator), \texttt{select()}, \texttt{filter()} and specific packages
and functions how to manipulate spatial data.
The chapter is based on:
\begin{itemize}
\item
Grolemund and Wickham (2019), this book illustrates key libraries,
including tidyverse, and functions for data manipulation in R
\item
Xie, Allaire, and Grolemund (2019), excellent introduction to R
markdown!
\item
Williamson (2018), some examples from the first lecture of ENVS450 are
used to explain the various types of random variables.
\item
Lovelace, Nowosad, and Muenchow (2019), a really good book on handling
spatial data and historical background of the evolution of R packages
for spatial data analysis.
\end{itemize}
\section{Dependencies}\label{dependencies}
This chapter uses the libraries below. Ensure they are installed on your
machine\footnote{You can install package \texttt{mypackage} by running
the command \texttt{install.packages("mypackage")} on the R prompt or
through the \texttt{Tools\ -\/-\textgreater{}\ Install\ Packages...}
menu in RStudio.} before you progress.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# data manipulation, transformation and visualisation}
\FunctionTok{library}\NormalTok{(tidyverse)}
\CommentTok{\# nice tables}
\FunctionTok{library}\NormalTok{(kableExtra)}
\CommentTok{\# spatial data manipulation}
\FunctionTok{library}\NormalTok{(sf) }
\CommentTok{\# thematic mapping}
\FunctionTok{library}\NormalTok{(tmap) }
\CommentTok{\# colour palettes}
\FunctionTok{library}\NormalTok{(RColorBrewer) }
\FunctionTok{library}\NormalTok{(viridis)}
\end{Highlighting}
\end{Shaded}
\section{Introducing R}\label{introducing-r}
R is a freely available language and environment for statistical
computing and graphics which provides a wide variety of statistical and
graphical techniques. It has gained widespread use in academia and
industry. R offers a wider array of functionality than a traditional
statistics package, such as SPSS and is composed of core (base)
functionality, and is expandable through libraries hosted on
\href{https://cran.r-project.org}{The Comprehensive R Archive Network
(CRAN)}. CRAN is a network of ftp and web servers around the world that
store identical, up-to-date, versions of code and documentation for R.
Commands are sent to R using either the terminal / command line or the R
Console which is installed with R on either Windows or OS X. On Linux,
there is no equivalent of the console, however, third party solutions
exist. On your own machine, R can be installed from
\href{https://www.r-project.org/}{here}.
Normally RStudio is used to implement R coding. RStudio is an integrated
development environment (IDE) for R and provides a more user-friendly
front-end to R than the front-end provided with R.
To run R or RStudio, just double click on the R or RStudio icon.
Throughout this module, we will be using RStudio: