forked from elalilab/Stroke_PDGFR-B_Reactivity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.qmd
2000 lines (1592 loc) · 54.2 KB
/
Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title-block-banner: true
title: "Analysis of PDGFRβ attachment to vasculature (CD31+)"
subtitle: "Data analysis notebook"
date: today
date-format: full
author:
- name: "Daniel Manrique-Castano"
orcid: 0000-0002-1912-1764
degrees:
- PhD
affiliation:
- name: Univerisity Laval
department: Psychiatry and Neuroscience
group: Laboratory of neurovascular interactions
note: "GitHub: https://daniel-manrique.github.io/"
keywords:
- PDGFRβ
- Brain vasculature
- Brain injury
- Bayesian modeling
license: "CC BY"
format:
pdf:
toc: true
number-sections: true
colorlinks: true
html:
code-fold: true
embed-resources: true
toc: true
toc-depth: 2
toc-location: left
number-sections: true
theme: spacelab
knitr:
opts_chunk:
warning: false
message: false
csl: science.csl
bibliography: references.bib
editor:
markdown:
wrap: 72
---
# Preview
This notebook reports the analysis of PDGFRβ localization in the
vasculature in defined ROIs (injured cortex and striatum, and
perilesional cortex).
**Parent dataset:** CD31 and PDGFRβ stained ROIs imaged at 10x using
widefield microscopy. These data set contain three major groups. First,
animals with cortico-striatal injuries grouped at 0 (sham), 3, 7, 14,
and 30 days post-ischemia (DPI). Second, animals with striatal injuries
at 14 and 30 DPI; and finally, a group of sham animals scarified at
during the time course to control for protein recombination after
tamoxifen injection. The raw images and pre-processing scripts (if
applicable) are available at the Zenodo repository
(10.5281/zenodo.10553084) under the name
`Widefield_10x_ROIs_CD31-Pdgfrb.zip`.
**Working dataset**: The
`Data_Raw/Raw_Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.csv`data frame
containing the raw output from CellProfiller [@stirling2021]. The
pipeline used to perform PDGFRβ/CD31 colocalization is available at
https://osf.io/6ec89/.
We perform scientific inference based on the ratio of PDGFRβ cells
attached to the brain vasculature stained with CD31.
# Install and load required packages
Install and load all required packages. Please uncomment (delete #) the
line code if installation is required. Load the installed libraries each
time you start a new R session.
```{r}
#| label: Install_Packages
#| include: true
#| warning: false
#| message: false
#install.packages("devtools")
#library(devtools)
#install.packages(c("bayesplot", "bayestestR", "brms","dplyr", "easystats", "emmeans", "ggplot","gtsummary", "modelr", "modelsummary", "patchwork", "poorman", "tidybayes", "tidyverse", "viridis"))
library(bayesplot)
library(bayestestR)
library(brms)
library(dplyr)
library(easystats)
library(emmeans)
library(ggplot2)
library(gtsummary)
library(modelr)
library(modelsummary)
library(patchwork)
library(poorman)
library(plyr)
library(tidybayes)
library(tidyverse)
library(viridis)
```
# Visual themes
We create a visual theme to use in our plots (ggplots).
```{r}
#| label: Plot_Theme
#| include: true
#| warning: false
#| message: false
Plot_theme <- theme_classic() +
theme(
plot.title = element_text(size=18, hjust = 0.5, face="bold"),
plot.subtitle = element_text(size = 10, color = "black"),
plot.caption = element_text(size = 12, color = "black"),
axis.line = element_line(colour = "black", size = 1.5, linetype = "solid"),
axis.ticks.length=unit(7,"pt"),
axis.title.x = element_text(colour = "black", size = 16),
axis.text.x = element_text(colour = "black", size = 16, angle = 0, hjust = 0.5),
axis.ticks.x = element_line(colour = "black", size = 1),
axis.title.y = element_text(colour = "black", size = 16),
axis.text.y = element_text(colour = "black", size = 16),
axis.ticks.y = element_line(colour = "black", size = 1),
legend.position="right",
legend.direction="vertical",
legend.title = element_text(colour="black", face="bold", size=12),
legend.text = element_text(colour="black", size=10),
plot.margin = margin(t = 10, # Top margin
r = 2, # Right margin
b = 10, # Bottom margin
l = 10) # Left margin
)
```
# Load and handle the datasets
We load the `Data_Raw/Raw_Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.csv` raw
data set to obtain the variables of interest.
```{r}
#| label: Pdgfr_CD31_Load_ROIs10x
#| include: true
#| warning: false
#| message: false
Pdgfrb_CD31_Raw <- read.csv (file = "Data_Raw/Widefield_10x_ROIs_CD31-Pdgfrb/Raw_Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.csv", header = TRUE)
# Eliminate unnecessary columns
Pdgfrb_CD31_Coloc <- subset(Pdgfrb_CD31_Raw, select = c(Count_Colocalization, Count_PDGFR_PrimaryObjects, FileName_PDGFR))
# Extract metadata information from image name
Pdgfrb_CD31_Coloc <- cbind(Pdgfrb_CD31_Coloc, do.call(rbind , strsplit(Pdgfrb_CD31_Coloc$FileName_PDGFR, "[_\\.]"))[,1:5])
# Eliminate File_Name column
Pdgfrb_CD31_Coloc <- subset(Pdgfrb_CD31_Coloc, select = -c(FileName_PDGFR))
# Change column names
colnames(Pdgfrb_CD31_Coloc) <- c("Pdgfrb_Perivascular", "Pdgfrb_Total", "AnimalID", "DPI", "Condition", "Lesion", "Region")
# Reordering the table
Pdgfrb_CD31_Coloc <- subset(Pdgfrb_CD31_Coloc, select = c("AnimalID", "DPI", "Condition", "Lesion", "Region", "Pdgfrb_Perivascular", "Pdgfrb_Total"))
# Create the variable for parenchymal cells
Pdgfrb_CD31_Coloc$Pdgfrb_Parenchymal <- Pdgfrb_CD31_Coloc$Pdgfrb_Total - Pdgfrb_CD31_Coloc$Pdgfrb_Perivascular
# Setting factors
Pdgfrb_CD31_Coloc$DPI <- factor(Pdgfrb_CD31_Coloc$DPI, levels = c("3D", "7D", "14D", "30D"))
Pdgfrb_CD31_Coloc$Region <- factor(Pdgfrb_CD31_Coloc$Region, levels = c("Peri", "Str", "Ctx"))
Pdgfrb_CD31_Coloc$Condition <- factor(Pdgfrb_CD31_Coloc$Condition, levels = c("Sham", "MCAO"))
Pdgfrb_CD31_Coloc$Lesion <- factor(Pdgfrb_CD31_Coloc$Lesion, levels = c("L0", "L1", "L2"))
# Create an additional DPI variable (numeric)
DPI_mapping <- c("0D" = "0", "3D" = "3", "7D" = "7", "14D" = "14", "30D" = "30")
Pdgfrb_CD31_Coloc$DPI2 <- as.numeric(DPI_mapping[as.character(Pdgfrb_CD31_Coloc$DPI)])
write.csv(Pdgfrb_CD31_Coloc, "Data_Processed/Widefield_10x_ROIs_CD31-Pdgfrb/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc.csv", row.names = FALSE)
```
We save the `Wide10x_ROIs_CD31-Pdgfrb_Coloc.csv` containing the
following variables:
- **AnimalID**: Unique animal identification
- **DPI**: Days post-ischemia with factor levels (3D, 7D, 14D, 30D)
- **Condition**: MCAO = Animals submitted to middle cerebral artery
occlusion. Sham = Healthy animals. For Sham animals, DPI equalizes
time of tamoxifen recombination to MCAO animals.
- **Lesion**: Lesion type. L0 = No lesion. L1 = Cortico-striatal
lesion. L2 = Striatal-only lesion.
- **Region**: Brain region where imaging was performed. Ctx = Cortex
(injured). Str = Striaum (injured). Peri = Perilesion (healthy).
- **Pdgfr_Perivascular**: PDGFRβ+ cells attached (colocalizing) with
CD31 (blood vessels)
- **Pdgfr_Total**: Total number of PDGFRβ+ cells.
- **Pdgfr_Parenchymal**: PDGFRβ+ cells not attached (colocalizing)
with CD31 (blood vessels)
- **DPI2**: Days-post ischemia as continuous (nemeric variable)
# Analysis of of PDGFRβ-CD31 colocalization in cortico-striatal lesions
First, our objective is to analyze the proportion of PDGFRβ/CD31
colocalization in animals with cortico-striatal lesions. To facilitate
the modeling and visualization of results using a binominal
distribution, we fit different models per brain region (Cortex, striatum
and perilesion).
## Analysis of PDGFRβ-CD31 colocalization in the cortex
We subset the dataset to exclude sham mice and animals with only
striatal injuries.
```{r}
#| label: Pdgfrb_CD31_MCAOData
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
Pdgfrb_CD31_CtxMCAO <- filter(Pdgfrb_CD31_Coloc, Lesion == "L1", Region == "Ctx")
```
### Exploratory data visualization
We visualize the number of parenchymal PDGFRβ+ cells in the injured
cortex.
```{r}
#| label: fig-Pdgfrb_CtxMCAO_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for PDGFRβ/CD31 colocalization
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Pdgfrb_Parenchymal_10x <-
ggplot(
data = Pdgfrb_CD31_CtxMCAO,
aes(x = DPI2,
y = Pdgfrb_Parenchymal)) +
geom_smooth(
method = "lm",
se = TRUE,
color = "black") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 2),
color = "darkred") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 3),
color = "darkgreen") +
geom_jitter(
width = 0.5,
shape = 1,
size = 1.5,
color = "black") +
scale_y_continuous(name= expression("Number of parenchymal PDGFRβ cells")) +
scale_x_continuous(name="Days post-ischemia (DPI) ",
breaks=c(0, 3, 7,14,30)) +
Plot_theme
Pdgfrb_Parenchymal_10x
```
@fig-Pdgfrb_CtxMCAO_Exploratory shows that the number of parenchymal
cells strongly increases in the cortex after 3 Days post ischemia and
seem the remain constant over time. However, to gain a more
comprehensive picture, we will model the number of parenchymal PDGFRβ
cells conditional on the total number of cells.
### Statistical modeling
We will fit a linear and a non-linear Bayesian model using a binomial
distribution to predict the proportion of parenchymal PDGFRβ cells by
DPI.
- **Pdgfr_CtxMCAO_Mdl1** DPI as a linear predictor of PDGFRβ, with
the following notation:
$$
P(Parenchymal | Total) \sim Binomial(n = Total, p) \\
\text{logit}(P(Y -1)) = \beta*0 +* \beta{DPI} \times DPI
$$
Where $Y$ represents the occurrence of parenchymal cells, $P(Y=1)$ is
the probability of observing parenchymal cells, $\beta_0$ is the
intercept, and $\beta_{DPI}$ is the coefficient for the effect of DPI on
the log-odds of observing parenchymal cells.
Next, we incorporate a smooth term for DPI, allowing a non-linear
relationship between DPI and the log-odds of observing parenchymal cells
within the total number fo cells. The use of a smoothing function with k
= 4 represents a flexible, spline-based curve to model this
relationship:
- **Pdgfr_CtxMCAO_Mdl2** Splines model on DPI, with the following
notation:
$$
Parenchymal | Total \sim Binomial(p) \\
\text{logit}(p) = s(DPI2, k = 4)
$$
Both models use default `brms` flat priors.
#### Fit the models
```{r}
#| label: Pdgfrb_CtxMCAO_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
# Model 1: DPI as a single predictor
Pdgfrb_CtxMCAO_Mdl1 <- bf(Pdgfrb_Parenchymal | trials(Pdgfrb_Total) ~ DPI2)
get_prior(Pdgfrb_CtxMCAO_Mdl1, Pdgfrb_CD31_CtxMCAO, family = binomial())
# Fit model 1
Pdgfrb_CtxMCAO_Fit1 <-
brm(
data = Pdgfrb_CD31_CtxMCAO,
family = binomial(),
formula = Pdgfrb_CtxMCAO_Mdl1,
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_CtxMCAO_Fit1.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_CtxMCAO_Fit1 <-
add_criterion(Pdgfrb_CtxMCAO_Fit1, c("loo", "waic", "bayes_R2"))
# Model 2: DPI with splines
Pdgfrb_CtxMCAO_Mdl2 <- bf(Pdgfrb_Parenchymal | trials(Pdgfrb_Total) ~ s(DPI2, k = 4))
get_prior(Pdgfrb_CtxMCAO_Mdl2, Pdgfrb_CD31_CtxMCAO, family = binomial())
# Fit model 2
Pdgfrb_CtxMCAO_Fit2 <-
brm(
data = Pdgfrb_CD31_CtxMCAO,
family = binomial(),
formula = Pdgfrb_CtxMCAO_Mdl2,
knots = list(DPI = c(3, 7, 14, 30)),
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_CtxMCAO_Fit2.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_CtxMCAO_Fit2 <-
add_criterion(Pdgfrb_CtxMCAO_Fit2, c("loo", "waic", "bayes_R2"))
```
#### Model comparison
We compare the fitted models using WAIC.
```{r}
#| label: Pdgfrb_CtxMCAO_Compare
#| include: true
#| warning: false
#| message: false
#| results: false
Pdgfrb_CtxMCAO_Comp <-
compare_performance(
Pdgfrb_CtxMCAO_Fit1,
Pdgfrb_CtxMCAO_Fit2
)
Pdgfrb_CtxMCAO_Comp
```
Let's see it in graphical terms:
```{r}
#| label: fig-Pdgfrb_CtxMCAO_Compare
#| include: true
#| warning: false
#| message: false
#| results: false
#| #| fig-cap: Model coparison for PDGFRβ/CD31 colocalization
#| fig-width: 5
#| fig-height: 4
Pdgfrb_CtxMCAO_W <-
loo_compare(
Pdgfrb_CtxMCAO_Fit1,
Pdgfrb_CtxMCAO_Fit2,
criterion = "waic")
# Generate WAIC graph
Pdgfrb_CtxMCAO_WAIC <-
Pdgfrb_CtxMCAO_W[, 7:8] %>%
data.frame() %>%
rownames_to_column(var = "model_name") %>%
ggplot(
aes(x = model_name,
y = waic,
ymin = waic - se_waic,
ymax = waic + se_waic)
) +
geom_pointrange(shape = 21) +
scale_x_discrete(
breaks=c("Pdgfrb_CtxMCAO_Fit1",
"Pdgfrb_CtxMCAO_Fit2"),
labels=c("Mdl1",
"Mdl2")) +
coord_flip() +
labs(x = "",
y = "WAIC (score)",
title = "") +
Plot_theme
Pdgfrb_CtxMCAO_WAIC
```
The graph shows the model with splines is far less penalized that the
linear model. This offer us good support to continue inference using the
model with splines.
#### Model diagnostics
We check the model fitting using posterior predictive checks
```{r}
#| label: Pdgfrb_CtxMCAO_Diagnistics
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model diagnostics for PDGFRβ/CD31 colocalization (Cortex)
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Pdgfrb_CtxMCAO_Fit2_pp <-
brms::pp_check(Pdgfrb_CtxMCAO_Fit2,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Formula: PDGFR_Parenchymal | PDGFR_Total ~ s(DPI, k = 4)") +
Plot_theme
Pdgfrb_CtxMCAO_Fit2_pp
```
The predictions follow the same pattern that the observed data. However,
we can appreciate a moderate deviation in the density of the peak about
200. Nonetheless, considering the R2 = 0.83 from this model, we believe
it has a good prediction accuracy.
```{r}
#| label: Pdgfrb_CtxMCAO_Shiny
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model diagnostics for PDGFRβ/CD31 colocalization
#| fig-height: 4
#| fig-width: 5
#launch_shinystan(Pdgfrb_CtxMCAO_Fit2)
```
### Model results
#### Visualization of conditional effects
We use the `conditiona_effects` function to see the posterior
distribution:
```{r}
#| label: fig-Pdgfrb_CtxMCAO_CE
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Posterior distribution for PDGFRβ/CD31 colocalization
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
# We create the graph for convex hull
Pdgfrb_CtxMCAO_DPI <-
conditional_effects(Pdgfrb_CtxMCAO_Fit2)
Pdgfrb_CtxMCAO_DPI <- plot(Pdgfrb_CtxMCAO_DPI,
plot = FALSE)[[1]]
Pdgfrb_CtxMCAO_fig <- Pdgfrb_CtxMCAO_DPI +
scale_y_continuous(name = expression ("(P) parenchymal PDGFRβ")) +
scale_x_continuous(name="DPI" ,
breaks = c(3, 10, 20, 30),
labels = c("3", "10", "20", "30")) +
Plot_theme +
theme(legend.position = "top", legend.direction = "horizontal")
ggsave(
plot = Pdgfrb_CtxMCAO_fig,
filename = "Plots/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_CtxMCAO_Fit2.png",
width = 9,
height = 9,
units = "cm")
Pdgfrb_CtxMCAO_fig
```
@fig-Pdgfrb_CtxMCAO_CE show an increasing probability for parenchymal
PDGFRβ+ cells with a peak during the second week post injury, and a
higher uncertainty thereafter.
#### Posterior summary
Next, We plot the posterior summary using the `describe_posterior`
function:
```{r}
#| label: Pdgfrb_CtxMCAO_Posterior
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
describe_posterior(
Pdgfrb_CtxMCAO_Fit2,
effects = "all",
test = c("p_direction", "rope"),
component = "all",
centrality = "median")
modelsummary(Pdgfrb_CtxMCAO_Fit2,
shape = term ~ model + statistic,
centrali2ty = "mean",
title = "PDGFRβ+ parenchymal cells following MCAO",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "Tables/html/Widefield_10x_ROIs_CD31-Pdgfrb_Ctx_Fit2_Table.html",
)
Pdgfrb_CtxMCAO_Fit2_Table <- modelsummary(Pdgfrb_CtxMCAO_Fit2,
shape = term ~ model + statistic,
centrality = "mean",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "gt")
gt::gtsave (Pdgfrb_CtxMCAO_Fit2_Table,
filename = "Tables/tex/Widefield_10x_ROIs_CD31-Pdgfrb_Ctx_Fit2_Table.tex")
```
Please note that we are unable to calculate derivatives for binomial
models.
## Analysis of PDGFRβ-CD31 colocalization in the striatum
We perform the same analysis for the injured striatum. As done before,
we filter the data set to select relevant ROIs.
```{r}
#| label: Pdgfrb_StrMCAO
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
Pdgfrb_CD31_StrMCAO <- filter(Pdgfrb_CD31_Coloc, Lesion == "L1", Region == "Str")
```
### Exploratory data visualization
We visualize the number of parenchymal PDGFRβ+ cells in the injured
striatum.
```{r}
#| label: fig-Pdgfrb_StrMCAO_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for PDGFRβ/CD31 colocalization
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Pdgfrb_Parenchymal_10x <-
ggplot(
data = Pdgfrb_CD31_StrMCAO,
aes(x = DPI2,
y = Pdgfrb_Parenchymal)) +
geom_smooth(
method = "lm",
se = TRUE,
color = "black") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 2),
color = "darkred") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 3),
color = "darkgreen") +
geom_jitter(
width = 0.5,
shape = 1,
size = 1.5,
color = "black") +
scale_y_continuous(name= expression("Number of parenchymal PDGFRβ cells")) +
scale_x_continuous(name="Days post-ischemia (DPI) ",
breaks=c(0, 3, 7,14,30)) +
Plot_theme
Pdgfrb_Parenchymal_10x
```
In this case, we see that linear and non-linear models are close.
However, we fit a splines model for consistency.
### Statistical modeling
We reproduce the same same approach employed with the cortex. This time
we focus exclusively in the model with splines.
#### Fit the model
```{r}
#| label: Pdgfrb_StrMCAO_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
set.seed(8807)
# Model 2: DPI with splines
Pdgfrb_StrMCAO_Mdl2 <- bf(Pdgfrb_Parenchymal | trials(Pdgfrb_Total) ~ s(DPI2, k = 4))
get_prior(Pdgfrb_StrMCAO_Mdl2, Pdgfrb_CD31_StrMCAO, family = binomial())
# Fit model 2
Pdgfrb_StrMCAO_Fit2 <-
brm(
data = Pdgfrb_CD31_StrMCAO,
family = binomial(),
formula = Pdgfrb_StrMCAO_Mdl2,
knots = list(DPI = c(3, 7, 14, 30)),
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_StrMCAO_Fit1.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_StrMCAO_Fit2 <-
add_criterion(Pdgfrb_StrMCAO_Fit2, c("loo", "waic", "bayes_R2"))
```
#### Model diagnostics
We check the model fitting using posterior predictive checks
```{r}
#| label: fig-Pdgfrb_StrMCAO_Diagnistics
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model diagnostics for PDGFRβ/CD31 colocalization (Striatum)
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
Pdgfrb_StrMCAO_Fit2_pp <-
brms::pp_check(Pdgfrb_StrMCAO_Fit2,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Formula: PDGFR_Parenchymal | PDGFR_Total ~ s(DPI, k = 4)") +
Plot_theme
Pdgfrb_StrMCAO_Fit2_pp
```
We observe no significant deviations from the data. We can explore
further the model using `shinystan`.
```{r}
#| label: Pdgfrb_StrMCAO_Shiny
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
#launch_shinystan(Pdgfrb_StrMCAO_Fit2)
```
### Model results
#### Visualization of conditional effects
```{r}
#| label: fig-Pdgfrb_StrMCAO_CE
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Posterior distribution for PDGFRβ/CD31 colocalization
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
# We create the graph for convex hull
Pdgfrb_StrMCAO_DPI <-
conditional_effects(Pdgfrb_StrMCAO_Fit2)
Pdgfrb_StrMCAO_DPI <- plot(Pdgfrb_StrMCAO_DPI,
plot = FALSE)[[1]]
Pdgfrb_StrMCAO_fig <- Pdgfrb_StrMCAO_DPI +
scale_y_continuous(name = expression ("(p) parenchymal PDGFRβ")) +
scale_x_continuous(name="DPI" ,
breaks = c(3, 10, 20, 30),
labels = c("3", "10", "20", "30")) +
Plot_theme +
theme(legend.position = "top", legend.direction = "horizontal")
ggsave(
plot = Pdgfrb_StrMCAO_fig,
filename = "Plots/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_StrMCAO_Fit2.png",
width = 9,
height = 9,
units = "cm")
Pdgfrb_StrMCAO_fig
```
@fig-Pdgfrb_StrMCAO_CE show an increasing probability for parenchymal
PDGFRβ+ cells with a peak during the second weeks post injury in 0.25.
#### Posterior summary
Next, We plot the posterior summary using the `describe_posterior`
function:
```{r}
#| label: Pdgfr_StrMCAO_DescribePosterior_Ipsi5x
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
describe_posterior(
Pdgfrb_StrMCAO_Fit2,
effects = "all",
test = c("p_direction", "rope"),
component = "all",
centrality = "median")
modelsummary(Pdgfrb_StrMCAO_Fit2,
shape = term ~ model + statistic,
centrali2ty = "mean",
title = "PDGFRβ+ parenchymal cells following MCAO",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "Tables/html/Widefield_10x_ROIs_CD31-Pdgfrb_Str_Fit2_Table.html",
)
Pdgfrb_StrMCAO_Fit2_Table <- modelsummary(Pdgfrb_StrMCAO_Fit2,
shape = term ~ model + statistic,
centrality = "mean",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "gt")
gt::gtsave (Pdgfrb_StrMCAO_Fit2_Table,
filename = "Tables/tex/Widefield_10x_ROIs_CD31-Pdgfrb_Str_Fit2_Table.tex")
```
## Analysis of PDGFRβ-CD31 colocalization in the perilesion
We analyze the perilesion using the same approach.We begin by filtering
the perilesion
```{r}
#| label: PDGFR_CD31_MCAOPeri
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
Pdgfrb_CD31_PeriMCAO <- filter(Pdgfrb_CD31_Coloc, Lesion == "L1", Region == "Peri")
```
### Exploratory data visualization
We visualize the number of parenchymal PDGFRβ+ cells in the perilesion.
```{r}
#| label: fig-Pdgfrb_PeriMCAO_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for PDGFRβ/CD31 colocalization
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Pdgfrb_Parenchymal_10x <-
ggplot(
data = Pdgfrb_CD31_PeriMCAO,
aes(x = DPI2,
y = Pdgfrb_Parenchymal)) +
geom_smooth(
method = "lm",
se = TRUE,
color = "black") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 2),
color = "darkred") +
geom_smooth(
method = "lm",
se = TRUE,
formula = y ~ poly(x, 3),
color = "darkgreen") +
geom_jitter(
width = 0.5,
shape = 1,
size = 1.5,
color = "black") +
scale_y_continuous(name= expression("Number of parenchymal PDGFRβ cells")) +
scale_x_continuous(name="Days post-ischemia (DPI) ",
breaks=c(0, 3, 7,14,30)) +
Plot_theme
Pdgfrb_Parenchymal_10x
```
@fig-Pdgfrb_PeriMCAO_Exploratory reveals that the number of parenchymal
PDGFRβ cells tends to remain constant.
### Statistical modeling
#### Fit the model
We fit a similar statistical model with splines per DPI.
```{r}
#| label: Pdgfrb_PeriMCAO_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
set.seed(8807)
# Model 1: DPI with splines
Pdgfrb_PeriMCAO_Mdl2 <- bf(Pdgfrb_Parenchymal | trials(Pdgfrb_Total) ~ s(DPI2, k = 4))
get_prior(Pdgfrb_PeriMCAO_Mdl2, Pdgfrb_CD31_PeriMCAO, family = binomial())
# Fit model 2
Pdgfrb_PeriMCAO_Fit2 <-
brm(
data = Pdgfrb_CD31_PeriMCAO,
family = binomial(),
formula = Pdgfrb_PeriMCAO_Mdl2,
knots = list(DPI = c(3, 7, 14, 30)),
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Widefield_10x_ROIs_CD31-Pdgfrb_Coloc/Widefield_10x_ROIs_CD31-Pdgfrb_PeriMCAO_Fit2.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_PeriMCAO_Fit2 <-
add_criterion(Pdgfrb_PeriMCAO_Fit2, c("loo", "waic", "bayes_R2"))
```
#### Model diagnostics
We plot posterior predictive checks
```{r}
#| label: fig-Pdgfrb_PeriMCAO_Diagnistics
#| include: true
#| warning: false
#| message: false
#| fig-cap: Model diagnostics for PDGFRβ/CD31 colocalization (Perilesion)
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Pdgfrb_PeriMCAO_Fit2_pp <-
brms::pp_check(Pdgfrb_PeriMCAO_Fit2,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Formula: PDGFR_Parenchymal | PDGFR_Total ~ s(DPI, k = 4)") +
Plot_theme
Pdgfrb_PeriMCAO_Fit2_pp
```
We observe similar trend and no significant deviations from the
observations.
```{r}
#| label: Pdgfrb_PeriMCAO_Shiny
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
#launch_shinystan(Pdgfrb_PeriMCAO_Fit2)
```
### Model results
#### Visualization of conditional effects
```{r}
#| label: fig-Pdgfrb_PeriMCAO_CE
#| include: true
#| warning: false
#| message: false
#| fig-cap: Model diagnostics for PDGFRβ/CD31 colocalization (Perilesion)
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
# We create the graph for convex hull
Pdgfrb_PeriMCAO_DPI <-
conditional_effects(Pdgfrb_PeriMCAO_Fit2)
Pdgfrb_PeriMCAO_DPI <- plot(Pdgfrb_PeriMCAO_DPI,