-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession9C_talk2.html
More file actions
841 lines (614 loc) · 30.7 KB
/
session9C_talk2.html
File metadata and controls
841 lines (614 loc) · 30.7 KB
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>bnmonitor: Checking the Robustness and Sensitivity of Bayesian Networks</title>
<meta charset="utf-8" />
<meta name="author" content="Dr. Rachel Wilkerson Founder at Tesserwell, LLC Github: rachwhatsit @rlwilkerson rachel.lynne.wilkerson@gmail.com" />
<link href="libs/remark-css/default.css" rel="stylesheet" />
<link href="libs/remark-css/default-fonts.css" rel="stylesheet" />
<script src="libs/htmlwidgets/htmlwidgets.js"></script>
<script src="libs/jquery/jquery.min.js"></script>
<link href="libs/datatables-css/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding/datatables.js"></script>
<link href="libs/dt-core/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk/js/crosstalk.min.js"></script>
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# <code>bnmonitor</code>: Checking the Robustness and Sensitivity of Bayesian Networks
### Dr. Rachel Wilkerson <br> Founder at <a href="https://www.tesserwell.co/">Tesserwell, LLC</a> <br> <a href="https://github.com/rachwhatsit"><i class="fa fa-github" style="font-size:48px;color:white"></i> Github: rachwhatsit</a><br> <a href="https://twitter.com/rlwilkerson?lang=en"> <i class="fa fa-twitter fa-fw"></i> <span class="citation">@rlwilkerson</span></a><br> <a href="mailto:rachelw52@gmail.com"> <i class="fa fa-paper-plane fa-fw"></i> rachel.lynne.wilkerson@gmail.com</a><br>
### 2021-07-09 <img src="user-logo-color.png" alt="drawing" width="100"/> <br><br> Package webpage at <br> <a href="https://cran.r-project.org/web/packages/bnmonitor/index.html" class="uri">https://cran.r-project.org/web/packages/bnmonitor/index.html</a>
---
# Package Overview 📦
### Robustness
- `bnmonitor` provides a suite of diagnostic monitors that can be used in increasing fineness to check the **accuracy of forecasts** flowing from a model
- Robustness monitors work on BNs learned from data
--
### Sensitivity
- The sensitivity functions check the **effect of changes to the probability distributions**
- Sensitivity monitors work on BNs learned either from data or elicitation. Data can be either discrete or continous.
???
---
# Example: Diabetes 💉
We illustrate our package with what the UCI Repository refers to as the Pima Indian dataset.
It consists of 392 observation with the following variables, discretized according to <a name=cite-Nojavan2017></a>[Nojavan, Qian, and Stow (2017)](#bib-Nojavan2017) :
--
- `PREG`: number of times pregnant (low/high)
--
- `GLUC`: plasma glucose concentration (low/high)
--
- `PRES`: diastolic blood pressure (low/high)
--
- `TRIC`: triceps skin fold thickness (low/high)
--
- `INS`: 2-hour serum insulin (low/high)
--
- `MASS`: body mass index (low/high)
--
- `PED`: diabetes pedigree function (low/high)
--
- `AGE`: age (low/high)
--
- `DIAB`: test for diabetes (neg/pos)
---
background-image: url("libs/img/women-Pima-shinny-game-field-hockey.jpeg")
background-position: contain
class: center, bottom, inverse
We chose this dataset as it best showcases our monitors. However, we acknowledge that we are using the data without the explicit consent of or compensation for the original Akimel O’odham participants. For more information see <a name=cite-radin2017digital></a>[Radin (2017)](#bib-radin2017digital).
???
Image credit: [image of Akimel O’odham women playing lacrosse](https://www.britannica.com/topic/Pima-people)
---
class: inverse, center, middle
# Robustness
---
# Bayesian Network
.pull-left[
```r
dag <- hc(diabetes)
graphviz.plot(dag)
```
<img src="useR-bnmonitor_files/figure-html/daghc-1.png" title="DAG generated by hill climbing algorithm, showing a collider at diabetes and age nodes." alt="DAG generated by hill climbing algorithm, showing a collider at diabetes and age nodes." width="75%" height="75%" />
]
.pull-right[
```r
dag2 <- mmhc(diabetes)
graphviz.plot(dag2)
```
<img src="useR-bnmonitor_files/figure-html/dagmmhc-1.png" title="Alternative DAG only showing a collider for diabetes. TRIC, MASS form their own component, and PED is a singleton edge." alt="Alternative DAG only showing a collider for diabetes. TRIC, MASS form their own component, and PED is a singleton edge." width="90%" height="75%" />
]
???
here are two candidates dags we learn from hill climbing and max min hill climbing.
can compute the BF in bnlearn package, ours shows the contributions
---
# Global monitors 🌍
```r
glb.mon <- global_monitor(dag = dag , df = diabetes,alpha=2)
glb.mon2 <- global_monitor(dag = dag2 , df = diabetes,alpha=2)
```
--
- `\(\alpha\)` is commonly set as the maximum number of levels for a node in the dataset
--
<table>
<thead>
<tr>
<th style="text-align:left;"> Vertex </th>
<th style="text-align:left;"> dag_hc </th>
<th style="text-align:left;"> dag_mmhc </th>
<th style="text-align:left;"> bf_vertex </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> PREG </td>
<td style="text-align:left;"> 236.266 </td>
<td style="text-align:left;"> 236.266 </td>
<td style="text-align:left;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> GLUC </td>
<td style="text-align:left;"> 274.348 </td>
<td style="text-align:left;"> 274.348 </td>
<td style="text-align:left;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> PRES </td>
<td style="text-align:left;"> 250.087 </td>
<td style="text-align:left;"> 250.087 </td>
<td style="text-align:left;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> TRIC </td>
<td style="text-align:left;"> 267.184 </td>
<td style="text-align:left;"> 274.15 </td>
<td style="text-align:left;"> 0.975 </td>
</tr>
<tr>
<td style="text-align:left;"> INS </td>
<td style="text-align:left;"> 219.878 </td>
<td style="text-align:left;"> 219.878 </td>
<td style="text-align:left;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> MASS </td>
<td style="text-align:left;"> 231.847 </td>
<td style="text-align:left;"> 231.847 </td>
<td style="text-align:left;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> PED </td>
<td style="text-align:left;"> 272.604 </td>
<td style="text-align:left;"> 274.475 </td>
<td style="text-align:left;"> 0.993 </td>
</tr>
<tr>
<td style="text-align:left;"> AGE </td>
<td style="text-align:left;"> 246.505 </td>
<td style="text-align:left;"> 250.768 </td>
<td style="text-align:left;"> 0.983 </td>
</tr>
<tr>
<td style="text-align:left;"> DIAB </td>
<td style="text-align:left;"> 214.011 </td>
<td style="text-align:left;"> 214.405 </td>
<td style="text-align:left;"> 0.998 </td>
</tr>
</tbody>
</table>
???
our nodes can be used in increasingly refined manner
comparing node contributions allows us to see directly
we can also return to the global monitor after making changes downstream
---
# Prequential Monitors
- Prequential monitors were first developed by <a name=cite-Dawid1992></a>[Dawid (1992)](#bib-Dawid1992) and refined in <a name=cite-Cowell2006></a><a name=cite-Cowell2007></a>[Cowell, Dawid, Lauritzen, and Spiegelhalter (2006)](#bib-Cowell2006); [Cowell, Verrall, and Yoon (2007)](#bib-Cowell2007).
--
- `\(p_i\)` gives the predictive density of the BN learned using the dataset `\(x_{[i-1]}\)` including only the first `\(i-1\)`-th observations
--
- the level of surprise 😲 of observing the value `\(y_j\in\mathbb{Y}_j\)` for the `\(j\)`-th variable after having processed `\(i\)` observations is:
`$$S_{ij} = -\log(p_i(y_j)))$$`
--
- We use the **logarithmic score** function here, but other score functions can certainly be substituted.
---
### Diabetes Example 💉
<div id="htmlwidget-be5a03d9052dc02a4d09" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-be5a03d9052dc02a4d09">{"x":{"filter":"none","fillContainer":false,"data":[["4","5","7","9","14","15","17","19","20","21"],["low","low","high","high","low","high","low","low","low","high"],["low","high","low","high","high","high","low","low","low","high"],["low","low","low","high","low","high","high","low","high","high"],["low","high","high","high","low","low","high","high","high","high"],["low","high","low","high","high","high","high","low","low","high"],["low","high","low","low","low","low","high","high","high","high"],["low","high","low","low","low","high","high","low","high","high"],["low","high","low","high","high","high","high","high","high","high"],["neg","pos","pos","pos","pos","pos","pos","neg","pos","neg"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>PREG<\/th>\n <th>GLUC<\/th>\n <th>PRES<\/th>\n <th>TRIC<\/th>\n <th>INS<\/th>\n <th>MASS<\/th>\n <th>PED<\/th>\n <th>AGE<\/th>\n <th>DIAB<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":8,"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}],"lengthMenu":[8,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# Standardization
- **Relative** standardization compares the log likelihood contributions to two different models.
--
- **Absolute** standardization computes a Z-statistic using the following expectation and variance:
--
`$$E_{ij} = \sum_{y_j\in\mathbb{Y}_j}p_i(y_j)\log(p_i(y_j))$$`
`$$V_{ij}=\sum_{y_j\in\mathbb{Y}_j}p_i(y_j)\log(p_i(y_j))^2-E_{ij}^2$$`
--
`$$Z_{ij}=\frac{\sum_{k=1}^iS_{kj}-\sum_{k=1}^iE_{kj}}{\sqrt{\sum_{k=1}^iV_{kj}}}$$`
- `\(| Z_{ij}|> 1.96\)` in absolute value may be an indication of poor model fit
---
class: center, middle
# Prequential = Sequential + predictions 🔮
---
# Marginal node monitors
- Marginal and conditional node monitors check the **appropriateness of the probability distributions** of each node
--
```r
marg.ped <- plot(seq_marg_monitor(dag, diabetes, "PED"))
```
--
.pull-left[
<img src="useR-bnmonitor_files/figure-html/nodegoodfitout-1.png" title="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. all points are within two dashed lines representing |z| &lt;1.96" alt="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. all points are within two dashed lines representing |z| &lt;1.96" width="95%" height="95%" />
]
--
.pull-right[
👌 The marginal node monitor for PED (diabetes pedigree function) indicates a good fit.
]
---
# Marginal node monitors
```r
marg.diab <- plot(seq_marg_monitor(dag, diabetes, "DIAB"), fig.alt = "scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. most points are within two dashed lines representing |z| <1.96 except towards the end of the indices.")
```
--
.pull-left[
<img src="useR-bnmonitor_files/figure-html/nodebadfitout-1.png" title="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. most points are within two dashed lines representing |z| &lt;1.96 except towards the end of the indices." alt="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. most points are within two dashed lines representing |z| &lt;1.96 except towards the end of the indices." width="95%" height="95%" />
]
--
.pull-right[
❌ The marginal node monitor for `DIAB` (diabetes) suggests that the the marginal distribution may be inappropriate for later forecasts.
]
???
By contrast, the marginal sequential node monitor suggests that the probability distribution for the node diabetes is not necessarily accurate for later observation in the data.
---
# Conditional node monitors 🤰🏽
- Conditional node monitors pass evidence on the other variables for the `\((i-1)\)`th observations.
--
--
.pull-left[
<img src="useR-bnmonitor_files/figure-html/condmonitorout-1.png" title="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. the first half of the dataset shows points well below the red dashed line representing z &lt; 1.96" alt="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. the first half of the dataset shows points well below the red dashed line representing z &lt; 1.96" width="504" />
]
.pull-right[
🧐The conditional node monitor for PREG (pregnancy) indicates a poor fit to early forecasts in the data.
]
---
# Parent child monitor 👪
- The parent-child monitors score `\(S_{ij}^{\pi_j}=p_i(y_j|y_{\pi_j})\)` with the same standardization as the node monitors.
--
```r
pach.preg <- plot(seq_pa_ch_monitor(dag, diabetes, "PREG",
pa.names = "AGE", pa.val = "low", alpha=2))
```
--
.pull-left[
<img src="useR-bnmonitor_files/figure-html/pachmonitorout-1.png" title="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. the first half of the dataset shows points well above the red dashed line representing z &lt; 1.96" alt="scatterplot with x axis depicting index in the dataset and y indicating the standardized z statistics. the first half of the dataset shows points well above the red dashed line representing z &lt; 1.96" width="85%" height="85%" />
]
--
.pull-right[
🧐 The parent-child monitor reveals poor forecasts of pregnancy for young women.
]
---
class: inverse, center, middle
# Sensitivity
---
# Background
- For model `\(G\)` with observation and evidence variables `\(O\)` and `\(E\)`, we are interested in `\(p_G(y_O|y_E)\)`
- We want to study how this probability varies in terms of the conditional probabilities `\(p(y_i|y_{{\Pi}_i})\)` that define the model.
- The question first adressed by <a name=cite-Chan2002></a>[Chan and Darwiche (2002)](#bib-Chan2002) is: which changes in the conditional probabilities `\(p(y_i|y_{\Pi_i})\)` would make `\(p_G(y_O|y_E)=a\)`?
---
# Diabetes Example 💉
- How does the marginal probability of a positive test ✔️ depends on the variable `GLUC` = `high.` 🍬
```r
plot(sensitivity(bn,
interest_node = "DIAB",
interest_node_value = "pos",
node = "GLUC",
value_node = "high",
value_parents = NULL,
new_value = "all")) +
theme(text=element_text(size=25))
```
???
The vertex of most interest is DIAB reporting the result of a diabetes test (either positive or negative). As an illustration, we first investigate how the probability of a positive test depends on the variable GLUC = high.
The plot shows that has the probability of having a high level of glucose increases, then also the probability of a positive test increases.
---
# Diabetes Example 💉
- We also consider how the conditional probability of a positive test ✔️ given a low level of insulin varies when the probability of a high level of 🍬 glucose changes.
```r
plot(sensitivity(bn,
interest_node = "DIAB",
interest_node_value = "pos",
evidence_nodes = "INS",
evidence_states = "low",
node = "GLUC",
value_node = "high",
value_parents = NULL ,
new_value = "all"))+
theme(text=element_text(size=25))
```
???
In the previous example the probability of interest was the marginal probability of a positive test. Similarly, we can assess how generic conditional probabilities are affected by changes in the model. As an illustration, let's consider the conditional probability of a positive test given a low level of insulin and this varies when the probability of a high level of glucose changes. This can be done similarly to the previous code, but now we have to fix the evidence nodes and evidence states inputs.
---
# Diabetes Example
.pull-left[
<img src="useR-bnmonitor_files/figure-html/sensdcout-1.png" title="line plot with new values on x axis and sensitivity on y axis showing linear relationship." alt="line plot with new values on x axis and sensitivity on y axis showing linear relationship." width="100%" height="100%" />
]
--
.pull.right[
<img src="useR-bnmonitor_files/figure-html/sensdicout-1.png" title="line plot with new values on x axis and sensitivity on y axis showing non-linear relationship." alt="line plot with new values on x axis and sensitivity on y axis showing non-linear relationship." width="50%" height="50%" />
]
--
- Both charts show as the probability of having a high level of glucose 🍬 increases 📈, the probability of a positive test increases📈.
- For the conditional probability, the increase is non-linear 🌀 as expected from the results of <a name=cite-Coupe2002></a>[Coupé and Van der Gaag (2002)](#bib-Coupe2002)
???
again the output (conditional) probability of a positive test increases when the probability of a high level of glucose increases. Notice that in this case the increase is non-linear as expected from the results of [Coupé and Van der Gaag (2002)](#bib-Coupe2002) .
---
# CD distance
- How do changes in the probability of high glucose 🍬 affect the overall probability distribution of the BN?
--
- We can check this with the CD distance from <a name=cite-Chan2005></a>[Chan and Darwiche (2005)](#bib-Chan2005)
--
```r
cd_g <- CD(bn,
node = "GLUC",
value_node = "high",
value_parents = NULL,
new_value = "all")
plot(cd_g) +
theme(text=element_text(size=25))
```
---
# CD distance
- How does this compare to the conditional probability of a positive diabetes test given a high body mass index 🏋🏽 and a high glucose 🍬?
```r
cd_d <- CD(bn,
node = "DIAB",
value_node = "pos",
value_parents = c("high","high"),
new_value = "all")
plot(cd_d) +
theme(text=element_text(size=25))
```
---
# CD distance
.pull-left[
Marginal
<img src="useR-bnmonitor_files/figure-html/cdgout-1.png" title="line plot with new values on x axis and CD on y axis. the plot has a sharp vertex around (0.5,0)." alt="line plot with new values on x axis and CD on y axis. the plot has a sharp vertex around (0.5,0)." width="75%" height="65%" />
]
--
.pull-right[
Conditional
<img src="useR-bnmonitor_files/figure-html/cddout -1.png" title="line plot with new values on x axis and CD on y axis. the plot has a sharp vertex just to the left of (0.65,0)." alt="line plot with new values on x axis and CD on y axis. the plot has a sharp vertex just to the left of (0.65,0)." width="75%" height="65%" />
]
--
- Overall the CD distance is smaller for changes conditioned on high BMI 🏋🏽 and high glucose🍬 comparatively.
???
We now might be interested in knowing how much changes in the probability of high glucose affect the overall probability distribution of the BN. We compute the CD distance using the \texttt{CD} function and the associated \texttt{plot} method.
The output is given in Figure \ref{fig:CD1} and one can see that the original value of this probability was around 0.5 since the CD is zero.
As an illustration let's consider the CD distance when the conditional probability of a positive diabetes test given a high body mass index and a high glucose is varied.
The plot is reported in Figure \ref{fig:CD2} and we can notice that overall the CD distance is smaller for changes of this probability compared to the one in Figure \ref{fig:CD1}.
---
# Query probabilities
- Consider probability of positive diabetes test when we have high blood pressure ❣️.
```r
tbl <- querygrain(as.grain(bn),
nodes = c("DIAB","PRES"),
type = "conditional")
```
<table>
<thead>
<tr>
<th style="text-align:left;"> </th>
<th style="text-align:right;"> low </th>
<th style="text-align:right;"> high </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> neg </td>
<td style="text-align:right;"> 0.7338181 </td>
<td style="text-align:right;"> 0.6185608 </td>
</tr>
<tr>
<td style="text-align:left;"> pos </td>
<td style="text-align:right;"> 0.2661819 </td>
<td style="text-align:right;"> 0.3814392 </td>
</tr>
</tbody>
</table>
--
- Suppose we believe this probability should be at least 0.4.
--
- What configurations of conditional probabilities meet this constraint?
---
# Query probabilities
```r
snsqur.diab <- sensquery(bn,
interest_node = "DIAB",
interest_node_value = "pos",
new_value = 0.4,evidence_nodes = "PRES",
evidence_states = "high");
```
<table>
<thead>
<tr>
<th style="text-align:left;"> Node </th>
<th style="text-align:left;"> Value node </th>
<th style="text-align:left;"> Value parents </th>
<th style="text-align:right;"> Original value </th>
<th style="text-align:right;"> Suggested change </th>
<th style="text-align:right;"> CD distance </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> GLUC </td>
<td style="text-align:left;"> low </td>
<td style="text-align:left;"> </td>
<td style="text-align:right;"> 0.4872449 </td>
<td style="text-align:right;"> 0.4409133 </td>
<td style="text-align:right;"> 0.1864248 </td>
</tr>
<tr>
<td style="text-align:left;"> PRES </td>
<td style="text-align:left;"> low </td>
<td style="text-align:left;"> low </td>
<td style="text-align:right;"> 0.6084656 </td>
<td style="text-align:right;"> 0.6993007 </td>
<td style="text-align:right;"> 0.4031032 </td>
</tr>
<tr>
<td style="text-align:left;"> DIAB </td>
<td style="text-align:left;"> pos </td>
<td style="text-align:left;"> low,low </td>
<td style="text-align:right;"> 0.0566038 </td>
<td style="text-align:right;"> 0.1250558 </td>
<td style="text-align:right;"> 0.8680104 </td>
</tr>
<tr>
<td style="text-align:left;"> MASS </td>
<td style="text-align:left;"> high </td>
<td style="text-align:left;"> low </td>
<td style="text-align:right;"> 0.2606383 </td>
<td style="text-align:right;"> 0.4817689 </td>
<td style="text-align:right;"> 0.9696970 </td>
</tr>
<tr>
<td style="text-align:left;"> AGE </td>
<td style="text-align:left;"> low </td>
<td style="text-align:left;"> low,neg </td>
<td style="text-align:right;"> 0.7034483 </td>
<td style="text-align:right;"> 0.9266871 </td>
<td style="text-align:right;"> 1.6731065 </td>
</tr>
</tbody>
</table>
- The function `sensquery` gives us the plausible scenarios.
???
---
# Co-Authors
.pull-left[

### Manuele Leonelli
Assistant Professor
#### IE University, Madrid
Github: [manueleleonelli](https://github.com/manueleleonelli)
]
.pull-right[

### Ramsiya Ramanathan
MSc Data Science Student
#### Università di Bologna, Bologna, Italy
Github: [rramsiya](https://github.com/rramsiya/bnsens)
]
---
# References
<a name=bib-Chan2002></a>[Chan, H. and A. Darwiche](#cite-Chan2002)
(2002). "When do numbers really matter?" In: _Journal of Artificial
Intelligence Research_ 17, pp. 265-287.
<a name=bib-Chan2005></a>[Chan, H. and A. Darwiche](#cite-Chan2005)
(2005). "A distance measure for bounding probabilistic belief change".
In: _International Journal of Approximate Reasoning_ 38.2, pp. 149-174.
<a name=bib-Coupe2002></a>[Coupé, V. M. and L. C. Van der
Gaag](#cite-Coupe2002) (2002). "Properties of sensitivity analysis of
Bayesian belief networks". In: _Annals of Mathematics and Artificial
Intelligence_ 36.4, pp. 323-356.
<a name=bib-Cowell2006></a>[Cowell, R. G., P. Dawid, S. L. Lauritzen,
et al.](#cite-Cowell2006) (2006). _Probabilistic networks and expert
systems: Exact computational methods for Bayesian networks_. Springer
Science & Business Media.
<a name=bib-Cowell2007></a>[Cowell, R. G., R. J. Verrall, and Y.
Yoon](#cite-Cowell2007) (2007). "Modeling operational risk with
Bayesian networks". In: _Journal of Risk and Insurance_ 74.4, pp.
795-827.
<a name=bib-Dawid1992></a>[Dawid, A. P.](#cite-Dawid1992) (1992).
"Prequential data analysis". In: _Lecture Notes-Monograph Series_, pp.
113-126.
<a name=bib-Nojavan2017></a>[Nojavan, F., S. S. Qian, and C. A.
Stow](#cite-Nojavan2017) (2017). "Comparative analysis of
discretization methods in Bayesian networks". In: _Environmental
Modelling & Software_ 87, pp. 64-71.
<a name=bib-radin2017digital></a>[Radin, J.](#cite-radin2017digital)
(2017). "“Digital natives”: How medical and indigenous histories matter
for big data". In: _Osiris_ 32.1, pp. 43-64.
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false,
"css": ["useR", "useR-fonts"]
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>