-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.Rmd
2344 lines (1422 loc) · 65.4 KB
/
index.Rmd
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
---
title: "Spatial analysis of public health data"
subtitle: "Point Pattern Analysis"
author: "Andy MacLachlan + Laura Sheppard"
output:
xaringan::moon_reader:
css: ["custom.css", "default", "rladies", "rladies-fonts"]
lib_dir: libs
includes:
in_header: [assets/header.html]
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
seal: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
```{r xaringan-all, echo=FALSE}
library(countdown)
library(xaringan)
library(xaringanExtra)
library(knitr)
hook_source <- knitr::knit_hooks$get('source')
knitr::knit_hooks$set(source = function(x, options) {
x <- stringr::str_replace(x, "^[[:blank:]]?([^*].+?)[[:blank:]]*#<<[[:blank:]]*$", "*\\1")
hook_source(x, options)
})
xaringanExtra::use_broadcast()
xaringanExtra::use_freezeframe()
xaringanExtra::use_scribble()
#xaringanExtra::use_slide_tone()
xaringanExtra::use_search(show_icon = TRUE)
xaringanExtra::use_freezeframe()
xaringanExtra::use_clipboard()
xaringanExtra::use_tile_view()
xaringanExtra::use_panelset()
xaringanExtra::use_editable(expires = 1)
xaringanExtra::use_fit_screen()
xaringanExtra::use_extra_styles(
hover_code_line = TRUE,
mute_unhighlighted_code = TRUE
)
```
class: center, title-slide, middle
background-image: url("img/CASA_Logo_no_text_trans_17.png")
background-size: cover
background-position: center
<style>
.title-slide .remark-slide-number {
display: none;
}
</style>
```{r load_packages, message=FALSE, warning=FALSE, include=FALSE}
library(fontawesome)
```
# Point Pattern / Spatial Autocorrelation Analysis
### 21/02/2022 (updated: `r format(Sys.time(), "%d/%m/%Y")`)
`r fa("paper-plane", fill = "#562457")`[a.maclachlan@ucl.ac.uk](mailto:a.maclachlan@ucl.ac.uk)
`r fa("twitter", fill = "#562457")`[andymaclachlan](https://twitter.com/andymaclachlan)
`r fa("github", fill = "#562457")`[andrewmaclachlan](https://github.com/andrewmaclachlan)
`r fa("location-dot", fill = "#562457")`[Centre for Advanced Spatial Analysis, UCL](https://www.ucl.ac.uk/bartlett/casa/)
<a href="https://github.com/andrewmaclachlan" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#fff; color:#151513; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1);" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
---
```{r xaringan-logo, echo=FALSE}
xaringanExtra::use_logo(
image_url = "img/casa_logo.jpg",
width = "50px",
position = xaringanExtra::css_position(top = "1em", right = "2em")
)
```
# How to use the lectures
- Slides are made with [xaringan](https://slides.yihui.org/xaringan/#1)
- `r fa("magnifying-glass")` In the bottom left there is a search tool which will search all content of presentation
- Control + F will also search
- Press enter to move to the next result
- `r fa("pencil")` In the top right let's you draw on the slides, although these aren't saved.
- Pressing the letter `o` (for overview) will allow you to see an overview of the whole presentation and go to a slide
- Alternatively just typing the slide number e.g. 10 on the website will take you to that slide
- Pressing alt+F will fit the slide to the screen, this is useful if you have resized the window and have another open - side by side.
---
class: inverse, center, middle
# Slide and content acknowledgement: [Professor Adam Dennett](https://twitter.com/adam_dennett)
---
# Outline
.pull-left[
* The importance of patterns
* Patterns of categorical point data – Point Pattern Analysis
* Quadrat Analysis
* Ripley’s K
* DBSCAN
* HDBSCAN
* Patterns of spatially referenced continuous observations
* Spatial autocorrelation
* Defining near and distant things
* Measuring spatial autocorrelation
* Moran’s I
* LISA (Local indicators of spatial association)
]
.pull-right[
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/pump.jpg')
```
.small[Broad street pump and John Snow pub. Source:[Hartford Courant](https://www.tribpub.com/gdpr/courant.com/)
]
]
???
Two halves:
* Rapid overview of point pattern analysis
* Detecting spatial patterns - where are they
* Point data (or categorical data in space - lines / polygons)
* Spatially referenced observations - where regions of a map are similar = clustering of values = spatial autocorrelation.
* Methods to detect if these patterns are there or not - it might just be use seeing them
---
class: inverse, center, middle
# Part 1: Point Pattern Analysis
---
# Questions we can ask / set
**Points**
Are these points distributed in a random way or is there some sort of pattern (uniform or clustered)?
**Spatially continuous observations (e.g. values of polygons)**
How (dis)similar are our values assigned to geographic units across geographic space
---
# The first (?) point pattern analysis
### Dr John Snow
.pull-left[
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/Jon_Snow_Season.png')
```
.small[Jon Snow. Source: [Wikipedia](https://en.wikipedia.org/wiki/Jon_Snow_(character)
]
]
--
.pull-right[
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/John_Snow.jpg')
```
.small[John Snow 1813-1858. Source:[Wikipedia](https://en.wikipedia.org/wiki/John_Snow)
]
]
???
John snow often attributed with identifying the outbreak at the broad street pump
Data was from mortality reports issued by the Registrar General Office not surveys
Snow wasn't responsible directly, but it contributed to the knowledge
Snow also didn't invent this mapping style - 1795 New York outbreak of Yellow fever - Valentine Seaman
---
# Background
.pull-left[
* In response to the Cholera outbreak in 1854
* This was the third outbreak the city had seen....
* John Snow saw a pattern from those dying of the disease ...
* a **spatial pattern**
* He was a doctor and pioneered the use of anesthesia
]
.pull-right[
Cartoon (dated 1852) showing that cholera was from social overcrowding associated with the industrial revolution as opposed to polluted water...
```{r echo=FALSE, out.width='100%', fig.align='center'}
knitr::include_graphics('img/king-cholera-wellcome.jpg')
```
.small[A court for king cholera. Source:[Science museum](https://www.sciencemuseum.org.uk/objects-and-stories/medicine/cholera-victorian-london)
]
]
---
# Famous map!
```{r echo=FALSE, out.width='55%', fig.align='center'}
knitr::include_graphics('img/cholera.png')
```
.small[Something in the water: the mythology of Snow’s map of cholera. Source:[Kenneth Field](https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/something-in-the-water-the-mythology-of-snows-map-of-cholera/)
]
---
# History of point pattern
.pull-left[
* John snow often attributed with identifying the outbreak at the broad street pump
* Data was from mortality reports **issued by the Registrar General Office not surveys**
* Snow wasn't responsible directly, but it contributed to the knowledge
* Snow also didn't invent this mapping style
* Snow didn't make the map, drawing was done by **Charles Cheffins** and probably others
* Valentine Seamen (1770-1817) did **before Snow was even born!**
]
.pull-right[
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/valentineseaman.jpg')
```
.small[Valentine Seamen ca 1800. Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
]
---
class: inverse, center, middle
## Valentine Seamen wondering if his work would be covered would be covered in a GIS class 220 years later...
---
# The problem...
.pull-left[
### Benjamin Rush
* We have Black Plague / Yellow Fever in Philadelphia (1793)
* Benjamin Rush (Founding father of USA) said it must be from foreign goods
* Believed it was contagious like COVID!
]
.pull-right[
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/YellowFeverHaulingDeadThumb.jpg')
```
.small[Philadelphia Under Siege: The Yellow Fever of 1793. Source:[ Samuel A. Gum](http://pabook2.libraries.psu.edu/palitmap/YellowFever.html)
]
]
---
# The problem...
.pull-left[
### New York Doctors
* Ships were the cause!
* But it wasn't passing from person to person
* Those who cared for these people didn't get it!
* The ships must be the cause but the people on them have developed less contagious version!
* There was another source that was from the decaying material in the ships and dock area
* Once someone was dying this also spread the disease
]
.pull-right[
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/ships.png')
```
.small[Arch Street Wharf in Philadelphia, where some of the first cases were identified. Source:[ History Channel](https://www.history.com/news/yellow-fever-outbreak-philadelphia)
]
]
---
class: inverse, center, middle
## Rush then claimed in was from a bad batch of coffee!
--
## Ok Rush?....
---
# The problem...
It is linked to ships, people, hot temperature, putrid air + water and cities!
**Valentine Seamen**
* Made a map 1794/95!!!
* Used idea of meteorological maps
```{r echo=FALSE, out.width='65%', fig.align='center'}
knitr::include_graphics('img/seamen_original.png')
```
.small[Second original map by Seamen. Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
---
# What this map means...1
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/seamen_1.png')
```
.small[Fatal cases are noted in red, non fatal cases in slate grey. “S” stands for site of contagion or effluvium (or other miasma source). Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
---
# What this map means...2
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/seamen_2.png')
```
.small[Fatal cases are noted in red, non fatal cases in slate grey. “S” stands for site of contagion or effluvium (or other miasma source). Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
---
# Interpretation
.pull-left[
* We can see why the belief was that it was coming from ships
* There were marked **waves**
* 9th September then no cases until 20th September
* Believed to be due to
* the time needed for decay from filth
* ships docking
* tidal patterns
* slips fill and empty - when empty it would exposure the disease
]
.pull-right[
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('img/seamen_3.png')
```
.small[Four Temporal Regions (Isopleths) with Isoline Boundaries, defined by clustering and “natural breaks”. Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
]
---
class: inverse, center, middle
## Everyone was wrong as it was the Mosquito
--
## This was discounted as they thought it could be flies / other pests
## Temporal nature due to breeding habbits that are related to rainfall
---
class: inverse, center, middle
## Correlation is not causation...
---
# Snow's Map (?!)
* The difference here is how Snow represented the deaths - with lines
* But did Snow even come up with this ?
* Did Cheffins make the map ?
```{r echo=FALSE, out.width='55%', fig.align='center'}
knitr::include_graphics('img/cholera.png')
```
.small[Something in the water: the mythology of Snow’s map of cholera. Source:[Kenneth Field](https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/something-in-the-water-the-mythology-of-snows-map-of-cholera/)
]
---
# Map before Snow's
```{r echo=FALSE, out.width='85%', fig.align='center'}
knitr::include_graphics('img/Coopermap.jpg')
```
.small[Deaths from cholera in Soho, London 1854 by Edmund Cooper. Source:[Kenneth Field](https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/something-in-the-water-the-mythology-of-snows-map-of-cholera/)
]
---
# Snow's other contribution...
.pull-left[
* Snow made two maps
* Most common one is 1854
* BUT the one in 1855 has the broad street pump in the right location
* AND also induces an isochrone - houses accessing the pump
* Is this the first kind of location analysis (in GIS location-allocation or accessibility)
* It might be the first instance of a **Voronoi Diagram**
]
.pull-right[
```{r echo=FALSE, out.width='100%', fig.align='center'}
knitr::include_graphics('img/Snowmap2.jpg')
```
.small[Something in the water: the mythology of Snow’s map of cholera. Source:[Kenneth Field](https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/something-in-the-water-the-mythology-of-snows-map-of-cholera/)
]
]
---
# Voronoi Diagram
* Voronoi (or Dirichlet tesselation or Thiessen polygons)
* Polygon showing the boundary of the closest point in space...
.pull-left[
```{r echo=FALSE, out.width='100%', fig.align='center'}
knitr::include_graphics('img/voroni.png')
```
.small[Voronoi diagram. Source:[Francesco Bellelli](https://towardsdatascience.com/the-fascinating-world-of-voronoi-diagrams-da8fc700fa1b)
]
]
.pull-right[
```{r echo=FALSE, out.width='85%', fig.align='center'}
knitr::include_graphics('img/voroni_nature.png')
```
.small[Voronoi in nature Source:[Francesco Bellelli](https://towardsdatascience.com/the-fascinating-world-of-voronoi-diagrams-da8fc700fa1b)
]
]
---
# Who is responsbile?
* Valentine Seamen = 1794/95
* Edmund Cooper = 1854
* John Snow / team / cartographers = 1854
.pull-left[
**Team Seamen**
```{r echo=FALSE, out.width='50%', fig.align='center'}
knitr::include_graphics('img/valentineseaman.jpg')
```
.small[Valentine Seamen ca 1800. Source:[Brian Altonen](https://brianaltonenmph.com/gis/historical-disease-maps/valentine-seaman-1804-the-black-plague-or-yellow-fever-in-new-york-city/)
]
]
.pull-right[
**Team Snow**
```{r echo=FALSE, out.width='55%', fig.align='center'}
knitr::include_graphics('img/John_Snow.jpg')
```
.small[John Snow 1813-1858. Source:[Wikipedia](https://en.wikipedia.org/wiki/John_Snow)
]
]
---
# The outcome to Snow's work
.pull-left[
* He convinced local authority to remove the handle of the broad street pump
* By that stage it was too late
* They found a **leaking sewer** that was going into the well!!
* **Go and visit the broad street pump in London**
]
.pull-right[
```{r echo=FALSE, out.width='80%', fig.align='center'}
knitr::include_graphics('img/Pump_Handle_-_John_Snow_.jpg')
```
.small[1854 Broad Street cholera outbreak. Source:[Wikipedia](https://en.wikipedia.org/wiki/John_Snow)
]
]
---
# What patterns show
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/cholera.png')
```
.small[Something in the water: the mythology of Snow’s map of cholera. Source:[Kenneth Field](https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/something-in-the-water-the-mythology-of-snows-map-of-cholera/)
]
---
# Spatial Epidemiology: Lung Cancer
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/Gatrell.png')
```
.small[Spatial Point Pattern Analysis and its Application in Geographical Epidemiology. Source:[Gatrell et al.1996](https://www.jstor.org/stable/622936?seq=1#metadata_info_tab_contents)
]
???
* Similar methods that we will use today - incidences of lung cancer relative to the physical envrionment - are they clustered and where? ...leads to why
* are the locations of lung cancer similar?
* Does the incinerator have any influence ?
---
# Quantifying Spatial Patterns
What is fixed?
.pull-left[
### Point Pattern Analysis
* Properties are fixed (e.g. binary - present or not)
* Discrete objects - present or not, binary, yes or no.
* Examples: fly tipping, stop and search, blue plaques, pharmacies
Properties fixed, but **space (location - x,y)** can vary
]
.pull-right[
### Spatial Autocorrelation
* Space (e.g. the location of the spatial units - wards, boroughs etc) is fixed
* The values of the spatial units vary
* Where the values are similar we say they exhibit Spatial Autocorrelation
Space is fixed, but **properties (values)** can vary
]
???
Properties - the location of the point is fixed - there or not, binary
Space fixed - the spatial units fixed - boundary but properties (values) vary.
---
# Examples
* Location of blue plaques in London
* Question: Are the points clustered or are they random?
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/blue_plaques.png')
```
.small[Source:[CASA0005](https://andrewmaclachlan.github.io/CASA0005repo/detecting-spatial-patterns.html#)
]
---
# Examples
* Average GCSE point score 2014 per London ward
* Question: Are the values similar between certain wards?
```{r echo=FALSE, out.width='60%', fig.align='center'}
knitr::include_graphics('img/average_GCSE.png')
```
.small[Source:[CASA0005](https://andrewmaclachlan.github.io/CASA0005repo/detecting-spatial-patterns.html#)
]
---
class: inverse, center, middle
# Now how do we calculate clustering and spatial autocorrelation...
---
# Observed vs Expected
.pull-left[
* Comparing what we observe in the real world against what we might expect is fundamental to most spatial (and other sorts of) analyses.
* If what we observe differs in some significant way from what we might expect, then there might be something interesting going on
* But how do we know what is expected?
* We should expect randomness
* Randomness conforms to known probability distributions
]
.pull-right[
* quincunx or bean machine (or Galton box) = normal distribution
```{r echo=FALSE, out.width='45%', fig.align='center'}
knitr::include_graphics('img/Galton_box.jpg')
```
.small[Source:[Wikipedia](https://en.wikipedia.org/wiki/Galton_board)
]
.small[Francis Galton coined the term eugenics and endowed UCL with his personal collection and archive along with a bequest for the country’s first professorial Chair of Eugenics. Karl Pearson was the first holder of this chair. UCL recently demaned all spaces associated with Pearson and Galton]
]
???
Living in the real world will have known probability distribution
Taking our points and comparing something random with real life distribution
If there is a difference then there is something going on...
Get the normal distribution every time - weight machine at a gym
---
# Observed vs Expected
```{r echo=FALSE, out.width='45%', fig.align='center'}
knitr::include_graphics('img/weights_normal.jpg')
```
.small[Source:[reddit](https://www.reddit.com/r/mildlyinteresting/comments/ut67my/the_weight_machine_at_my_gym_shows_a_normal/)
]
---
class: inverse, center, middle
# look familiar? - the wall BBC show
```{r echo=FALSE, out.width='100%', fig.align='center'}
knitr::include_graphics('img/thewall.jpg')
```
.small[Source:[BBC](https://www.bbc.co.uk/programmes/p07bvx36)
]
---
# Eugencis at UCL
* Eugenics "the scientifically erroneous and immoral theory of “racial improvement” and “planned breeding”
* Until recently UCL had named buildings and lecture halls after these people...
.pull-left[
**Karl Perason**
* Developed at UCL
* University's first Chair of Eugenics that was established on the request of Galton
* Pearson’s product-moment coefficient BUT just use **product-moment coefficient**
* Range from -1 to 1 to show relationship between two variables....
]
.pull-right[
**Francis Galton**
* Coined the word eugenics in 1883
* Wanted it to become a religion
* Key figure in stats but most of these were to further eugenic ideas...
.small[Source:[Natalie Ball](https://eugenicsarchive.ca/discover/tree/518c1ed54d7d6e0000000002)
]
]
---
# Point Pattern Anaysis
### The core question..
> ### Are these points distributed in a random way or is there some sort of pattern (uniform or clustered)?
.pull-left[
* The **expected random model** is known as Complete Spatial Randomness (CSR)
* A random distribution of points is said to have a Poisson distribution
* By comparing the distribution of observed points with a CSR Poisson model, we can tell if we have an interesting point distribution….
]
.pull-right[
```{r echo=FALSE, out.width='75%', fig.align='center'}
knitr::include_graphics('img/Point_pattern.png')
```
.small[Source:[Wikipedia](https://en.wikipedia.org/wiki/Point_pattern_analysis#/media/File:Point_pattern.png)
]
]
???
Compare all observations to complete spatial randomness - distribution of points that conforms to the Poisson distribution
Comparing our observations to an idealized distribution of points - is it random or not?
---
# The Poisson Distribution
.pull-left[
* Describes the probability or rate of an event happening over a fixed interval of time or space
* Where the total number of events in a fixed unit is small (e.g. Breweries in a London Borough), then the probability of getting a low rate is higher
* As number of events increases, the mean (`λ` – lambda) increases and the probability distribution changes
]
.pull-right[
```{r echo=FALSE, out.width='75%', fig.align='center'}
knitr::include_graphics('img/The Poisson Distribution.png')
```
.small[Source:[UMAS](https://www.pinterest.co.uk/pin/89368373833174553/)
]
```{r echo=FALSE, out.width='75%', fig.align='center'}
knitr::include_graphics('img/breweries.png')
```
.small[Source:[Adam Dennett](https://twitter.com/adam_dennett)
]
]
???
Poisson distribution will tell us the probability of rate of event happening over fixed interval of space
Breweries in London around 2017 - what the probability of finding a brewery is in a borough, based on the average occurrence in London
---
# The Poisson Distribution 2
<p align="center"><iframe width="560" height="315" src="https://www.youtube.com/embed/FdcFWP1nyRQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
---
# The Poisson Distribution 3
### Rules / applies when
* The events are discrete and can be counted in integers
* Events are independent of each other
* The average number of events over space (or time) is known
### Use
* It’s very useful in Point Pattern Analysis as it allows us to compare a random expected model to our observations
* Where our data **do not fit the Poisson model, then something interesting might be going on!**
* Our events might not be independent of each other – they might be clustered or dispersed and something might be causing this...
---
# Testing for CSR - Point Pattern Analysis
## Quadrat Analysis
.pull-left[
* Developed and used frequently by ecologists
* Grid of squares
* Count number of incidents (burglaries, cholera deaths, hippos etc.) in each cell – store results in a table
]
.pull-right[
```{r echo=FALSE, out.width='100%', fig.align='center'}
knitr::include_graphics('img/blue_plaques_in_harrow.png')
```
.small[Source:[CASA0005](https://andrewmaclachlan.github.io/CASA0005repo/detecting-spatial-patterns.html#)
]
]
.center[
**Compare the observed occurrences with a CSR Poisson model...**
Note, be careful with CSR and CRS]
???
* Often done at school count the occurrence in a square
---
class: inverse, center, middle
# How do we apply this to spatial data ?
---
# In code...
For point pattern analysis we need a point pattern (ppp) object...and an observation window...
```{r, eval=FALSE}
window <- as.owin(Harrow)
BluePlaquesSub.ppp <- ppp(x=BluePlaquesSub@coords[,1],
y=BluePlaquesSub@coords[,2],
window=window)
```
The we can create a grid...
```{r, eval=FALSE}
BluePlaquesSub.ppp %>%
quadratcount(.,nx = 6, ny = 6)
```
Then pull out the results...
```{r, eval=FALSE}
Qcount <- BluePlaquesSub.ppp %>%
quadratcount(.,nx = 6, ny = 6) %>%
as.data.frame() %>%
dplyr::count(Var1=Freq)%>%
dplyr::rename(Freqquadratcount=n)
```
---
# Quadrat Analysis
* The (Poisson) probability (Pr) of an event (brewery in a quadrat square) is calculated ...
ex
$$Pr= (X =k) = \frac{\lambda^{k}e^{-\lambda}}{k!}$$
where:
* $x$ is the number of occurrences
* $λ$ is the mean number of occurrences
* $e$ is a constant- 2.718
* $k!$ is the factorial of the number of occurences $((e.g. 4! = 1*2*3*4))$
* Here, remember $X=k$ - they are the same here.
---
# Plugging in the numbers
| Var1 | Freq count | Total plaques | Lambda | Probability | Expected count | Observed probability |
|------|------------|---------------|--------|-------------|----------------|----------------------|
| 0 | 12 | 0 | 1.38 | 0.3 | 7.3 | 0.4 |
| 1 | 7 | 7 | | 0.3 | 10.1 | 0.2 |
| 4 | 2 | 8 | | 0.0 | 1.1 | 0.1 |
| 7 | 1 | 7 | | 0.0 | 0.0 | 0.0 |
| | 29 | 40 | | 1.0 | 28.9 | 1.0 |
.pull-left[
* Var 1 = Number of values within the grids
* Freqquad = Number of grids with that value
* Total blue plaques = Var1*Frequency
* Lambda = Total blue plaques / total frequency
* Probability = Probability of number of plaques in quadrant ....
]
.pull-right[
$$\frac{\lambda^{k}e^{-\lambda}}{k!}$$
* In excel = `(($D$2^A2)*EXP(-$D$2)/FACT(A2))`
* Expected = Expected frequency count on the Poisson distribution (freq count * probability)
* Observed probability = Frequency count / sum of the frequency count
]
???
* Count the number in square, then work out the mean in each given square
* Compare the observation to our expectation - and chi square will tell us if significant.