generated from rstudio/bookdown-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprdm.html
556 lines (518 loc) · 82.5 KB
/
prdm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 5 Geostatistical Data Analysis | RESTful Scraping API for Real Estate data, a Spatial Bayesian modeling perspective with INLA</title>
<meta name="description" content="This is Niccolò Salvini master’s thesis project" />
<meta name="generator" content="bookdown 0.21 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 5 Geostatistical Data Analysis | RESTful Scraping API for Real Estate data, a Spatial Bayesian modeling perspective with INLA" />
<meta property="og:type" content="book" />
<meta property="og:url" content="https://niccolosalvini.github.io/Thesis/" />
<meta property="og:image" content="https://niccolosalvini.github.io/Thesis/images/logo/spatial_logo.png" />
<meta property="og:description" content="This is Niccolò Salvini master’s thesis project" />
<meta name="github-repo" content="NiccoloSalvini/thesis" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 5 Geostatistical Data Analysis | RESTful Scraping API for Real Estate data, a Spatial Bayesian modeling perspective with INLA" />
<meta name="twitter:description" content="This is Niccolò Salvini master’s thesis project" />
<meta name="twitter:image" content="https://niccolosalvini.github.io/Thesis/images/logo/spatial_logo.png" />
<meta name="author" content="Candidate: Niccolò Salvini" />
<meta name="author" content="Supervisor: PhD Marco L. Della Vedova" />
<meta name="author" content="Assistant Supervisor: PhD Vincenzo Nardelli" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="images/logo/spatial_logo.png" />
<link rel="shortcut icon" href="images/logo/spatial_logo.ico" type="image/x-icon" />
<link rel="prev" href="inla.html"/>
<link rel="next" href="exploratory.html"/>
<script src="libs/header-attrs-2.6/header-attrs.js"></script>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-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" />
<script src="libs/htmlwidgets-1.5.3/htmlwidgets.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.16/datatables.js"></script>
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.10.20/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.10.20/js/jquery.dataTables.min.js"></script>
<link href="libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet" />
<script src="libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
<link href="libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet" />
<script src="libs/selectize-0.12.0/selectize.min.js"></script>
<link href="libs/crosstalk-1.1.0.1/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.1.0.1/js/crosstalk.min.js"></script>
<script src="libs/kePrint-0.0.1/kePrint.js"></script>
<link href="libs/lightable-0.0.1/lightable.css" rel="stylesheet" />
<link href="libs/leaflet-1.3.1/leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-1.3.1/leaflet.js"></script>
<link href="libs/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
<script src="libs/Proj4Leaflet-1.0.1/proj4-compressed.js"></script>
<script src="libs/Proj4Leaflet-1.0.1/proj4leaflet.js"></script>
<link href="libs/rstudio_leaflet-1.3.1/rstudio_leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-binding-2.0.3/leaflet.js"></script>
<link href="libs/leaflet-easybutton-1.3.1/easy-button.css" rel="stylesheet" />
<script src="libs/leaflet-easybutton-1.3.1/easy-button.js"></script>
<script src="libs/leaflet-easybutton-1.3.1/EasyButton-binding.js"></script>
<link href="libs/leaflet-locationfilter2-0.1.1/locationfilter.css" rel="stylesheet" />
<script src="libs/leaflet-locationfilter2-0.1.1/locationfilter.js"></script>
<script src="libs/leaflet-locationfilter2-0.1.1/locationfilter-bindings.js"></script>
<link href="libs/ionicons-2.0.1/ionicons.min.css" rel="stylesheet" />
<link href="libs/leaflet-minimap-3.3.1/Control.MiniMap.min.css" rel="stylesheet" />
<script src="libs/leaflet-minimap-3.3.1/Control.MiniMap.min.js"></script>
<script src="libs/leaflet-minimap-3.3.1/Minimap-binding.js"></script>
<script src="libs/core-js-2.5.3/shim.min.js"></script>
<script src="libs/react-16.12.0/react.min.js"></script>
<script src="libs/react-16.12.0/react-dom.min.js"></script>
<script src="libs/reactwidget-1.0.0/react-tools.js"></script>
<script src="libs/reactable-binding-0.2.3/reactable.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-171723874-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-171723874-1');
</script>
<script src="js/1book.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="css/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 class="toc-logo"><a href="./"><img src="images/logo/spatial_logo.png"></a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Preliminary Content</a>
<ul>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#acknowledgements"><i class="fa fa-check"></i>Acknowledgements</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#dedication"><i class="fa fa-check"></i>Dedication</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#colophon"><i class="fa fa-check"></i>Colophon</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> Introduction</a></li>
<li class="chapter" data-level="2" data-path="scraping.html"><a href="scraping.html"><i class="fa fa-check"></i><b>2</b> Web Scraping</a>
<ul>
<li class="chapter" data-level="2.1" data-path="scraping.html"><a href="scraping.html#reverse"><i class="fa fa-check"></i><b>2.1</b> A Gentle Introduction on Web Scraping</a></li>
<li class="chapter" data-level="2.2" data-path="scraping.html"><a href="scraping.html#anatomy-of-a-url-and-reverse-engineering"><i class="fa fa-check"></i><b>2.2</b> Anatomy of a url and reverse engineering</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="scraping.html"><a href="scraping.html#scraping-with-rvest"><i class="fa fa-check"></i><b>2.2.1</b> Scraping with <code id="ContentArchitecture">rvest</code></a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="scraping.html"><a href="scraping.html#ProperScraping"><i class="fa fa-check"></i><b>2.3</b> Searching Technique for Scraping</a></li>
<li class="chapter" data-level="2.4" data-path="scraping.html"><a href="scraping.html#best-practices"><i class="fa fa-check"></i><b>2.4</b> Scraping Best Practices and Security provisions</a></li>
<li class="chapter" data-level="2.5" data-path="scraping.html"><a href="scraping.html#HTTPmethod"><i class="fa fa-check"></i><b>2.5</b> HTTP overview</a>
<ul>
<li class="chapter" data-level="2.5.1" data-path="scraping.html"><a href="scraping.html#spoofing"><i class="fa fa-check"></i><b>2.5.1</b> User Agent and further Identification Headers Spoofing</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="scraping.html"><a href="scraping.html#possibly"><i class="fa fa-check"></i><b>2.6</b> Dealing with failure</a></li>
<li class="chapter" data-level="2.7" data-path="scraping.html"><a href="scraping.html#parallelscraping"><i class="fa fa-check"></i><b>2.7</b> Parallel Scraping</a>
<ul>
<li class="chapter" data-level="2.7.1" data-path="scraping.html"><a href="scraping.html#parallel-furrrfuture"><i class="fa fa-check"></i><b>2.7.1</b> Parallel furrr+future</a></li>
<li class="chapter" data-level="2.7.2" data-path="scraping.html"><a href="scraping.html#parallel-foreachdofuture"><i class="fa fa-check"></i><b>2.7.2</b> Parallel foreach+doFuture</a></li>
</ul></li>
<li class="chapter" data-level="2.8" data-path="scraping.html"><a href="scraping.html#legal"><i class="fa fa-check"></i><b>2.8</b> Legal Profiles</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Infrastructure.html"><a href="Infrastructure.html"><i class="fa fa-check"></i><b>3</b> API Technology Stack</a>
<ul>
<li class="chapter" data-level="3.1" data-path="Infrastructure.html"><a href="Infrastructure.html#restful-api"><i class="fa fa-check"></i><b>3.1</b> RESTful API</a>
<ul>
<li class="chapter" data-level="3.1.1" data-path="Infrastructure.html"><a href="Infrastructure.html#plumberapi"><i class="fa fa-check"></i><b>3.1.1</b> Plumber HTTP API</a></li>
<li class="chapter" data-level="3.1.2" data-path="Infrastructure.html"><a href="Infrastructure.html#sanitize"><i class="fa fa-check"></i><b>3.1.2</b> Sanitization</a></li>
<li class="chapter" data-level="3.1.3" data-path="Infrastructure.html"><a href="Infrastructure.html#DoS"><i class="fa fa-check"></i><b>3.1.3</b> Denial Of Service (DoS)</a></li>
<li class="chapter" data-level="3.1.4" data-path="Infrastructure.html"><a href="Infrastructure.html#logging"><i class="fa fa-check"></i><b>3.1.4</b> Logging</a></li>
<li class="chapter" data-level="3.1.5" data-path="Infrastructure.html"><a href="Infrastructure.html#docs"><i class="fa fa-check"></i><b>3.1.5</b> RESTful API docs</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="Infrastructure.html"><a href="Infrastructure.html#docker"><i class="fa fa-check"></i><b>3.2</b> Docker</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="Infrastructure.html"><a href="Infrastructure.html#dockerfile"><i class="fa fa-check"></i><b>3.2.1</b> REST-API container</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="Infrastructure.html"><a href="Infrastructure.html#nginx"><i class="fa fa-check"></i><b>3.3</b> NGINX reverse Proxy Server and Authorization</a></li>
<li class="chapter" data-level="3.4" data-path="Infrastructure.html"><a href="Infrastructure.html#docker-compose"><i class="fa fa-check"></i><b>3.4</b> Docker-Compose</a></li>
<li class="chapter" data-level="3.5" data-path="Infrastructure.html"><a href="Infrastructure.html#HTTPS"><i class="fa fa-check"></i><b>3.5</b> HTTPS(ecure) and SSL certificates</a></li>
<li class="chapter" data-level="3.6" data-path="Infrastructure.html"><a href="Infrastructure.html#aws"><i class="fa fa-check"></i><b>3.6</b> AWS EC2 instance</a></li>
<li class="chapter" data-level="3.7" data-path="Infrastructure.html"><a href="Infrastructure.html#sdwf"><i class="fa fa-check"></i><b>3.7</b> Software CI/CD Workflow</a></li>
<li class="chapter" data-level="3.8" data-path="Infrastructure.html"><a href="Infrastructure.html#further-sf-integrations"><i class="fa fa-check"></i><b>3.8</b> Further SF Integrations</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="inla.html"><a href="inla.html"><i class="fa fa-check"></i><b>4</b> INLA</a>
<ul>
<li class="chapter" data-level="4.1" data-path="inla.html"><a href="inla.html#LGM"><i class="fa fa-check"></i><b>4.1</b> The class of Latent Gaussian Models (LGM)</a></li>
<li class="chapter" data-level="4.2" data-path="inla.html"><a href="inla.html#gmrf"><i class="fa fa-check"></i><b>4.2</b> Gaussian Markov Random Field (GMRF)</a></li>
<li class="chapter" data-level="4.3" data-path="inla.html"><a href="inla.html#approx"><i class="fa fa-check"></i><b>4.3</b> INLA Laplace Approximations</a></li>
<li class="chapter" data-level="4.4" data-path="inla.html"><a href="inla.html#rinla"><i class="fa fa-check"></i><b>4.4</b> R-INLA package</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="prdm.html"><a href="prdm.html"><i class="fa fa-check"></i><b>5</b> Geostatistical Data Analysis</a>
<ul>
<li class="chapter" data-level="5.1" data-path="prdm.html"><a href="prdm.html#GP"><i class="fa fa-check"></i><b>5.1</b> Gaussian Process (GP)</a></li>
<li class="chapter" data-level="5.2" data-path="prdm.html"><a href="prdm.html#spdeapproach"><i class="fa fa-check"></i><b>5.2</b> The Stochastic Partial Differential Equation (SPDE) approach</a></li>
<li class="chapter" data-level="5.3" data-path="prdm.html"><a href="prdm.html#hedonic-rental-price-models"><i class="fa fa-check"></i><b>5.3</b> Hedonic (rental) Price Models</a></li>
<li class="chapter" data-level="5.4" data-path="prdm.html"><a href="prdm.html#criticism"><i class="fa fa-check"></i><b>5.4</b> Model Criticism</a>
<ul>
<li class="chapter" data-level="5.4.1" data-path="prdm.html"><a href="prdm.html#predbase"><i class="fa fa-check"></i><b>5.4.1</b> Methods based on the predictive distribution</a></li>
<li class="chapter" data-level="5.4.2" data-path="prdm.html"><a href="prdm.html#devbased"><i class="fa fa-check"></i><b>5.4.2</b> Deviance-based Criteria</a></li>
</ul></li>
<li class="chapter" data-level="5.5" data-path="prdm.html"><a href="prdm.html#priorsspec"><i class="fa fa-check"></i><b>5.5</b> Penalized Complexity Priors</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="exploratory.html"><a href="exploratory.html"><i class="fa fa-check"></i><b>6</b> Exploratory Analysis</a>
<ul>
<li class="chapter" data-level="6.1" data-path="exploratory.html"><a href="exploratory.html#prep"><i class="fa fa-check"></i><b>6.1</b> Preprocessing and Feature Engineering</a></li>
<li class="chapter" data-level="6.2" data-path="exploratory.html"><a href="exploratory.html#spatassess"><i class="fa fa-check"></i><b>6.2</b> Spatial Dependece Assessement</a></li>
<li class="chapter" data-level="6.3" data-path="exploratory.html"><a href="exploratory.html#factor-counts"><i class="fa fa-check"></i><b>6.3</b> Factor Counts</a></li>
<li class="chapter" data-level="6.4" data-path="exploratory.html"><a href="exploratory.html#mvp"><i class="fa fa-check"></i><b>6.4</b> Assessing the most valuable properties</a></li>
<li class="chapter" data-level="6.5" data-path="exploratory.html"><a href="exploratory.html#assessing-relevant-predictors"><i class="fa fa-check"></i><b>6.5</b> Assessing relevant predictors</a></li>
<li class="chapter" data-level="6.6" data-path="exploratory.html"><a href="exploratory.html#missassimp"><i class="fa fa-check"></i><b>6.6</b> Missing Assessement and Imputation</a>
<ul>
<li class="chapter" data-level="6.6.1" data-path="exploratory.html"><a href="exploratory.html#missing-assessement"><i class="fa fa-check"></i><b>6.6.1</b> Missing Assessement</a></li>
<li class="chapter" data-level="6.6.2" data-path="exploratory.html"><a href="exploratory.html#missing-imputation"><i class="fa fa-check"></i><b>6.6.2</b> Missing Imputation</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="modelspec.html"><a href="modelspec.html"><i class="fa fa-check"></i><b>7</b> Model Selection & Fitting</a>
<ul>
<li class="chapter" data-level="7.1" data-path="modelspec.html"><a href="modelspec.html#modelspecandmesh"><i class="fa fa-check"></i><b>7.1</b> Model Specification & Mesh Assessement</a></li>
<li class="chapter" data-level="7.2" data-path="modelspec.html"><a href="modelspec.html#spdemodeol"><i class="fa fa-check"></i><b>7.2</b> Building the SPDE object</a></li>
<li class="chapter" data-level="7.3" data-path="modelspec.html"><a href="modelspec.html#model-selection"><i class="fa fa-check"></i><b>7.3</b> Model Selection</a></li>
<li class="chapter" data-level="7.4" data-path="modelspec.html"><a href="modelspec.html#fit"><i class="fa fa-check"></i><b>7.4</b> Parameter Estimation and Results</a></li>
<li class="chapter" data-level="7.5" data-path="modelspec.html"><a href="modelspec.html#plot-gmrf"><i class="fa fa-check"></i><b>7.5</b> Plot GMRF</a></li>
<li class="chapter" data-level="7.6" data-path="modelspec.html"><a href="modelspec.html#spatial-model-criticism"><i class="fa fa-check"></i><b>7.6</b> Spatial Model Criticism</a></li>
<li class="chapter" data-level="7.7" data-path="modelspec.html"><a href="modelspec.html#spatial-prediction-on-a-grid"><i class="fa fa-check"></i><b>7.7</b> Spatial Prediction on a Grid</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="conclusions.html"><a href="conclusions.html"><i class="fa fa-check"></i><b>8</b> Conclusions</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
<ul>
<li class="chapter" data-level="8.1" data-path="appendix.html"><a href="appendix.html#triangular"><i class="fa fa-check"></i><b>8.1</b> SPDE and Triangulation</a></li>
<li class="chapter" data-level="8.2" data-path="appendix.html"><a href="appendix.html#laplaceapprox"><i class="fa fa-check"></i><b>8.2</b> Laplace Approximation</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
<li class="divider"></li>
<li><a href="https://github.com/NiccoloSalvini/tesi-prova" target="blank"> See Github Repository</a></li>
<li><a href="https://niccolosalvini.netlify.app/">About The Author</a></li>
<li><a Proudly 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="./">RESTful Scraping API for Real Estate data, a Spatial Bayesian modeling perspective with INLA</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="prdm" class="section level1" number="5">
<h1><span class="header-section-number">Chapter 5</span> Geostatistical Data Analysis</h1>
<p>Geostatistical or equivalently point reference data are a collection of samples indexed by coordinates pertaining to a spatially continuous surface <span class="citation">(<a href="references.html#ref-Moraga2019" role="doc-biblioref">Moraga 2019</a>)</span>. Coordinates might be in the form of Latitude and Longitude or Eastings and Northings, moreover they can be also unprojected with respect to a Coordinate Reference Systems (CRS e.g. lat and log), or projected (e.g. East. and North.). Data as such can monitor a vast range of phenomena, e.g. accidental fisheries bycatch for endangered species <span class="citation">(<a href="references.html#ref-CosandeyGodin2015" role="doc-biblioref">Cosandey-Godin et al. 2015</a>)</span>, COVID19 severity and case fatality rates in Spain <span class="citation">(<a href="references.html#ref-Moragacovid2020" role="doc-biblioref">Moraga et al. 2020</a>)</span>, PM10 pollution concentration in a North-Italian region Piemonte <span class="citation">(<a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al. 2012</a>)</span>. Moreover a large geostatistical application takes place on Real Estate e.g. Boston house prices lattice data <span class="citation">(<a href="#ref-mass" role="doc-biblioref"><strong>mass?</strong></a>)</span> are ingested by several spatial models <span class="citation">(<a href="references.html#ref-rubiorealestate" role="doc-biblioref">Bivand, Gómez Rubio, and Rue 2015</a>)</span>, or spatio-temporal modeling for apartment transaction prices in Corsica (FR) <span class="citation">(<a href="references.html#ref-Ling" role="doc-biblioref">Ling 2019</a>)</span>. All the examples taken before have implied inla and might have documented a spatial nature of data according to which closer observations were displaying similar values. This phenomenon is named spatial autocorrelation. Spatial autocorrelation conceptually stems from geographer Waldo Tobler whose famous quote, known as first law of geography, inspires geostatisticians:</p>
<blockquote>
<p>“Everything is related to everything else, but near things are more related than distant things”</p>
<footer>
— Waldo R. Tobler
</footer>
</blockquote>
<p>Spatial data can be partitioned into three main types, even tough they all fall under the umbrella of inla algorithm, indeed each employs context specific tools.</p>
<ul>
<li>Areal Data</li>
<li><strong>Point Referenced Data</strong></li>
<li>Point Pattern Data</li>
</ul>
<div class="figure"><span id="fig:prdmap"></span>
<img src="images/map.png" alt="" />
<p class="caption">Figure 5.1: Point Referenced Data map plot (<code>Leaflet</code> <span class="citation"><a href="references.html#ref-leaflet" role="doc-biblioref">Cheng, Karambelkar, and Xie</a> (<a href="references.html#ref-leaflet" role="doc-biblioref">2019</a>)</span>) of a RESTful API call on Milan Rental Real Estate 20-11-2019, Author’s Source</p>
</div>
<!-- RESTful scraping API in <a href="Infrastructure.html#Infrastructure">3</a> allows to grab data containing point referenced coordinates as in fig. <a href="prdm.html#fig:prdmap">5.1</a> by simply specifying the city or the zone desired according to the syntax in <a href="Infrastructure.html#docs">3.1.5</a>. Moreover it is flexible enough to specify the number of observation, this may land a hand when the practitioner is dealing with complex models that are not able to ingest large amounts of data, or alternatively when the analyst's interest resides in only certain type of house characteristics. -->
<p>In this chapter Gaussian Processes are seen as the continuous surface from which point referenced data are the partial realization. At first they are defined, then aer constrained to the properties of Stationarity and Isotropy. Furthermore they are considered with a suitable covariance function, i.e. Matèrn that uncovers convenient properties. These properties and the reason why Matérn is selected as candidate relies, besides its inner flexibility, on the fact that GP whose covariance function is Matérn are able to determine a GMRF <a href="inla.html#gmrf">4.2</a> representation of the process through the Stochastic Partial Differential Equations (SPDE) approach <span class="citation">(<a href="references.html#ref-Lindgren2011" role="doc-biblioref">Lindgren, Rue, and Lindström 2011</a>)</span>. The main benefit proceeding from a GP to a GMRF arises from the good computational properties that the latter appreciate enabling to wrap up modeling around INLA and consequently benefiting from its speed. Hedonic Price Models brings to the present analysis the theoretical foundation according to which covariates are added to the model. Then model criticism in the context of INLA is reviewed introducing two methodologies to assess model suitability based on predictive posterior distribution and deviance. In the end the prior choice falls on penalized complexity priors <span class="citation">(<a href="references.html#ref-simpson2017" role="doc-biblioref">Simpson et al. 2017</a>)</span> which constitutes a set of effective guidelines to choose priors that are compatible and natively implemented in INLA.</p>
<div id="GP" class="section level2" number="5.1">
<h2><span class="header-section-number">5.1</span> Gaussian Process (GP)</h2>
<p>Geostatistical data are defined as realizations of a stochastic process indexed by space.</p>
<p><span class="math display">\[
Y(s) \equiv\{y(s), s \in \mathscr{D}\}
\]</span>
where <span class="math inline">\(\mathscr{D}\)</span> is a (fixed) subset of <span class="math inline">\(\mathbb{R}^{d}\)</span> (in the present work <em>Latitude</em> and <em>Longitude</em>, i.e. <span class="math inline">\(d=2\)</span>).
The actual data can be then represented by a collection of observations <span class="math inline">\(\boldsymbol{\mathbf{y}}=\left\{y\left(s_{1}\right), \ldots, y\left(s_{n}\right)\right\}\)</span> (recall notation from previous chapter <a href="inla.html#LGM">4.1</a>) where the set <span class="math inline">\(\left(s_{1}, \ldots, s_{n}\right)\)</span> points to the spatial location where data has been observed. For example, following <span class="citation"><a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al.</a> (<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span>, let us assume to have collection of samples from air pollutant measurements obtained by observing a set of monitoring stations. Then The stochastic process <span class="math inline">\(Y(s)\)</span> is monitored in a fixed set of spatial indexes corresponding to the station locations (upword arrows left in figure <a href="prdm.html#fig:prdproc">5.2</a>). This information is essential to interpolate points and build a spatially continuous surface (right panel in figure <a href="prdm.html#fig:prdproc">5.2</a>) over the y-studied variable domain in order to predict the phenomenon at locations not yet observed <span class="citation">(<a href="references.html#ref-LecturePaci" role="doc-biblioref">Paci 2020</a>)</span>. Note that notation such as <span class="math inline">\(Y(s_i)\)</span> from now on will be discarded in favor of the subscript for the correspondent observation indexes i.e. <span class="math inline">\(Y_i\)</span>.</p>
<div class="figure"><span id="fig:prdproc"></span>
<img src="images/prdprocess.png" alt="" />
<p class="caption">Figure 5.2: Stockton data, Left: Spatial drop line scatterplot projected into the <span class="math inline">\(3^{rd}\)</span> dim <span class="math inline">\(\log(Price)\)</span>, Right: its three-dimensional surface , source <span class="citation"><a href="references.html#ref-Blangiardo-Cameletti" role="doc-biblioref">Michela Blangiardo Marta; Cameletti</a> (<a href="references.html#ref-Blangiardo-Cameletti" role="doc-biblioref">2015</a>)</span></p>
</div>
<p>The first step in defining a spatial model within INLA is to impose a LGM hierarchical structure which requires at first to identify a probability distribution function for the observed data <span class="math inline">\(\boldsymbol{\mathbf{y}}\)</span>, i.e. higher level. The most common choice is to draw distributions from the <em>Exponential family</em>, indexed by a set of parameters <span class="math inline">\(\boldsymbol\theta\)</span> as in <a href="inla.html#LGM">4.1</a>, accounting for the spatial correlation. In the case of geostatistical data, the model parameters <span class="math inline">\(\boldsymbol\theta\)</span>, following notation imposed in chapter <a href="inla.html#inla">4</a> are defined as a latent Gaussian Process (GP). Then a formal definition of GP is given,</p>
<div class="definition">
<span id="def:GP" class="definition"><strong>Definition 5.1 (GP definition) </strong></span>A collection of <span class="math inline">\(n\)</span> random variables, such as <span class="math inline">\(Y(s_{1}), Y(s_{2}) , \ldots, Y(s_{n})\)</span> that are <em>valid</em> and <em>finite</em> stochastic processes are said to be a <strong>GP</strong> if for any set of spatial index <span class="math inline">\(n\)</span> and for each set of corresponding locations <span class="math inline">\(\left\{y\left(s_{1}\right), \ldots, y\left(s_{n}\right)\right\}\)</span> follows a <em>Multivariate Gaussian</em> distribution with mean <span class="math inline">\(\boldsymbol{\mu}=\left\{\mu\left(s_{1}\right), \ldots, \mu\left(s_{n}\right)\right\}\)</span> and covariance matrix <span class="math inline">\(\mathbf{Q}^{-1}_{i,j}, \forall i \neq j\)</span> defined then by a covariance function <span class="math inline">\(\mathscr{\cdot, \cdot}\)</span> i.e.
</div>
<p>The latent GP are in function of some hyper-parameters <span class="math inline">\(\boldsymbol\psi\)</span> and their respective prior <span class="math inline">\(\pi(\boldsymbol\psi)\)</span>. Moreover a GP is completely characterized by a mean <span class="math inline">\(\boldsymbol{\mu}=\left(\mu_{1}, \ldots, \mu_{n}\right)^{\prime}\)</span> and a spatially structured covariance matrix <span class="math inline">\(\boldsymbol{Q^{-1}}\)</span>, whose generic element is <span class="math inline">\(\boldsymbol{Q^{-1}}_{i j}=\operatorname{Cov}(\theta_{i}, \theta_{j})=\sigma^2_{\mathscr{\boldsymbol{\mathbf{y}}}} \mathscr{C}(\Delta_{i j})\)</span>, where <span class="math inline">\(\sigma_{\mathscr{\boldsymbol{\mathbf{\xi}}}}^{2}\)</span> is the variance component of the process and for <span class="math inline">\(i, j = 1, \ldots, n\)</span>. <span class="math inline">\(\mathscr{C}\left( \cdot, \cdot \right)\)</span> function generally ensures that all the values that are close together in input space will produce output values that are close together, by inheriting the <em>validity</em> and <em>positive definitness</em> characteristics from the GP. The spatial stochastic process commonly is assumed to fulfill two important properties: <strong>stationary</strong>, <strong>Isotropy</strong> (even tough both of the two can be relaxed). A process is said <strong>stationary</strong> i.e. weak stationary, if process values at any two locations can be summarized by a covariance function <span class="math inline">\(\mathscr{C(\Delta_{i j})}\)</span> depending solely on the distance. In other words it is invariant under <em>translation</em> <span class="citation">(<a href="references.html#ref-Krainski-Rubio" role="doc-biblioref">E. T. Krainski 2019</a>)</span>. A process is said <strong>Isotropical</strong> if the covariance function depends only on the between-points distance <span class="math inline">\(\Delta_{i j}=\left\|s_{i}-s_{j}\right\|\)</span> (in this context <em>Euclidean</em>), so it is invariant under <em>rotation</em> <span class="citation">(<a href="references.html#ref-Krainski-Rubio" role="doc-biblioref">2019</a>)</span>. A further way of seeing this property is that Isotropy causes to stochastic processes concentric decaying contours <span class="citation">(<a href="references.html#ref-LecturePaci" role="doc-biblioref">Paci 2020</a>)</span>, green in fig. <a href="prdm.html#fig:isoovsanis">5.3</a>, meaning the vanishing of spatial dependence <span class="citation">(<a href="references.html#ref-Blangiardo-Cameletti" role="doc-biblioref">Michela Blangiardo Marta; Cameletti 2015</a>)</span>, and so for covariance values.</p>
<div class="figure"><span id="fig:isoovsanis"></span>
<img src="images/isotropyVSanisotropy.png" alt="" />
<p class="caption">Figure 5.3: Left: anisotropical concentric decaying contours, Right: isotropical concentric decaying contours , source <span class="citation"><a href="references.html#ref-blanchetscalliet" role="doc-biblioref">Blanchet-Scalliet et al.</a> (<a href="references.html#ref-blanchetscalliet" role="doc-biblioref">2019</a>)</span></p>
</div>
<p>In spatial statistics the isotropical assumption is very frequent despite being restrictive for describing the rich variety of interactions that can characterize spatial processes. Anyway assuming the property it offers a wide range of underlying functions that can model spatial dependence for which three are the most common ones <span class="citation">(<a href="references.html#ref-Krainski2018" role="doc-biblioref">E. Krainski et al. 2018</a>)</span></p>
<p><span class="math display">\[
\begin{aligned}
&\text { Exponential } \quad \mathscr{C}(\Delta_{i j})=\left\{\begin{array}{cl}
\tau^{2}_{\mathscr{C}}+\sigma^{2}_{\mathscr{C}} & \text { if } \Delta_{i j}=0 \\
\sigma^{2}_{\mathscr{C}} \exp (-\phi_{\mathscr{C}} \Delta_{i j}) & \text { if } \Delta_{i j}>0
\end{array}\right.\\
&\text { Gaussian } \quad \mathscr{C}(\Delta_{i j})=\left\{\begin{array}{cl}
\tau^{2}_{\mathscr{C}}+\sigma^{2}_{\mathscr{C}} & \text { if } \Delta_{i j}=0 \\
\sigma^{2}_{\mathscr{C}} \exp \left(-\phi^{2}_{\mathscr{C}} \Delta_{i j}^{2}\right) & \text { if } \Delta_{i j}>0
\end{array}\right. \\
&\text { Matérn } \quad \mathscr{C}(\Delta_{i j})=\left\{\begin{array}{cl}
\tau^{2}_{\mathscr{C}}+\sigma^{2}_{\mathscr{C}} & \text { if } \Delta_{i j}=0 \\
\frac{\sigma^{2}_{\mathscr{C}}}{\Gamma(\nu) 2^{\nu-1}}(\phi_{\mathscr{C}} \Delta_{i j})^{\nu} K_{\nu}(\phi_{\mathscr{C}} \Delta_{i j}) & \text { if } \Delta_{i j}>0
\end{array}\right.
\end{aligned}
\]</span></p>
<p>where all the parameters above are special quantities derived from the emphirical variogram. <span class="math inline">\(\sigma^2\)</span>, <span class="math inline">\(\tau^2\)</span>, <span class="math inline">\(\phi^2\)</span>, and are respectively the <em>range</em>, the distance at which correlation vanishes, the <em>nugget</em>, i.e. the non spatial variance and the <em>partial sill</em>, i.e. the spatial effect variance <span class="citation">(<a href="references.html#ref-LecturePaci" role="doc-biblioref">Paci 2020</a>)</span>. In particular the focus is on the <em>Matérn</em> – as it is required by the SPDE approach in section <a href="prdm.html#spdeapproach">5.2</a> – and this should not be intended as a restriction. In fact, as long described in <span class="citation"><a href="references.html#ref-gneiting2006geostatistical" role="doc-biblioref">Gneiting, Genton, and Guttorp</a> (<a href="references.html#ref-gneiting2006geostatistical" role="doc-biblioref">2006</a>)</span>, the Matèrn family is a very flexible class. Matérn is tuned mainly by two hyper-parameters, a scaling one <span class="math inline">\(\phi>0\)</span>, usually set equal to the range of the spatial process <span class="math inline">\(\sigma^{2}_{var}\)</span> i.e. the distance at which the spatial dependence becomes negligible, by the empirically derived relation <span class="math inline">\(r =\frac{\sqrt{8 \lambda}}{\kappa}\)</span>), and a smoothing one <span class="math inline">\(\nu>0\)</span> usually kept fixed. An <em>isotropical</em> and <em>stationary</em> Matérn covariance expression by isolating the variance of the spatial process <span class="math inline">\(\sigma_{\mathscr{\boldsymbol{\mathbf{\xi}}}}^{2}\)</span> is:</p>
<p><span class="math display">\[
\begin{aligned}
\text { Matérn } \quad \mathscr{C}( \Delta_{i j})= \sigma_{\mathscr{\boldsymbol{\mathbf{\xi}}}}^{2} \left\{\begin{array}{cl}
\tau^{2}_{\mathscr{C}} & \text { if } \Delta_{i j}=0 \\
\frac{1}{\Gamma(\nu) 2^{\nu-1}}\left(\phi \Delta_{i j}\right)^{\nu} K_{\nu}\left(\phi \Delta_{i j}\right)& \text { if } \Delta_{i j}>0
\end{array}\right.
\end{aligned}
\]</span></p>
<p><span class="math inline">\(\Gamma(\nu)\)</span> is a Gamma function depending on <span class="math inline">\(\nu\)</span> values and <span class="math inline">\(K_{\nu}(\cdot)\)</span> is a modified Bessel function of second kind <span class="citation">(<a href="references.html#ref-yaşar2016unified" role="doc-biblioref">Yaşar and Özarslan 2016</a>)</span>. The scaling parameter <span class="math inline">\(\phi\)</span> in figure <a href="prdm.html#fig:matern">5.4</a> takes 4 different values showing the flexibility of Matérn to relate different distances according to varying parameters, while <span class="math inline">\(\nu\)</span> is kept to the value of <span class="math inline">\(.5\)</span> and addresses the GP degree of smoothness. Looking at the functions in figure <a href="prdm.html#fig:matern">5.4</a> and their interception with horizontal red line, when <span class="math inline">\(\phi = 1\)</span>, it smoothly falls towards 0 covariance and spatial dependece decays at <span class="math inline">\(\approx 2.3\)</span>. When <span class="math inline">\(\phi = 1/2\)</span> it becomes the exponential covariance function and rapidly pushes covariance to 0, When <span class="math inline">\(\phi = 3/2\)</span> it uncovers a convenient closed form <span class="citation">(<a href="references.html#ref-LecturePaci" role="doc-biblioref">Paci 2020</a>)</span> for which spatial dependence vanishes at <span class="math inline">\(\approx 3.8\)</span>. When <span class="math inline">\(\phi \approx \infty\)</span>, (here <span class="math inline">\(\phi = 80\)</span> for graphics reasons), it becomes Gaussian covariance function. In the the case shown in section <a href="prdm.html#spdeapproach">5.2</a> <span class="math inline">\(\sigma_{\mathscr{C}}^{2}\)</span> the range, for any <span class="math inline">\(\phi\)</span>, is set equal to the distance at which dependence vanishes below .1, which is actually what the red line points out.</p>
<!-- ![Matérn function with 4 different values of $\nu$ (upper right legend), kept $\phi$ fixed, author's source](images/matern.png) -->
<div class="figure" style="text-align: center"><span id="fig:matern"></span>
<img src="05-prd_modelling_files/figure-html/matern-1.png" alt="Matérn covariance function for 4 different phi values and fixed nu = .5, dashed red horizontal line when covariance is .1" width="672" />
<p class="caption">
Figure 5.4: Matérn covariance function for 4 different phi values and fixed nu = .5, dashed red horizontal line when covariance is .1
</p>
</div>
<p>In the end summarizing the result obtained (abuse of notation with <span class="math inline">\((s)\)</span> to make it clear that is a spatial process) in chapter <a href="inla.html#inla">4</a> with what it has been seen so far, the Gaussian process <span class="math inline">\(y(s)\)</span> assumes the following measurement equation, where <span class="math inline">\(\xi_{i}\)</span> is the latent field, <span class="math inline">\(\varepsilon_{t} \sim N\left(\mathbf{0}, \sigma_{\varepsilon}^{2} I_{d}\right)\)</span> is the white noise error and <span class="math inline">\(I_{d}\)</span> is an identity matrix and <span class="math inline">\(\xi(\boldsymbol{s})\sim N\left(\mathbf{0}, \boldsymbol{Q^{-1}}=\sigma_{\xi}^{2} \mathscr{C}( \Delta_{i j})\right)\)</span>.</p>
<p><span class="math display">\[
y(s)=\boldsymbol{z}(\boldsymbol{s}) \boldsymbol{\beta}+\xi(\boldsymbol{s})+\varepsilon(\boldsymbol{s})
\]</span></p>
</div>
<div id="spdeapproach" class="section level2" number="5.2">
<h2><span class="header-section-number">5.2</span> The Stochastic Partial Differential Equation (SPDE) approach</h2>
<p>Locations in the spatial setting are considered as realizations of a stationary, isotropical unobserved GP to be estimated (<a href="prdm.html#GP">5.1</a>). Before approaching the problem with SPDE, GPs were treated as multivariate Gaussian densities and Cholesky factorizations were applied on the covariance matrices and then fitted with likelihood <span class="citation">(<a href="references.html#ref-LecturePaci" role="doc-biblioref">Paci 2020</a>)</span>. Covariance matrices in the context of spatial and spatio-temporal models <span class="citation">(<a href="references.html#ref-PACI2017149" role="doc-biblioref">Paci et al. 2017</a>; <a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al. 2012</a>)</span> are <span class="math inline">\(n \times n\)</span> dimension matrices defined by the number of observations at each single point location (at each time stamp in spatio-temporal) <span class="citation">(<a href="references.html#ref-BLANGIARDO201339" role="doc-biblioref">Marta Blangiardo et al. 2013</a>)</span>. Covariance matrix as such are very dense and they were scaling with the order of <span class="math inline">\(\mathcal{O}\left(n^{3}\right)\)</span> <span class="citation">(<a href="references.html#ref-Banerjee-Gelfand" role="doc-biblioref">Banerjee, Carlin, and Gelfand 2014</a>)</span>. Problem were linked to the computational costs needed for linear algebra operations for model fitting and spatial interpolation as well as prediction <span class="citation">(<a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al. 2012</a>)</span>, having led to obvious <em>big-n</em> problem. The breakthrough came with <span class="citation"><a href="references.html#ref-Lindgren2011" role="doc-biblioref">Lindgren, Rue, and Lindström</a> (<a href="references.html#ref-Lindgren2011" role="doc-biblioref">2011</a>)</span> that proves that a stationary, isotropical (can be both relaxed at the cost of different settings) GP with Matérn covariance can be represented as a GMRF using SPDE solutions by Finite Element Method <span class="citation">(<a href="references.html#ref-Krainski-Rubio" role="doc-biblioref">E. T. Krainski 2019</a>)</span>. In other words given a GP whose covariance matrix is <span class="math inline">\(\boldsymbol{Q^{-1}}\)</span>, SPDE can provide a method to approximate <span class="math inline">\(\boldsymbol{Q^{-1}}\)</span> without the previous computational constraints. As a matter of fact SPDE are equations whose solutions are GPs with a chosen covariance function focused on satisfying the relationship SPDE specifies <span class="citation">(<a href="references.html#ref-Krainski-Rubio" role="doc-biblioref">2019</a>)</span>. Benefits are many but the most important is that the representation of the GP through a GMRF provides a sparse representation of the spatial effect through a sparse precision matrix <span class="math inline">\(\boldsymbol{Q}\)</span> . Sparse matrices enable convenient inner computation properties of GMRF <a href="inla.html#approx">4.3</a> which are exploited by INLA algorithm <a href="inla.html#inla">4</a> leading to a more feasible big-O <span class="math inline">\(\mathcal{O}\left(n^{3 / 2}\right)\)</span>. Mathematical details and deep understanding of the equations in SPDE are beyond the scope of the analysis. Luckily enough R-INLA has a set of functions that makes clear to the practitioner the minimal requirements to pass from discrete locations to their continuously indexed surface alter-ego. As a result of SPDE the spatial Matérn field i.e. the spatial process <span class="math inline">\(\xi(\boldsymbol{s})\)</span> becomes <span class="math inline">\(\tilde\xi(\boldsymbol{s})\)</span>, where the precision matrix <span class="math inline">\(Q\)</span> comes from the SPDE representation <span class="citation">(<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span>.</p>
<p>In few words SPDE approach uses a finite element (FEM method) representation to shape the Matérn field as a linear combination of basis functions defined on a triangulation (Delaunay) of the domain <span class="math inline">\(\mathcal{D}\)</span> <span class="citation">(<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span>, also named <em>mesh</em>. What it internally does is splitting the domain <span class="math inline">\(\mathcal{D}\)</span> into a number of non-intersecting triangles which converge in a common edge or corner. Then the initial vertices of the triangles are set at <span class="math inline">\(s_1 \ldots s_d\)</span>. In order to get a proper triangulation, useful for spatial prediction, additional vertices are then added. The more vertices are added the more the triangulation is accurate since many more triangles can better interpolate the surface reaching more complex shapes. On the other side the more are the triangle the more it will take to compute the mesh and INLA performances can be damaged.</p>
<p>Secondly SPDE maps with a Projection matrix the values of the triangulation to the discretized spatial surface with weighted sum of areas of the underlying triangles.</p>
<div class="bulb">
<p>A less superficial intuition on how SPDE computes triangularizes values and how it uses the projection matrix based on a weighted sum of basis functions to inject the triangulation into the GRMF is offered in the appendix in section <a href="appendix.html#triangular">8.1</a>.</p>
</div>
<p>To illustrate the concept of triangulation <span class="citation"><a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al.</a> (<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span> provide a scatterplot for Piemonte PM10 concentration observed at 24 monitoring stations left in figure <a href="prdm.html#fig:piepm10">5.5</a>. Its respective mesh using 123 vertices and Piemonte borders is in right figure <a href="prdm.html#fig:piepm10">5.5</a>.</p>
<div class="figure"><span id="fig:piepm10"></span>
<img src="images/piemonte_pm10.jpg" alt="" />
<p class="caption">Figure 5.5: Left: monitoring stations in Piemonte region for PM10 pollution levels. Right: its triangulation using 123 vertices. <span class="citation"><a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al.</a> (<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span> source</p>
</div>
<p>Any triangle height (the size of the spatial field at each vertex triangle) is calculated by weighted sum, with linear interpolation deciding the values within the triangle. Figure <a href="prdm.html#fig:spdesurf">5.6</a> shows a continously indexed random spatial field (left side of figure <a href="prdm.html#fig:spdesurf">5.6</a>) with the corresponding SPDE on the basis of a triangulation (right panel <a href="prdm.html#fig:spdesurf">5.6</a>).</p>
<div class="figure"><span id="fig:spdesurf"></span>
<img src="images/spde_indexedsurface.jpg" alt="" />
<p class="caption">Figure 5.6: Left: example of a spatial random field where <span class="math inline">\(X(s)= \cos(s_1)+\sin(s_2)\)</span>, Right: <span class="math inline">\(X(s)\)</span> SPDE representation given a triangulation, <span class="citation"><a href="references.html#ref-Cameletti2012" role="doc-biblioref">Cameletti et al.</a> (<a href="references.html#ref-Cameletti2012" role="doc-biblioref">2012</a>)</span> source</p>
</div>
<p>In INLA mesh triangularization of the region of the study is performed within the function <code>inla.mesh.2d()</code>. Main arguments are:</p>
<ul>
<li><code>loc</code>: the coordinates used as initial vertices of mesh,</li>
<li><code>boundary</code>: the borders of the region of the study <span class="math inline">\(\mathscr{D}\)</span></li>
<li><code>offset</code>: the distance between data positions, which determines the inner and outer extension size,</li>
<li><code>cutoff</code>: minimum distance between points approved.</li>
<li><code>max.edge</code>: value that suggest the current maximum triangle edge lengths in the area and extension. This argument is on the same scale unit as coordinates.</li>
<li><code>min.angle</code> the opposite of max.edge</li>
</ul>
<p>Moreover the mesh can also be built on non convex study area by prior passing coordinates on <code>inla.nonconvex.hull()</code> which are then sent back to the <code>inla.mesh.2d()</code>. A convex hull is a polygon of triangles out of the domain area, in other words the extension made to avoid the boundary effect. If borders are available (and they are) are generally preferred over non convex hull meshes. A decent mesh must have triangles of size and shape as regularly as possible <span class="citation">(<a href="references.html#ref-Krainski-Rubio" role="doc-biblioref">E. T. Krainski 2019</a>)</span>.</p>
</div>
<div id="hedonic-rental-price-models" class="section level2" number="5.3">
<h2><span class="header-section-number">5.3</span> Hedonic (rental) Price Models</h2>
<p>The theoretical foundation of the Hedonic Price Models (from now on HPM) resides in the consumer utility theory of <span class="citation"><a href="references.html#ref-Lancaster" role="doc-biblioref">Lancaster</a> (<a href="references.html#ref-Lancaster" role="doc-biblioref">1966</a>)</span> together with <span class="citation"><a href="references.html#ref-Rosen" role="doc-biblioref">Rosen</a> (<a href="references.html#ref-Rosen" role="doc-biblioref">1974</a>)</span> market equilibrium. According to Lancaster the utility of a commodity does not exist by itself, instead it exists as the sum of the utilities associated to its separable characteristics. Integrating Lancater, Rosen introduces HPM and suggests that each separate commodity characteristics are priced by the markets on the basis of supply and demand equilibra. Applying HPM to Real Estate in a market context, from the buy side house prices (indeed also rents) are set as the unit cost of each household attributes, conversely from the selling side the expenditures associated to build of each them. Formalizing the results, Hedonic Price <span class="math inline">\(P\)</span> in Real Estate is expressed as a general <span class="math inline">\(f\)</span> functional form that takes as input the house characteristics vector <span class="math inline">\(\mathbf{C} = \{c_1,c_2, c_3, \ldots c_n\}\)</span>.</p>
<p><span class="math display">\[P=f\left(c_{1}, c_{2}, c_{3}, \ldots, c_{n}\right)\]</span></p>
<p>Vector <span class="math inline">\(\mathbf{C}\)</span> since now might contain a unidentified and presumably vast number of ungrouped characteristics. In this setting <span class="citation"><a href="references.html#ref-Malpezzi" role="doc-biblioref">Malpezzi</a> (<a href="references.html#ref-Malpezzi" role="doc-biblioref">2008</a>)</span> tried to organize house features by decomposing <span class="math inline">\(\mathbf{C}\)</span> into mutually exclusive and exhaustive subgroups. The vector components involves the house price <span class="math inline">\(P\)</span>, which is in a <span class="math inline">\(f\)</span> relation with: <span class="math inline">\(S\)</span>, the structural characteristics of the house, <span class="math inline">\(N\)</span>, the neighborhood characteristics, <span class="math inline">\(L\)</span>, the locational characteristics, <span class="math inline">\(C\)</span>, the contract conditions and <span class="math inline">\(T\)</span> time dimension (not included in the model). <span class="math inline">\(\beta\)</span> is the vector of the parameters to be estimated. Therefore:</p>
<p><span class="math display">\[P=f\left(S, N, L, C, T, \beta\right)\]</span> However the critical part of studying house characteristics in geostatistics is the <em>estimation</em> and a recent (and not recent) number of emerging trends are observed <span class="citation">(<a href="references.html#ref-SHEPPARD19991595" role="doc-biblioref">Sheppard 1999</a>)</span>. Trends, other than the methods presented in this analysis suggests semi-parametric or non-parametric methods and applications of spatial econometrics <span class="citation"><a href="references.html#ref-Ling" role="doc-biblioref">Ling</a> (<a href="references.html#ref-Ling" role="doc-biblioref">2019</a>)</span>. Researchers would also contend with problems ranging from variable selection to model specification <span class="citation">(<a href="references.html#ref-Ling" role="doc-biblioref">2019</a>)</span>. For semi-paramametric models a local polynomial regression is developed by <span class="citation"><a href="references.html#ref-clapp" role="doc-biblioref">Clapp</a> (<a href="references.html#ref-clapp" role="doc-biblioref">2003</a>)</span>. The model provides a nonlinear term for the measurement of housing position values dependent on latitudes and longitudes. Proper geoadditive models family was originally proposed by Kammann and Wand <span class="citation">(<a href="references.html#ref-kammanwand" role="doc-biblioref">2003</a>)</span>, which offers a combination of additive modeling <span class="citation">(<a href="references.html#ref-buja1989" role="doc-biblioref">Buja, Hastie, and Tibshirani 1989</a>)</span> and a geostatistical component. As Ling <span class="citation">(<a href="references.html#ref-Ling" role="doc-biblioref">2019</a>)</span> points out the candidates for the spatial component are many, e.g. kriging component <span class="citation">(<a href="references.html#ref-dey2017metamodel" role="doc-biblioref">Dey, Mukhopadhyay, and Adhikari 2017</a>)</span> (which will be then subsituted with a GP <a href="prdm.html#GP">5.1</a>) or a smooth spatial trend component based on a tensor product of longitude and latitude for which <span class="citation"><a href="references.html#ref-basilebenfratmcast" role="doc-biblioref">Basile, Benfratello, and Castellani</a> (<a href="references.html#ref-basilebenfratmcast" role="doc-biblioref">2013</a>)</span> have investigated European industrial agglomeration externalities. The model outshines the other parameteric model performances by better managing spatial unobserved patterns. Furthermore they made available a third study dimension which is time <span class="citation">(<a href="references.html#ref-Ling" role="doc-biblioref">2019</a>)</span>. Spatial econometrics’ evolution trends are seen in <span class="citation"><a href="references.html#ref-spateconomshifei" role="doc-biblioref">Shi and Lee</a> (<a href="references.html#ref-spateconomshifei" role="doc-biblioref">2017</a>)</span> and lately in <span class="citation"><a href="references.html#ref-spateconanslein" role="doc-biblioref">Anselin</a> (<a href="references.html#ref-spateconanslein" role="doc-biblioref">2010</a>)</span> where point referenced data are modeled with endogenous time varying spatial weights matrices and unobserved common factors and ultimately are fitted with traditional bayesian estimation methods as MCMC <span class="citation">(<a href="references.html#ref-spateconanslein" role="doc-biblioref">2010</a>)</span>. Then two further interesting modeling approach does not fall perfectly in the categories, but are higly considered in literature within the Hedonic Price models. <span class="citation"><a href="references.html#ref-dubelegros" role="doc-biblioref">Dubé and Legros</a> (<a href="references.html#ref-dubelegros" role="doc-biblioref">2013</a>)</span> recognize that the modeling tools available analyzing point referenced data were not sufficient to take into account all the dimensions according to which they want to evaluate the phenomenon. They acknowledge that <em>Moran’s I</em> index and his statistics test relies mainly on an exogenous specification of a spatial weights matrix <span class="citation">(<a href="references.html#ref-dubelegros" role="doc-biblioref">2013</a>)</span>. As a result they assemble a spatio‐temporal weights matrix to evaluate spatial dependence through Moran’s I index whose application is on real estate data (selling) for Québec City from 1986 to 1996. The second approach was addressed in <span class="citation"><a href="references.html#ref-baltagiparis" role="doc-biblioref">Baltagi, Bresson, and Etienne</a> (<a href="references.html#ref-baltagiparis" role="doc-biblioref">2015</a>)</span> whose object is price estimation based on flats sold in the city of Paris over the period 1990–2003. This is a rich and unbalanced pseudo‒panel data which are modeled with spatial lag. Results displayed a nested structure of the Paris housing data, which have been tested with likelihood ratio. A similar approach was followed by Nardelli and Arbia <span class="citation">(<a href="references.html#ref-arbia2020spatial" role="doc-biblioref">Arbia and Nardelli 2020</a>)</span> which collected crowdsourced as well as webscraped (as in section <a href="scraping.html#scraping">2</a>) data and lately applied Spatial Lag Model (SLM) on a “post-sampled” <span class="citation">(<a href="references.html#ref-arbia2020postsampling" role="doc-biblioref">Arbia et al. 2020</a>)</span> version of the same. As a result bias in the model is diminished, indeed variance of the estimators is increased. <!-- Historically a first attempt to include spatial effect in urban economic literature is provided by _Alonso (1964) miss ref_. Its contribution was to raise voice on house prices (also rent) mainly depending on land price and a number of purely spatial covariates like CBD, the distance from City Business District. Other covariates were transport cost per kilometer and community income, even though they were defined also as spatial parameters through distances. The model proposed by Alonso is called monocentric since the centroid from which distances are calculated is only one. Moreover a first touch to spatial data theory was done since the CBD was defined as areal unit with well-defined boundaries of regular or irregular shape. However applications of the model were not convincing since empirical studies offered a different picture. Results displayed a Poly-centric areal structure (universities and Malls) which might be better explaining the variance of prices. The model also assumed that covariates like CBD are only informative within city center boundaries and then show no significance out of the core of the city. Poly-centric theory was also more coherent with the architectural and socio-economical evolution of cities during that times, therefore mono centric theory was then criticized and abandoned. Critics regarded also neighborhood quality measure and boundary problems _Dubin (1987) miss ref_. Dubin for these reasons developed a model including areal effects in the error term since handling these covariates was posing several hard challenges. Areal data choice for Dubin was forced since he was interested in land values, geostatics interest was not a focus also due to the difficulties in gathering accurate data. Coming to recent literature a change in focus has been made by switching from theory based model to estimation methods. As a consequence to the change in focus @Ling said that practitioners should spend more time in variable selection and model specification with respect to their specific need. --> <!-- As Ling has observed the emerging trends are in the field of semi-parametric and non-parametric methods -@Ling. Historically semi-parametric regression considers models indexed by spatial coordinates _Pace RK (1995)_. At the same time _Kammann and Wand (2003)_ gave birth to geoadditive models where the spatial component is added as a covariate. [...] --> A further aspect of the problem is posed by scholars not considering rents to be representative for the actual value of the real estate due to heavier legislation on rent and indebtedness (for selling). As a consequence predictors choice and functional relatioship should be different from the selling. Nevertheless in many empirical analysis rent values are considered as a proxy for real estate pricing when considered in long-run <span class="citation">(<a href="references.html#ref-Herath_Maier_2011" role="doc-biblioref">Herath and Maier 2011</a>)</span>. A further argument to endorse this hypothesis is brought by <span class="citation"><a href="references.html#ref-sellingVSrental" role="doc-biblioref">Manganelli, Morano, and Tajani</a> (<a href="references.html#ref-sellingVSrental" role="doc-biblioref">2013</a>)</span> considering housing a commodity, then the selling or the rental option should be interchangeable economic actions with respect to same inner need to be satisfied. This assumption is also stronger in this context since Manganelli, Morano, and Tajani have centered their analysis on italian Real Estate data. Moreover <span class="citation"><a href="references.html#ref-Capozza_Seguin_1996" role="doc-biblioref">Capozza and Seguin</a> (<a href="references.html#ref-Capozza_Seguin_1996" role="doc-biblioref">1996</a>)</span> discussed on how much rent-price ratio predicts future changes both in rents and prices. Among all the other points raised they brought the decomposition of rent-price ratio into two parts: the predictable part and the unexplained residuals part. The predictable part was discovered to be negatively correlated with price changes, in other words cities in which prices are relatively high with respect to rents are associated with higher capital gains that might justify that misalignment. This is also true for the opposite, that is cities in which prices are lower with respect to the rents, and this effect can not be associated to any local condition, realize lower capital gains. A further argument is offered by Clark <span class="citation">(<a href="references.html#ref-Clark_1995" role="doc-biblioref">Clark 1995</a>)</span> which went after the Capozza and Seguin work. Rent-price ratio is negatively correlated with following future changes in rents. In other words prices are still higher when areas in which they are observed documents an increase in rent prices.</p>
</div>
<div id="criticism" class="section level2" number="5.4">
<h2><span class="header-section-number">5.4</span> Model Criticism</h2>
<p>Since INLA can fit a wide range of models then the flexibility should be reflected by a mouldable tool to check model suitability. Model criticism may regard the research on which variables are used in the model, which assumptions are made on parameters and on the likelihood as well as the prior choice addressed in <a href="prdm.html#priorsspec">5.5</a>. However here are two common <em>modi operandi</em> which are also implemented inside inla: one based on predictive distribution and the other on deviance. Note that all specifications mentioned in this analysis can be determined by setting the option in <code>control.compute</code>.</p>
<div id="predbase" class="section level3" number="5.4.1">
<h3><span class="header-section-number">5.4.1</span> Methods based on the predictive distribution</h3>
<p>One of the most used method to assess Bayesian model quality is LOOCV, i.e. Leave One Out Cross Validation and it is also default choice in INLA. Assume to have <span class="math inline">\(\boldsymbol{y}\)</span> data from which it is left out one single <span class="math inline">\(y_i\)</span> observation, as a result the assessment set is <span class="math inline">\(\boldsymbol{y}_{A} = \boldsymbol{y}_{-i}\)</span> and the validation set is <span class="math inline">\({y}_{V} = y_{i}\)</span>, where the notation is the same for chapter <a href="inla.html#inla">4</a>. Two metrics are assumed to be demonstrative:</p>
<ul>
<li>CPO Conditional Predictive Ordinate <span class="citation">(<a href="references.html#ref-petit1990" role="doc-biblioref">Pettit 1990</a>)</span>: <span class="math inline">\(CPO_{i} = \pi(y_{V} \mid \boldsymbol{y}_{A})\)</span>, For any observation the CPO is the posterior probability of observing the left out <span class="math inline">\(y_{V}\)</span> when the model is fitted with <span class="math inline">\(\boldsymbol{y}_A\)</span> assessment set. High values imply that the model suits well the data, while small values indicate a poor fit, i.e. outlier. <span class="citation">(<a href="references.html#ref-Bayesian_INLA_Rubio" role="doc-biblioref">Gómez Rubio 2020</a>)</span>. The negative log-summation (LPML <span class="citation"><a href="references.html#ref-lpml" role="doc-biblioref">Geisser and Eddy</a> (<a href="references.html#ref-lpml" role="doc-biblioref">1979</a>)</span>) of each CPO gives a cross-validatory summary measure of fit <span class="citation">(<a href="references.html#ref-wang2018bayesian" role="doc-biblioref">Wang, Yue, and Faraway 2018</a>)</span> i.e. <span class="math inline">\(-\sum_{i=1}^{n} \log \left(C P O_{i}\right)\)</span></li>
<li>PIT Predictive Integral Transform <span class="citation">(<a href="references.html#ref-marshall2007" role="doc-biblioref">Marshall and Spiegelhalter 2007</a>)</span>: <span class="math inline">\(PIT_{i} = \pi(y_{V} < y_{i} \mid \boldsymbol{y}_{A})\)</span>. PIT computes the probability of a new response value being smaller than the observed real value and it is calculated for each left out observation:</li>
</ul>
<p>Inla also provides for both of the predictive methods an inner functionality to automatically handle abnormalities while computing the two quantities. Inla encodes values with 1 when predictions are not reliable, otherwise they are set equal to 0. Moreover the empirical distribution of the PIT can be used to asses predictive performance: if it is Uniform, so there are not values that significantly differ from the others then the model suits the data. Otherwise if the distribution almost approximates any of the other one then the “out of the bag” prediction suggest a model miss-pecification.</p>
<p>For example assume to have data from a 1970’s study on the relationship between insurance redlining in Chicago and racial composition, fire and theft rates, age of housing and income in 47 zip codes (inherited by <code>brinla</code><span class="citation">(<a href="references.html#ref-brinla" role="doc-biblioref">Faraway, Yue, and Wang 2021</a>)</span>). Assume also to fit a linear model whose response is “involact” being new FAIR plan policies and renewals per 100 housing units and the rest are predictors, i.e. <span class="math inline">\(involact \sim race + fire +theft + age + \log(income)\)</span>. Then the resulting LPML is: -20.6402106 Furthermore in left panel of fig. <a href="prdm.html#fig:pitcpo">5.7</a> the resulting cross-validated PIT resembles a Uniform distribution which is also highlighted whose density is highlighted in tone in the lower part. In the right side a Quantile-Quantile for a Uniform (whose parameter are mean 0 and std 1) plot evidences how much the points are attached to the diagonal, confirming the well behaved model.</p>
<div class="figure" style="text-align: center"><span id="fig:pitcpo"></span>
<img src="05-prd_modelling_files/figure-html/pitcpo-1.png" alt="Left: histogram of cross-validated PIT, Right: QQ plot for Unif(0,1)" width="672" />
<p class="caption">
Figure 5.7: Left: histogram of cross-validated PIT, Right: QQ plot for Unif(0,1)
</p>
</div>
<p>Posterior Predictive checking methods <span class="citation">(<a href="references.html#ref-gelman1996posterior" role="doc-biblioref">Gelman, Meng, and Stern 1996</a>)</span> exploit a full cross-validation where <span class="math inline">\(\boldsymbol{y}_{A} = \boldsymbol{y}_{V}\)</span>, operating on the full set of observation. The statistics capitalized below are quite commonly used in practice, but they are high context dependent:</p>
<ul>
<li>the <em>posterior predictive distribution</em>: <span class="math inline">\(\pi(y^{\star} \mid \boldsymbol{y}) = \int \pi(y^{\star} \mid \theta_{i})\pi({\theta_{i}} \mid \boldsymbol{y})\mathrm{d}\theta_{i}\)</span> which is the likelihood of a replicate observation. When values are small that indicates that are those values are coming from tails, since the area under the curve (i.e. probability) is less. If this happens for many observation then outliers are driving the model leading to poor estimates</li>
<li>the <em>posterior predictive p-value</em> whose math expression is:<span class="math inline">\(\pi(y^{\star} \leq y_{i} \mid \boldsymbol{y})\)</span> for which values near to 0 and 1 indicates poor performances.</li>
<li>the <em>Root Mean Square Predictive Error RMSE</em>: <span class="math inline">\(\sqrt{\frac{1}{n} \sum_{i=1}^{n}(y_{i}-{y}^{\star}_{i})^{2}}\)</span></li>
<li><span class="math inline">\(R^2\)</span></li>
</ul>
<p>R-INLA has already antiticipated in chapter 4 section<a href="#example"><strong>??</strong></a> have dedicated function to compute statistics on posterior distribution e.g. <code>inla.pmarginal()</code> returning the cumulative density distribution.</p>
</div>
<div id="devbased" class="section level3" number="5.4.2">
<h3><span class="header-section-number">5.4.2</span> Deviance-based Criteria</h3>
<p>If there is an interest in comparing multiple models, then their deviance may be used. Given data <span class="math inline">\(\boldsymbol{y}\)</span> and its likelihood function, along with its parameters <span class="math inline">\(\boldsymbol\theta\)</span> then the <em>deviance</em> is:</p>
<p><span class="math display">\[
\mathrm{D}(\theta)=-2 \log (\pi(\boldsymbol{y} \mid \theta))
\]</span></p>
<p>The model’s deviance tests the likelihood variability conditioned to its parameters. Since this is a random variable tt can be analyzed by several statistics such as mean, median, mode etc. The most used is the posterior mean deviance i.e.<span class="math inline">\(\overrightarrow{\mathrm{D}}=E_{\theta_{\mid y}}(\mathrm{D}(\theta))\)</span> which is also robust <span class="citation">(<a href="#ref-Blangiaro-Cameletti" role="doc-biblioref"><strong>Blangiaro-Cameletti?</strong></a>)</span>. Indeed it suffers from cost complexity, as a result DIC proposed by <span class="citation"><a href="references.html#ref-spiegelhalter2002bayesian" role="doc-biblioref">Spiegelhalter et al.</a> (<a href="references.html#ref-spiegelhalter2002bayesian" role="doc-biblioref">2002</a>)</span> adds to the deviance a penalization for complex model i.e. <span class="math inline">\(p_{\mathrm{D}}=\mathrm{E}_{\theta_{\mathrm{y}}}(\mathrm{D}(\theta))-\mathrm{D}\left(\mathrm{E}_{\theta_{\mathrm{y}}}(\theta)\right)=\overline{\mathrm{D}}-\mathrm{D}(\bar{\theta})\)</span> from which, following <span class="citation">(<a href="#ref-Blangiaro-Cameletti" role="doc-biblioref"><strong>Blangiaro-Cameletti?</strong></a>)</span> obtain,</p>
<span class="math display" id="eq:dic">\[\begin{equation}
\mathrm{DIC}=\overline{\mathrm{D}}+p_{\mathrm{D}}
\tag{5.1}
\end{equation}\]</span>
<p>Data is best served in models with small-scale DICs and the correspondent INLA option setting is analogous to the ones seen sec. <a href="prdm.html#predbase">5.4.1</a>. INLA moreover take advantage of the hierarchical structure and computes different posterior deviances for latent parameters i.e. mean and hyper parameters i.e. mode (due to skewness). For further discussions <span class="citation"><a href="references.html#ref-spiegelhalter2014deviance" role="doc-biblioref">Spiegelhalter et al.</a> (<a href="references.html#ref-spiegelhalter2014deviance" role="doc-biblioref">2014</a>)</span> oppose DIC with other criteria for model comparison. Finally the Watanabe Akaike information criterion (WAIC) which is more Bayesian orthodox in setting up the criteria, for this reason is also more preferred <span class="citation">(<a href="references.html#ref-gelman2014understanding" role="doc-biblioref">Gelman, Hwang, and Vehtari 2014</a>)</span>.</p>
</div>
</div>
<div id="priorsspec" class="section level2" number="5.5">
<h2><span class="header-section-number">5.5</span> Penalized Complexity Priors</h2>
<p>The priors choice is the most central part of a Bayesian analysis and at the same time the weakest since any selection might be criticized. Priors expression involves a considerably high amount of subjectivity and domain experience which may be imported from other comparable literature works or results. However according to purists Bayesian priors should be decided <em>a-priori</em>, without either looking at the data, nor the posterior results. This can be tedious since many models are sensitive to priors, as evidenced in the example in sec. <a href="inla.html#rinla">4.4</a>. Priors may negatively impact posteriors when are wrong and they usually require a later revision. The choice in this context is also more difficult since it is also constrained to LGM requirements for which the latent field demands them to be jointly Gaussian. <span class="citation"><a href="references.html#ref-simpson2017" role="doc-biblioref">Simpson et al.</a> (<a href="references.html#ref-simpson2017" role="doc-biblioref">2017</a>)</span> provide a solid backbone knowledge on priors specification in Hierarchical models by setting up 4 guidelines principles on top of which it is built a new prior class called Penalized Complexity (PC) priors. Before jumping into the principles it is needed an abstract concept that goes by the name of “base model.” For a general density <span class="math inline">\(\pi(\mathbf{y} \,| \,\xi)\)</span> which is controlled by a flexibility parameter <span class="math inline">\(\xi\)</span> the base model is the most uncomplicated one in the class. Following the notation this would be the model corresponding to <span class="math inline">\(\xi = 0\)</span>. The base model ideally grabs the parameter choice with the lowest possible complexity given the model and set it as a ground benchmark. The following example regards base model for a a Gaussian Random effect and it considers a multivarite gaussian distributed with mean <strong>0</strong> and precision matrix <span class="math inline">\(\tau \boldsymbol{Q}\)</span>, i.e. <span class="math inline">\(\mathbf{y} \mid \xi \sim \operatorname{MVN}(\, 0\, ,\,\tau \boldsymbol{Q})\)</span>, where <span class="math inline">\(\tau=\xi^{-1}\)</span>. The base model tries to put the mass <span class="citation">(<a href="references.html#ref-simpson2017" role="doc-biblioref">2017</a>)</span> on <span class="math inline">\(\xi = 0\)</span> since the base model in this case is a model without the random effect. At this point it is possible to present the building blocks, first priciple is <em>Occam’s razor</em> according to which priors should be weighted down in fuction of the distance between the added complexity and the base model i.e. simpler models are preferred. The second principle regards how it is measured complexity whose solution is found in KLD (Kullback–Leibler divergence), calculating distance <span class="math inline">\(d\)</span> from base model. KLD in this context along with principle 1 affirms that the prior shall have high mass in areas where replacing the base model with the flexible model will not cause any information loss. Principle 3 is constant rate penalization as names suggest relates the distance <span class="math inline">\(d\)</span> to a constant rate penalization whose assumption implies an exponential prior on the distance scale, i.e. <span class="math inline">\(\pi(d) = \lambda \exp (-\lambda d)\)</span>. In the end, the PC prior is described in the required scale with probability statements on the model parameters. Statement regards the selection of two further user defined (here the subjectivity) hyper-parameters, <span class="math inline">\(U\)</span> regulating the tail event and <span class="math inline">\(\alpha\)</span> the mass to put to this event such that <span class="math inline">\(\operatorname{P}(Q(\xi)>U)=\alpha\)</span>. A prior satisfying all the requirements is said Penalized in Complexity. Priors of this class should be then derived with respect to the specific content they are needed. In this context PC priors are seen for Gaussian Random effect, i.e. the GP <a href="prdm.html#def:GP">5.1</a> modeling spatial dependence for which a precision hyper parameter is demanded. The PC prior for the precision <span class="math inline">\(\tau\)</span> is on standard deviation scale <span class="math inline">\(\sigma=\tau^{-1 / 2}\)</span>.<br />
Then the GMRF latent field has mean 0 and covariance matrix <span class="math inline">\(\boldsymbol{Q^{-1}}\)</span>, i.e. <span class="math inline">\(\boldsymbol{\theta} \sim \mathcal{N}\left(\mathbf{0}, \tau^{-1} \boldsymbol{Q}^{-1}\right)\)</span>. The base model considers the absence of the random effect which implies <span class="math inline">\(\tau \rightarrow \infty\)</span>. Then the derived PC prior <span class="citation">(<a href="references.html#ref-simpson2017" role="doc-biblioref">Simpson et al. 2017</a>)</span> takes the form of an exponential distribution, i.e. “type-2 Gumbel distribution” eq: <a href="prdm.html#eq:exponential">(5.2)</a>, whose rate parameter is <span class="math inline">\(\lambda\)</span> determining the severity of the penalty when diverging from the base model. Note that the parameter <span class="math inline">\(\lambda\)</span> is on the standard deviation scale (in contrast to the Gamma on the precision seen in <a href="inla.html#rinla">4.4</a>).</p>
<span class="math display" id="eq:exponential">\[\begin{equation}
\pi(\tau)=\frac{\lambda}{2} \tau^{-3 / 2} \exp \left(-\lambda \tau^{-1 / 2}\right), \tau>0
\tag{5.2}
\end{equation}\]</span>
<p>The distribution depends on a rate parameter <span class="math inline">\(\lambda\)</span> that regulates the penalty according to the probability natural criterion <span class="citation">(<a href="#ref-slides" role="doc-biblioref"><strong>slides?</strong></a>)</span> <span class="math inline">\(\operatorname{Prob}(\tau^{-\frac{1}{2}} > U)=\alpha\)</span>. <span class="math inline">\(U\)</span> in this case is an upper limit for the standard deviation (being in the base model) and <span class="math inline">\(\alpha\)</span> a small probability. The probability statement aforementioned implies the follwing realtion <span class="math inline">\(\lambda=-\ln (\alpha) / U\)</span>. Some further investigations of <span class="citation"><a href="references.html#ref-simpson2017" role="doc-biblioref">Simpson et al.</a> (<a href="references.html#ref-simpson2017" role="doc-biblioref">2017</a>)</span> acknowledged that parameters upper bounds for <span class="math inline">\(\tau\)</span> are <span class="math inline">\(U = 0.968\)</span>, and <span class="math inline">\(\alpha = 0.01\)</span>, where alpha regulates the importance of the prior believe. Ideally it would be picked up <span class="math inline">\(U\)</span> drawing on previous experience. Indeed a reasonable choice in the absence of knowledge might be taking the semivariogram range <a href="prdm.html#GP">5.1</a>, i.e. where the spatial dependece disappears. PC priors are natively implemented in INLA and are shown to be well suited for the modular additive definition <span class="citation">(<a href="references.html#ref-Bayesian_INLA_Rubio" role="doc-biblioref">Gómez Rubio 2020</a>)</span>. As a consequence they are selected as prior candidates with a reasonable <span class="math inline">\(U\)</span> selection and no sensitivity analysis is performed i.e. evalutaing posterior disstribution while prior are changing.</p>
<!-- ![New prior (dashed) with parameters ($U = 0.968$,$\alpha = 0.01$), and the $\Gamma(shape = 1,rate = b)$ prior (solid).](images/new_prior.jpg) -->
<p>Fig. <a href="prdm.html#fig:priorfun">5.9</a> indicates various PC priors using several <span class="math inline">\(\alpha\)</span> values for the precision <span class="math inline">\(\tau\)</span>. Note that increasing <span class="math inline">\(\alpha\)</span>’s values contribute to a stronger prior belief for <span class="math inline">\(U\)</span> which then leads to a higher conviction of <span class="math inline">\(\tau\)</span>.</p>
<!-- PROVA A METTERE ESEMPIO SPDETOY -->
<div class="figure" style="text-align: center"><span id="fig:priorfun"></span>
<img src="05-prd_modelling_files/figure-html/priorfun-1.png" alt="PC priors for the precision by varying alpha values and fixing $U$" width="672" />
<p class="caption">
Figure 5.9: PC priors for the precision by varying alpha values and fixing <span class="math inline">\(U\)</span>
</p>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="inla.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="exploratory.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": true,
"weibo": false,
"instapaper": false,
"vk": false,
"all": false,
"google": false
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/NiccoloSalvini/thesis/edit/master/05-prd_modelling.Rmd",
"text": "Suggest an edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["Niccolo_Salvini_Thesis.pdf"],
"toc": {
"collapse": "section",
"scroll_highlight": true
},
"search": true
});
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
var src = "true";
if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
if (location.protocol !== "file:")
if (/^https?:/.test(src))
src = src.replace(/^https?:/, '');
script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>