-
Notifications
You must be signed in to change notification settings - Fork 1
/
bayesian_neuroimaging.html
5463 lines (4871 loc) · 281 KB
/
bayesian_neuroimaging.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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Bayesian analysis of Neuroimaging data with R</title>
<meta charset="utf-8">
<meta name="author" content="Chris Hammill Jason Lerch" />
<meta name="date" content="2018-06-14" />
<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>
<script src="libs/viz/viz.js"></script>
<link href="libs/DiagrammeR-styles/styles.css" rel="stylesheet" />
<script src="libs/grViz-binding/grViz.js"></script>
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# Bayesian analysis of Neuroimaging data with R
### Chris Hammill<br>Jason Lerch
### 2018-06-14
---
<style>
.remark-code {
font-size: 75%;
}
.remark-slide-scaler {
overflow: scroll;
}
.small {
font-size: 65%;
}
.remark-slide-number {
font-size: 10pt;
margin-bottom: -11.6px;
margin-right: 10px;
color: #FFFFFF; /* white */
opacity: 1; /* default: 0.5 */
}
</style>
# Outline
1. Quick overview of algorithms and datasets used today
1. Anatomy and hierarchies
1. Massively univariate classical statistics
1. Meet Reverend Thomas
1. A simple model
1. A more involved model
1. Diagnostics
1. A complex example (if we have time)
1. ...
1. Profit?
---
# Following Along
- To follow along with today's session you will need to either:
- run R with `c("knitr", "tidyverse", "forcats", "ggplot2", "broom", "data.tree", "treemap", "rstanarm", "bayesplot", "pheatmap", "ggrepel")` on your laptop
- use R from our singularity container
---
# Get these slides and code
- From a terminal run:
```bash
git clone https://github.com/Mouse-Imaging-Centre/Scinet-SS-bayesian-neuroimaging-R
cd Scinet-SS-bayesian-neuroimaging-R
## cp in some extra files <use scp if you're working on your own laptop>
cp /bb/scinet/course/ss2018/3_bm/7_mrir/ADNI2_BL_MAGeT_Hippocampus_subfields.csv .
cp /bb/scinet/course/ss2018/3_bm/7_mrir/flathierarchy.Rds .
cp /bb/scinet/course/ss2018/3_bm/7_mrir/twolevelhierarchy.Rds .
```
---
# Singularity set up
- First ssh to niagara and set your port to forward
```bash
ssh -L8787:localhost:<your-port> <you>@niagara.scinet.utoronto.ca
ssh -L<your-port>:localhost:<your-port> tds01
```
- To use the singularity container you will need to set an environment variable with a temporary RStudio password. You will also
need a temporary directory on SCRATCH, this assumes you don't have a directory with this name already
```bash
export RSTUDIO_PASSWORD="dont_use_this_fake_password"
mkdir $SCRATCH/tmp
module load singularity
```
---
# Run the container
- Run the container <this command will remain running>, can be sent to the background
```bash
module load singularity/2.5.1
singularity exec \
--bind /bb/scinet/course/ss2018/3_bm/7_mrir/rstudio_auth.sh:/usr/lib/rstudio-server/bin/rstudio_auth.sh \
--bind $SCRATCH/tmp:/tmp \
--bind $SCRATCH:$SCRATCH \
/bb/scinet/course/ss2018/3_bm/7_mrir/RMINC-develop-2018-06-13-6793fefb8a5a.img \
rserver \
--auth-none 0 \
--auth-pam-helper-path rstudio_auth.sh \
--www-port <your-port>
```
- Then navigate to localhost:8787 in your browser, use your scinet username and `$RSTUDIO_PASSWORD$`
---
# Optional step to compile the slides
- You'll need the package "xaringan" to render the slides
- On singularity this is slightly involved, you'll need a library directory
```r
dir.create("~/tmp_rlibs")
.libPaths(new = "~/tmp_rlibs")
install.packages("xaringan")
```
---
class: middle
# The dataset: ADNI
* baseline scans from ADNI2
* multi-site initiative to study Alzheimer's and Mild Cognitive Impairment
With much gratitude to Nikhil Bhagwat of the CoBrA Lab (PI: Chakravarty) for providing us with processed data.
---
# MAGeT - the algorithm
![MAGeT figure](MAGeT-fig.png)
Chakravarty MM, Steadman P, van Eede MC, Calcott RD, Gu V, Shaw P, Raznahan A, Collins DL, Lerch JP. Performing label-fusion-based segmentation using multiple automatically generated templates. Hum Brain Mapp. 2013 Oct;34(10):2635–54.
---
# MAGeT - the atlas
<img src="hippoatlas.png" width="576" height="400px" />
.small[
Pipitone J, Park MTM, Winterburn J, Lett TA, Lerch JP, Pruessner JC, Lepage M, Voineskos AN, Chakravarty MM, Alzheimer’s Disease Neuroimaging Initiative. Multi-atlas segmentation of the whole hippocampus and subfields using multiple automatically generated templates. Neuroimage. 2014 Nov 1;101:494–512.
Winterburn JL, Pruessner JC, Chavez S, Schira MM, Lobaugh NJ, Voineskos AN, Chakravarty MM. A novel in vivo atlas of human hippocampal subfields using high-resolution 3 T magnetic resonance imaging. Neuroimage. 2013 Jul 1;74:254–65.
]
---
# Load the data
Read in the processed files
```r
suppressMessages(library(tidyverse))
adni <- read.csv("ADNI2_BL_MAGeT_Hippocampus_subfields.csv")
names(adni)
```
```
## [1] "X" "L_CA1" "L_subiculum" "L_CA4DG" "L_CA2CA3"
## [6] "L_stratum" "L_Alv" "L_Fimb" "L_Fornix" "L_Mam"
## [11] "R_CA1" "R_subiculum" "R_CA4DG" "R_CA2CA3" "R_stratum"
## [16] "R_Alv" "R_Fimb" "R_Fornix" "R_Mam" "PTID"
## [21] "VISCODE" "ImageUID" "ORIGPROT" "COLPROT" "AGE"
## [26] "APOE4" "PTGENDER" "DX_bl" "MMSE" "ADAS11"
## [31] "ADAS13"
```
---
#Reorganize the diagnosis label
```r
library(forcats)
adni <- adni %>%
mutate(DX_bl=fct_relevel(DX_bl,
"CN", "SMC", "EMCI", "LMCI", "AD"))
```
---
# Data organization
Make the dataframe long rather than wide
```r
adniLong <- adni %>%
select(-X) %>%
gather(structure, volume, L_CA1:R_Mam)
adniLong %>%
select(PTID, DX_bl, structure, volume) %>% sample_n(5)
```
```
## PTID DX_bl structure volume
## 8863 073_S_4443 EMCI R_CA2CA3 188.39999
## 7152 013_S_4395 LMCI R_subiculum 255.60001
## 3466 137_S_4536 EMCI L_stratum 446.39997
## 6336 002_S_4270 CN R_CA1 642.00003
## 4577 057_S_5295 SMC L_Fimb 86.64124
```
---
# A quick look at the data
```r
library(ggplot2)
ggplot(adniLong) + aes(x=DX_bl, y=AGE) + geom_boxplot()
```
![](bayesian_neuroimaging_files/figure-html/unnamed-chunk-10-1.png)<!-- -->
---
# A quick look at hippocampal volume
```r
adniLong %>% group_by(PTID) %>%
summarize(DX=DX_bl[1], GENDER=PTGENDER[1], HPC=sum(volume)) %>%
ggplot() + aes(DX, HPC, colour=GENDER) + geom_boxplot()
```
![](bayesian_neuroimaging_files/figure-html/unnamed-chunk-11-1.png)<!-- -->
---
# Classic Statistics
1. Decide on model
1. Apply model to every ROI/voxel separately
1. Widen confidence intervals to account for multiple comparisons
---
# map for looping over structures
```r
library(broom)
adniLong %>%
split(.$structure) %>%
map(~lm(volume ~ AGE+PTGENDER+DX_bl, .)) %>%
map_dfr(tidy, .id='roi') %>% head(14)
```
```
## roi term estimate std.error statistic p.value
## 1 L_Alv (Intercept) 196.5742731 29.2852653 6.7123952 3.973773e-11
## 2 L_Alv AGE 2.5174188 0.3956152 6.3633019 3.580089e-10
## 3 L_Alv PTGENDERMale 65.3630633 5.6039202 11.6638106 7.719764e-29
## 4 L_Alv DX_blSMC 16.4673321 9.2922494 1.7721578 7.680579e-02
## 5 L_Alv DX_blEMCI 16.8111358 8.1134240 2.0720149 3.863178e-02
## 6 L_Alv DX_blLMCI 27.8697000 8.3720730 3.3288888 9.178674e-04
## 7 L_Alv DX_blAD 44.5716230 8.5053623 5.2404144 2.126327e-07
## 8 L_CA1 (Intercept) 706.9671959 41.3804715 17.0845612 6.521867e-55
## 9 L_CA1 AGE 0.2790874 0.5590095 0.4992534 6.177587e-01
## 10 L_CA1 PTGENDERMale 87.9815655 7.9184141 11.1110083 1.619634e-26
## 11 L_CA1 DX_blSMC 36.2846228 13.1300726 2.7634747 5.870110e-03
## 12 L_CA1 DX_blEMCI -1.3742345 11.4643766 -0.1198700 9.046207e-01
## 13 L_CA1 DX_blLMCI -29.5212053 11.8298511 -2.4954841 1.280902e-02
## 14 L_CA1 DX_blAD -49.0521356 12.0181907 -4.0814909 4.993610e-05
```
---
# better overview
```r
rTable <- adniLong %>%
split(.$structure) %>%
map(~lm(volume ~ AGE+PTGENDER+DX_bl, .)) %>%
map_dfr(tidy, .id='roi') %>%
filter(startsWith(term, "DX")) %>%
select(roi, term, statistic) %>%
spread(term, statistic)
```
---
# better overview
```r
rTable
```
```
## roi DX_blAD DX_blEMCI DX_blLMCI DX_blSMC
## 1 L_Alv 5.2404144 2.0720149 3.3288888 1.7721578
## 2 L_CA1 -4.0814909 -0.1198700 -2.4954841 2.7634747
## 3 L_CA2CA3 -1.1964159 -0.2493317 -0.9781210 1.2829814
## 4 L_CA4DG -7.0736847 -1.0666621 -4.5515264 1.8258561
## 5 L_Fimb -5.8276864 -1.3677552 -5.1790266 1.0673108
## 6 L_Fornix -0.1788469 1.1224113 -1.1998364 1.6453122
## 7 L_Mam -3.0547427 0.4167804 -0.9110615 1.0460497
## 8 L_stratum -7.5668406 -0.8851018 -4.2477610 2.0285441
## 9 L_subiculum -8.4089152 -1.3472510 -4.6988241 1.4397638
## 10 R_Alv 2.2203457 1.3354607 1.9552464 1.0756636
## 11 R_CA1 -2.3190902 0.2005679 -1.8465551 2.0229622
## 12 R_CA2CA3 -5.0678893 -1.2333109 -2.5235391 0.1698605
## 13 R_CA4DG -4.2709485 -0.4105204 -3.5381430 0.7337568
## 14 R_Fimb -6.0683126 -1.5310185 -4.3249336 -0.1997899
## 15 R_Fornix -1.1565583 0.3071713 -2.3384244 1.1363678
## 16 R_Mam -1.9359947 1.2241687 -0.8748597 1.2207012
## 17 R_stratum -8.1615304 -1.7229391 -4.4048893 0.9723020
## 18 R_subiculum -7.7494464 -1.0529968 -4.5346801 1.7301202
```
---
# better overview
```r
DT::datatable(rTable %>% remove_rownames() %>%
column_to_rownames("roi") %>% round(2), options=list(pageLength=7))
```
<div id="htmlwidget-5e56aa2e737d4c5dc806" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-5e56aa2e737d4c5dc806">{"x":{"filter":"none","data":[["L_Alv","L_CA1","L_CA2CA3","L_CA4DG","L_Fimb","L_Fornix","L_Mam","L_stratum","L_subiculum","R_Alv","R_CA1","R_CA2CA3","R_CA4DG","R_Fimb","R_Fornix","R_Mam","R_stratum","R_subiculum"],[5.24,-4.08,-1.2,-7.07,-5.83,-0.18,-3.05,-7.57,-8.41,2.22,-2.32,-5.07,-4.27,-6.07,-1.16,-1.94,-8.16,-7.75],[2.07,-0.12,-0.25,-1.07,-1.37,1.12,0.42,-0.89,-1.35,1.34,0.2,-1.23,-0.41,-1.53,0.31,1.22,-1.72,-1.05],[3.33,-2.5,-0.98,-4.55,-5.18,-1.2,-0.91,-4.25,-4.7,1.96,-1.85,-2.52,-3.54,-4.32,-2.34,-0.87,-4.4,-4.53],[1.77,2.76,1.28,1.83,1.07,1.65,1.05,2.03,1.44,1.08,2.02,0.17,0.73,-0.2,1.14,1.22,0.97,1.73]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th> <\/th>\n <th>DX_blAD<\/th>\n <th>DX_blEMCI<\/th>\n <th>DX_blLMCI<\/th>\n <th>DX_blSMC<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":7,"columnDefs":[{"className":"dt-right","targets":[1,2,3,4]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[7,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# Frequentist Null Hypothesis Testing
- To form conclusions in frequentism we typically lean on null hypothesis testing.
- Null hypotheses are parameter values for your model you'd like to disprove
- If your statistics (and more extreme statistics) would be very unlikely given your null model
you reject the null hypothesis, and conclude that the null hypothesis is not correct.
- Choosing a threshold for this probability (e.g. 0.05) and rejecting when your p-value
is below the threshold gives you a fixed probability of making a "Type I" error,
which conveniently is equal to your threshold.
- So if we reject all p-values when they are below 0.05 we have a 5% chance of
rejecting when the null model is in fact true.
- If this is confusing, you're not alone, this is very hard to wrap your mind around.
---
# Zoom in on a single structure
```r
adniLong %>%
split(.$structure) %>%
map(~lm(volume ~ AGE+PTGENDER+DX_bl, .)) %>%
first %>%
summary
```
```
##
## Call:
## lm(formula = volume ~ AGE + PTGENDER + DX_bl, data = .)
##
## Residuals:
## Min 1Q Median 3Q Max
## -398.90 -49.05 -7.69 45.79 280.80
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 196.5743 29.2853 6.712 3.97e-11 ***
## AGE 2.5174 0.3956 6.363 3.58e-10 ***
## PTGENDERMale 65.3631 5.6039 11.664 < 2e-16 ***
## DX_blSMC 16.4673 9.2922 1.772 0.076806 .
## DX_blEMCI 16.8111 8.1134 2.072 0.038632 *
## DX_blLMCI 27.8697 8.3721 3.329 0.000918 ***
## DX_blAD 44.5716 8.5054 5.240 2.13e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 73.1 on 696 degrees of freedom
## Multiple R-squared: 0.2577, Adjusted R-squared: 0.2513
## F-statistic: 40.28 on 6 and 696 DF, p-value: < 2.2e-16
```
---
# Interpreting these results
- After fitting our models we're left with:
1. coefficient estimates
1. t-statistics
1. p-values
- We know if our model assumptions are satisfied our t-statistics
have a known distribution.
- From this distribution we can figure out the probability of t-statistics
as large or larger than the one we observed (p-value)
---
# Dealing with Many Tests
- If you're testing a lot of hypotheses, a 5% chance of making a mistake adds up
- After 14 tests you have a better than a 50/50 chance of having made at least one mistake
- How do we control for this?
- Two main approaches Family-Wise Error Rate (FWER) control and False-Discovery Rate (FDR) control.
---
# FWER
- In family-wise error rate control, we try to limit the chance we will at least one
type I error.
- Quite conservative, so in neuroimaging we tend to use False Discovery Rate control.
---
# FDR
- Instead of trying to control our chances of making at least one mistake, let's try to control the
fraction of mistakes we make.
- To do this we employ the Benjamini-Hochberg procedure.
- The Benjamini-Hochberg procedure turns our p-values in q-values. Rejecting all q-values below some
threshold controls the expected number of mistakes.
- For example if we reject all hypotheses with q < 0.05, we expect about 5% of our results to be
false discoveries (type I errors).
- If we have 100's or more tests we can accept a few mistakes in the interest of finding the
important results.
---
# multiple comparisons - omnibus FDR
```r
pTable <- adniLong %>%
split(.$structure) %>%
map(~lm(volume ~ AGE+PTGENDER+DX_bl, .)) %>%
map_dfr(tidy, .id='roi') %>%
filter(startsWith(term, "DX")) %>%
select(roi, term, p.value) %>%
spread(term, p.value) %>%
remove_rownames() %>%
column_to_rownames("roi") %>%
as.matrix()
qTable <- pTable
qTable[,] <- p.adjust(pTable, 'fdr')
```
---
# multiple comparisons - omnibus FDR
```r
qTable
```
```
## DX_blAD DX_blEMCI DX_blLMCI DX_blSMC
## L_Alv 1.913694e-06 0.09933886 3.304323e-03 0.15800049
## L_CA1 1.997444e-04 0.90462074 3.842707e-02 0.01921127
## L_CA2CA3 3.408123e-01 0.86311637 4.042228e-01 0.32715109
## L_CA4DG 5.305411e-11 0.37376998 3.761830e-05 0.14463584
## L_Fimb 8.840563e-08 0.30175056 2.338860e-06 0.37376998
## L_Fornix 8.773547e-01 0.36287262 3.408123e-01 0.19015000
## L_Mam 8.017881e-03 0.75494833 4.350941e-01 0.37376998
## L_stratum 2.186873e-12 0.44355718 1.038839e-04 0.10430127
## L_subiculum 1.682195e-14 0.30501574 2.064548e-05 0.27069092
## R_Alv 7.124433e-02 0.30501574 1.183444e-01 0.37376998
## R_CA1 5.726437e-02 0.87735472 1.423331e-01 0.10430127
## R_CA2CA3 3.715510e-06 0.34081228 3.706287e-02 0.87735472
## R_CA4DG 9.976500e-05 0.75494833 1.628422e-03 0.52953604
## R_Fimb 2.547278e-08 0.23302004 8.394683e-05 0.87735472
## R_Fornix 3.569035e-01 0.82778710 5.658467e-02 0.36168535
## R_Mam 1.198641e-01 0.34081228 4.435572e-01 0.34081228
## R_stratum 5.578523e-14 0.16607426 6.300383e-05 0.40422277
## R_subiculum 7.859835e-13 0.37376998 3.761830e-05 0.16607426
```
---
# Hippocampal anatomical hierarchy
Setting up a simple hierarchy, dividing the hippocampus in grey matter and tracts.
1. Hippocampal Formation
1. Grey Matter
1. CA1
1. CA2/CA3
1. CA4/DG
1. subiculum
1. stratum
1. Mammilary bodies
1. White Matter
1. Alveus
1. Fimbria
1. Fornix
---
# Hippocampal anatomical hierarchy
```r
library(data.tree)
hpc <- Node$new("HPC")
gm <- hpc$AddChild("GM")
ca1 <- gm$AddChild("CA1")
lca1 <- ca1$AddChild("left CA1")
lca1$volumes <- adni$L_CA1
rca1 <- ca1$AddChild("right CA1")
rca1$volumes <- adni$R_CA1
ca23 <- gm$AddChild("CA2CA3")
lca23 <- ca23$AddChild("left CA2CA3")
lca23$volumes <- adni$L_CA2CA3
rca23 <- ca23$AddChild("right CA2CA3")
rca23$volumes <- adni$R_CA2CA3
ca4 <- gm$AddChild("CA4DG")
lca4 <- ca4$AddChild("left CA4DG")
lca4$volumes <- adni$L_CA4DG
rca4 <- ca4$AddChild("right CA4DG")
rca4$volumes <- adni$R_CA4DG
subiculum <- gm$AddChild("subiculum")
lsubiculum <- subiculum$AddChild("left subiculum")
lsubiculum$volumes <- adni$L_subiculum
rsubiculum <- subiculum$AddChild("right subiculum")
rsubiculum$volumes <- adni$R_subiculum
stratum <- gm$AddChild("stratum")
lstratum <- stratum$AddChild("left stratum")
lstratum$volumes <- adni$L_stratum
rstratum <- stratum$AddChild("right stratum")
rstratum$volumes <- adni$R_stratum
mam <- gm$AddChild("Mammillary bodies")
lmam <- mam$AddChild("left Mammillary bodies")
lmam$volumes <- adni$L_Mam
rmam <- mam$AddChild("right Mammillary bodies")
rmam$volumes <- adni$R_Mam
wm <- hpc$AddChild("WM")
alveus <- wm$AddChild("Alveus")
lalveus <- alveus$AddChild("left Alveus")
lalveus$volumes <- adni$L_Alv
ralveus <- alveus$AddChild("right Alveus")
ralveus$volumes <- adni$R_Alv
fimbria <- wm$AddChild("Fimbria")
lfimbria <- fimbria$AddChild("left Fimbria")
lfimbria$volumes <- adni$L_Fimb
rfimbria <- fimbria$AddChild("right Fimbria")
rfimbria$volumes <- adni$R_Fimb
fornix <- wm$AddChild("Fornix")
lfornix <- fornix$AddChild("left Fornix")
lfornix$volumes <- adni$L_Fornix
rfornix <- fornix$AddChild("right Fornix")
rfornix$volumes <- adni$R_Fornix
```
---
# Hippocampal anatomical hierarchy
```r
hpc
```
```
## levelName
## 1 HPC
## 2 ¦--GM
## 3 ¦ ¦--CA1
## 4 ¦ ¦ ¦--left CA1
## 5 ¦ ¦ °--right CA1
## 6 ¦ ¦--CA2CA3
## 7 ¦ ¦ ¦--left CA2CA3
## 8 ¦ ¦ °--right CA2CA3
## 9 ¦ ¦--CA4DG
## 10 ¦ ¦ ¦--left CA4DG
## 11 ¦ ¦ °--right CA4DG
## 12 ¦ ¦--subiculum
## 13 ¦ ¦ ¦--left subiculum
## 14 ¦ ¦ °--right subiculum
## 15 ¦ ¦--stratum
## 16 ¦ ¦ ¦--left stratum
## 17 ¦ ¦ °--right stratum
## 18 ¦ °--Mammillary bodies
## 19 ¦ ¦--left Mammillary bodies
## 20 ¦ °--right Mammillary bodies
## 21 °--WM
## 22 ¦--Alveus
## 23 ¦ ¦--left Alveus
## 24 ¦ °--right Alveus
## 25 ¦--Fimbria
## 26 ¦ ¦--left Fimbria
## 27 ¦ °--right Fimbria
## 28 °--Fornix
## 29 ¦--left Fornix
## 30 °--right Fornix
```
---
# Hippocampal anatomical hierarchy
```r
SetGraphStyle(hpc, rankdir="LR")
plot(hpc)
```
<div id="htmlwidget-ad8109ac80e4352e3d65" style="width:720px;height:432px;" class="grViz html-widget"></div>
<script type="application/json" data-for="htmlwidget-ad8109ac80e4352e3d65">{"x":{"diagram":"digraph {\n\ngraph [rankdir = \"LR\"]\n\n\n\n \"1\" [label = \"HPC\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"2\" [label = \"GM\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"3\" [label = \"CA1\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"4\" [label = \"left CA1\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"5\" [label = \"right CA1\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"6\" [label = \"CA2CA3\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"7\" [label = \"left CA2CA3\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"8\" [label = \"right CA2CA3\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"9\" [label = \"CA4DG\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"10\" [label = \"left CA4DG\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"11\" [label = \"right CA4DG\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"12\" [label = \"subiculum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"13\" [label = \"left subiculum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"14\" [label = \"right subiculum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"15\" [label = \"stratum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"16\" [label = \"left stratum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"17\" [label = \"right stratum\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"18\" [label = \"Mammillary bodies\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"19\" [label = \"left Mammillary bodies\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"20\" [label = \"right Mammillary bodies\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"21\" [label = \"WM\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"22\" [label = \"Alveus\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"23\" [label = \"left Alveus\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"24\" [label = \"right Alveus\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"25\" [label = \"Fimbria\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"26\" [label = \"left Fimbria\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"27\" [label = \"right Fimbria\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"28\" [label = \"Fornix\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"29\" [label = \"left Fornix\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"30\" [label = \"right Fornix\", fillcolor = \"#FFFFFF\", fontcolor = \"#000000\"] \n \"1\"->\"2\" \n \"1\"->\"21\" \n \"2\"->\"3\" \n \"2\"->\"6\" \n \"2\"->\"9\" \n \"2\"->\"12\" \n \"2\"->\"15\" \n \"2\"->\"18\" \n \"21\"->\"22\" \n \"21\"->\"25\" \n \"21\"->\"28\" \n \"3\"->\"4\" \n \"3\"->\"5\" \n \"6\"->\"7\" \n \"6\"->\"8\" \n \"9\"->\"10\" \n \"9\"->\"11\" \n \"12\"->\"13\" \n \"12\"->\"14\" \n \"15\"->\"16\" \n \"15\"->\"17\" \n \"18\"->\"19\" \n \"18\"->\"20\" \n \"22\"->\"23\" \n \"22\"->\"24\" \n \"25\"->\"26\" \n \"25\"->\"27\" \n \"28\"->\"29\" \n \"28\"->\"30\" \n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
---
# Aggregate up the tree
```r
hpc$Do(function(x){
x$volumes <- Aggregate(x, "volumes", rowSums)
}, traversal="post-order", filterFun=isNotLeaf)
hpc$Do(function(x) {
x$meanVolume <- mean(x$volumes)
})
```
---
# Tree graph
```r
library(treemap)
ToDataFrameTable(hpc, "pathString", "meanVolume", "name") %>%
mutate(path=strsplit(pathString, "/"),
struct=map_chr(path, ~ .x[3]),
tissue=map_chr(path, ~ .x[2])) %>%
select(struct, tissue, name, meanVolume) %>%
treemap(index=c("tissue", "struct"), vSize="meanVolume")
```
![](bayesian_neuroimaging_files/figure-html/unnamed-chunk-23-1.png)<!-- -->
---
# Statistics on the tree
```r
hpc$Do(function(x){
adni$volumes <- x$volumes
x$stats <-
lm(volumes ~ AGE+PTGENDER+DX_bl, adni) %>%
tidy() %>%
filter(startsWith(term, "DX")) %>%
select(term, estimate, statistic, p.value)
})
```
---
# Statistics on the tree
```r
print(hpc, AD=function(x)
x$stats %>% filter(term=="DX_blAD") %>% select(statistic) )
```
```
## levelName AD
## 1 HPC -4.5728017
## 2 ¦--GM -6.4256670
## 3 ¦ ¦--CA1 -3.2923199
## 4 ¦ ¦ ¦--left CA1 -4.0814909
## 5 ¦ ¦ °--right CA1 -2.3190902
## 6 ¦ ¦--CA2CA3 -3.5392995
## 7 ¦ ¦ ¦--left CA2CA3 -1.1964159
## 8 ¦ ¦ °--right CA2CA3 -5.0678893
## 9 ¦ ¦--CA4DG -5.9874539
## 10 ¦ ¦ ¦--left CA4DG -7.0736847
## 11 ¦ ¦ °--right CA4DG -4.2709485
## 12 ¦ ¦--subiculum -8.6168787
## 13 ¦ ¦ ¦--left subiculum -8.4089152
## 14 ¦ ¦ °--right subiculum -7.7494464
## 15 ¦ ¦--stratum -8.2297918
## 16 ¦ ¦ ¦--left stratum -7.5668406
## 17 ¦ ¦ °--right stratum -8.1615304
## 18 ¦ °--Mammillary bodies -2.6843408
## 19 ¦ ¦--left Mammillary bodies -3.0547427
## 20 ¦ °--right Mammillary bodies -1.9359947
## 21 °--WM 0.7325428
## 22 ¦--Alveus 4.1207504
## 23 ¦ ¦--left Alveus 5.2404144
## 24 ¦ °--right Alveus 2.2203457
## 25 ¦--Fimbria -6.5869583
## 26 ¦ ¦--left Fimbria -5.8276864
## 27 ¦ °--right Fimbria -6.0683126
## 28 °--Fornix -0.6995234
## 29 ¦--left Fornix -0.1788469
## 30 °--right Fornix -1.1565583
```
---
# Statistics on the tree
```r
print(hpc, AD=function(x)
x$stats %>% filter(term=="DX_blAD") %>%
select(statistic),
filterFun=isNotLeaf )
```
```
## levelName AD
## 1 HPC -4.5728017
## 2 ¦--GM -6.4256670
## 3 ¦ ¦--CA1 -3.2923199
## 4 ¦ ¦--CA2CA3 -3.5392995
## 5 ¦ ¦--CA4DG -5.9874539
## 6 ¦ ¦--subiculum -8.6168787
## 7 ¦ ¦--stratum -8.2297918
## 8 ¦ °--Mammillary bodies -2.6843408
## 9 °--WM 0.7325428
## 10 ¦--Alveus 4.1207504
## 11 ¦--Fimbria -6.5869583
## 12 °--Fornix -0.6995234
```
---
# Statistics on the tree
```r
hpc$Do(function(x){
x$ad <- -log10(x$stats %>% filter(term=="DX_blAD") %>%
select(p.value))
})
ToDataFrameTable(hpc, "pathString", "meanVolume", "name", "ad") %>%
mutate(path=strsplit(pathString, "/"),
struct=map_chr(path, ~ .x[3]),
tissue=map_chr(path, ~ .x[2])) %>%
select(struct, tissue, name, meanVolume, ad) %>%
treemap(index=c("tissue", "struct"), vSize="meanVolume",
vColor="ad", type="value")
```
![](bayesian_neuroimaging_files/figure-html/unnamed-chunk-27-1.png)<!-- -->
---
class: center
# And now for Bayesianism!
---
# Why Bayesian Statistics?
Have you ever...
1. Been confused about what a p-value means?
1. Been frustrated that a difference in significance doesn't mean a significant difference?
1. Known some values for a parameter are impossible but been unable to use that to your advantage?
1. Wanted to ask more interesting questions than whether or not a parameter is or isn't zero?
1. Wanted to use information from the literature to improve your estimates?
---
# Why Bayesian Statistics?
Have you ever...
1. Been confused about what a p-value means?
1. Been frustrated that a difference in significance doesn't mean a significant difference?
1. Known some values for a parameter are impossible but been unable to use that to your advantage?
1. Wanted to ask more interesting questions than whether or not a parameter is or isn't zero?
1. Wanted to use information from the literature to improve your estimates?
Then Bayesian statistics might be right for you!
---
## How you ask?
1. **De-emphasize binary descisions.**
Bayesians avoid null hypothesis tests, instead focusing on estimating their parameters of
interest, and reporting their uncertainty.
1. **Posterior Distributions**
Bayesian analyses produce a distribution of possible parameter values (the posterior), that
can be used to ask many interesting questions about values. E.g. what is the probability the
effect in the hippocampus is larger than the effect in the anterior cingulate cortex.
1. **Prior Information**
Bayesian analyses can use prior information. Bayesian analysis requires an *a priori* assessment
of how likely certain parameters are. This can be vague (uninformative) or can precise (informative)
and steer your analysis away from nonsensical results.
---
class: center
# Meet The Reverend
Reverend Thomas Bayes
![](Thomas_Bayes.gif)
---
class: middle
## Bayes' Theorem
- Bayes noticed this useful property for the probabilities for two events "A" and "B"
$$ \color{red}{P(A | B)} = \frac{{\color{blue}{P(B | A)}\color{orange}{P(A)}}}{\color{magenta}{P(B)}} $$
- `\(\color{red}{P(A|B)}\)`: The probability of A given that B happened
- `\(\color{blue}{P(B|A)}\)`: The probability of B given that A happened
- `\(\color{orange}{P(A)}\)`: The probability of A
- `\(\color{magenta}{P(B)}\)`: the probability of B
- Bayes did this in the context of the binomial distribution
---
class: middle
# But who's that behind him!
---
class: center
# It's Pierre-Simon Laplace
![](Pierre-Simon-Laplace.jpg)
---
## Bayesian Statistics
- Laplace generalized Bayes Theorem into it's modern form. While working on sex-ratios in French births.
- For light reading on the history of bayesianism consider reading [the theory that would not die](https://yalebooks.yale.edu/book/9780300188226/theory-would-not-die)
## Bayes in brief
- Start with some parameters `\(\theta\)`
- Collect some data `\(D\)`
- And deduce the probability of different values of `\(\theta\)` given that you observed `\(D\)`
- Key difference between Bayesianism and Frequentism is that view that `\(\theta\)` has an associated
probability distribution. In frequentism `\(\theta\)` is an unknown constant.
---
# Different Probabilities
- Frequentists believe that probabilities represent the long-run proportion of events
- Under this model `\(P(\theta)\)` doesn't make much sense.
- Ramsey and DeFinetti showed that probability can also represent degree of belief.
- Under this model `\(P(\theta)\)` is an assesment of what you think the the parameter will be.
- For some of the philosophy underpinning bayesian reasoning consider reading
[Bayesian philosophy of science](http://www.laeuferpaar.de/Papers/BookFrame_v1.pdf)
---
class: middle
# Bayes' Theorem Redux
$$ \color{red}{P(\theta | D)} = \frac{{\color{blue}{P(D | \theta)}\color{orange}{P(\theta)}}}{\color{magenta}{\int P(D | \theta)P(\theta)d\theta}} $$
**Posterior**: `\(\color{red}{P(\theta|D)}\)`:
the probability of our parameters given our data
**Likelihood**: `\(\color{blue}{P(D|\theta)}\)`
The probability of our data given our parameters
**Prior**: `\(\color{orange}{P(\theta)}\)`
The probability of our parameters before we saw the data
**Normalizing Constant**: `\(\color{magenta}{\int P(D | \theta)P(\theta)d\theta}\)`
The probability of the data averaged over all possible parameter sets
---
class: middle
# Bayes' Theorem Redux
$$ \color{red}{P(\theta | D)} \propto \color{blue}{P(D | \theta)}\color{orange}{P(\theta)}$$
**Posterior**: `\(\color{red}{P(\theta|D)}\)`:
the probability of our parameters given our data
**Likelihood**: `\(\color{blue}{P(D|\theta)}\)`
The probability of our data given our parameters
**Prior**: `\(\color{orange}{P(\theta)}\)`
The probability of our parameters before we saw the data
---
class: middle
# Bayes' Theorem Redux
$$ \color{red}{P(\theta | D)} \propto \color{orange}{P(\theta)}\color{blue}{P(D | \theta)}$$
**Posterior**: `\(\color{red}{P(\theta|D)}\)`:
the probability of our parameters given our data
**Prior**: `\(\color{orange}{P(\theta)}\)`
The probability of our parameters before we saw the data
**Likelihood**: `\(\color{blue}{P(D|\theta)}\)`
The probability of our data given our parameters
**Pardon the re-ordering**
---
class: middle
# Posterior
`\(\color{red}{P(\theta|D)}\)`
- The goal of bayesian statistics
- The posterior is probability distribution over parameters.
- Depends on the data we observed.
- Can be used to answer interesting questions. For
example how likely is an effect between two biologically meaninful boundaries.
---
class: middle
# Prior
`\(\color{orange}{P(\theta)}\)`
- This is what we knew before the experiment.
- The prior is also a probability distribution over parameters.
- Doesn't depend on the data we saw.
- Gives a probability for any value the parameters could take.
---
class: middle
# Likelihood
`\(\color{blue}{P(D | \theta)}\)`
- This is how probable our data is given a hypothetical parameter set
- The likelihood is a probability distribution over data (not parameters)
- Is still a function of parameters.
---