forked from elalilab/Stroke_PDGFR-B_Reactivity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowCytometry_Pdgfrb_Analysis.qmd
621 lines (504 loc) · 15.7 KB
/
FlowCytometry_Pdgfrb_Analysis.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
---
title-block-banner: true
title: "FACS analysis of PDGFR-β+ live/deat cells"
subtitle: "FACS processing 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-β
- FACS
- 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
In this notebook, we do the FACS analysis of PDGFR-β+ cells sorted from
the ipsilateral and contralateral hemispheres of ischemic
PDGFR-β-TdTomato mice. Rere to [this](https://github.com/elalilab/Stroke_PDGFR-B_Reactivity/blob/main/FlowCytometry_Pdgfrb_Processing.qmd) notebook to see .fcs files processing.
**Parent dataset:** We sorted PDGFR-β+ from ischemic PDGFR-β-TdTomato
animals at 14 DPI. We took coronal \~2 mm-tick sections of the
ipsilateral hemisphere comprising the injured areas exclusively. We took
analogous tissue from the contralateral hemisphere as a baseline control
for the mortality of cells.The raw FACS files (including compensation
controls) are available at the OSF repository in
['Datasets/FACS'](https://osf.io/zvnxa/).
**Working dataset:** We use the `Data_Processed/Facs_Pdgfrb/Fcas_Pdgfrb_Cells-Dead.csv` file generated after processing the .fcs files. We perform scientific inference based on the percentage of PDGFR-β+ cells and Death PDGFR-β+ dead cells.
# Load the required packages
```{r}
#| label: Facs_LoadPackages
#| include: true
#| warning: false
#| message: false
library(brms)
library(dplyr)
library(easystats)
library(ggplot2)
library(magrittr)
library(modelsummary)
library(patchwork)
library(poorman)
library(tidybayes)
```
# Visual themes
```{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 = 5, # Right margin
b = 10, # Bottom margin
l = 10) # Left margin
)
```
# Analysis of the percentaje of PDGFR-β+ cells
## Exploratory data visualization
```{r}
#| label: fig-Pdgfrb_Percentage_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for the number of PDGFR-β+ cells
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Facs_Dataset <- read.csv("Data_Processed/Facs_Pdgfrb/Facs_Pdgfrb_Cells-Dead.csv", header = TRUE)
Facs_Dataset$Hemisphere <- factor (Facs_Dataset$Hemisphere, levels = c("Contra", "Ipsi"))
Pdgfrb_Cells <-
ggplot(
data = Facs_Dataset,
aes(x = Hemisphere,
y = Cells)) +
geom_boxplot() +
scale_y_continuous(name= expression("Percentage of PDGFR-β+ cells")) +
scale_x_discrete(name="Hemisphere",
breaks=c("Contra","Ipsi")) +
Plot_theme
Pdgfrb_Cells
```
As expected, we witness that th ipsilateral hemisphere registers the double of PDGFR-β+ cells.
## Statistical modeling
### Fit the model
```{r}
#| label: Pdgfrb_Percentage_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
set.seed(8807)
# Model 1: Hemisphere as a linear predictor
Pdgfrb_Percentage_Mdl1 <- bf(Cells ~ Hemisphere)
get_prior(Pdgfrb_Percentage_Mdl1, Facs_Dataset, family = student)
# Fit model 1
Pdgfrb_Percentage_Fit1 <-
brm(
data = Facs_Dataset,
family = student,
formula = Pdgfrb_Percentage_Mdl1,
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Facs_Pdgfrb/Facs_Pdgfrb_Cells_Fit1.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_Percentage_Fit1 <-
add_criterion(Pdgfrb_Percentage_Fit1 , c("loo", "waic", "bayes_R2"))
```
### Model diagnostics
We check the model fitting using posterior predictive checks
```{r}
#| label: fig-Pdgfrb_Percentage_Diagnistics
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model diagnostics for the percentage of Td-Tomato+ cells
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
Pdgfrb_Percentage_Fit1_pp <-
brms::pp_check(Pdgfrb_Percentage_Fit1,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Cells ~ Hemisphere") +
Plot_theme
Pdgfrb_Percentage_Fit1_pp
```
We observe no significant deviations from the data. We can explore further the model using `shinystan`.
```{r}
#| label: Pdgfrb_Percentage_Shiny
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
#launch_shinystan(Pdgfrb_Percentage_Fit1)
```
## Model results
### Visualization of conditional effects
```{r}
#| label: fig-Pdgfrb_Percentage_CE
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Posterior distribution for the percentage of PDGFR-β+ cells
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
Pdgfrb_Percentage_Contrast <- Pdgfrb_Percentage_Fit1 %>%
spread_draws(b_HemisphereIpsi) %>%
mutate(Hemisphere_contrast = b_HemisphereIpsi) %>%
ggplot(aes(x = Hemisphere_contrast, fill = after_stat(abs(x) < 0.03))) +
stat_halfeye() +
geom_vline(xintercept = c(-0.03, 0.03), linetype = "dashed") +
scale_fill_manual(
name="ROPE",
values = c("gray80", "skyblue"),
labels = c("False", "True")) +
scale_y_continuous(name = "Probability density") +
scale_x_continuous(name = "Contrast (Contra-Ipsi)",
limits = c(-0.1, 0.2),
breaks = seq(-0.1, 0.2, 0.1) ) +
Plot_theme +
theme (legend.position = c(0.8, 0.8))
ggsave(
plot = Pdgfrb_Percentage_Contrast,
filename = "Plots/FACS_Pdgfrb/FACS_Pdgfrb_Percentage_Fit1.png",
width = 8,
height = 8,
units = "cm")
Pdgfrb_Percentage_Contrast
```
@fig-Pdgfrb_Percentage_CE show that the ipsilateral hemisphere (as expected) has more (the double) of PDGFR-β+ cells at 14 DPI.
### Posterior summary
Next, We plot the posterior summary using the `describe_posterior` function:
```{r}
#| label: Pdgfr_Percentage_DescribePosterior
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
describe_posterior(
Pdgfrb_Percentage_Fit1,
effects = "all",
test = c("p_direction", "rope"),
component = "all",
centrality = "median")
modelsummary(Pdgfrb_Percentage_Fit1,
shape = term ~ model + statistic,
centrali2ty = "mean",
title = "PErcentage of PDGFR-β+ cells following MCAO",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "Tables/html/Facs_Pdgfrb_Fit1_Table.html",
)
Pdgfrb_Percentage_Fit1_Table <- modelsummary(Pdgfrb_Percentage_Fit1,
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_Percentage_Fit1_Table,
filename = "Tables/tex/Facs_Pdgfrb_Fit1_Table.tex")
```
# Analysis of the percentaje of PDGFR-β+ dead cells
## Exploratory data visualization
```{r}
#| label: fig-Pdgfrb_Dead_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for the number of PDGFR-β+ dead cells
#| fig-width: 5
#| fig-height: 4
set.seed(8807)
Facs_Dataset <- read.csv("Data_Processed/Facs_Pdgfrb/Facs_Pdgfrb_Cells-Dead.csv", header = TRUE)
Facs_Dataset$Hemisphere <- factor (Facs_Dataset$Hemisphere, levels = c("Contra", "Ipsi"))
Pdgfrb_Dead <-
ggplot(
data = Facs_Dataset,
aes(x = Hemisphere,
y = Dead)) +
geom_boxplot() +
scale_y_continuous(name= expression("Percentage of PDGFR-β+ dead cells")) +
scale_x_discrete(name="Hemisphere",
breaks=c("Contra","Ipsi")) +
Plot_theme
Pdgfrb_Dead
```
As expected, we witness that th ipsilateral hemisphere registers the double of PDGFR-β+ cells.
# Statistical modeling
## Fit the model
```{r}
#| label: Pdgfrb_Dead_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
set.seed(8807)
# Model 1: Hemisphere as a linear predictor
Pdgfrb_Dead_Mdl1 <- bf(Dead ~ Hemisphere)
get_prior(Pdgfrb_Dead_Mdl1, Facs_Dataset, family = student)
# Fit model 1
Pdgfrb_Dead_Fit1 <-
brm(
data = Facs_Dataset,
family = student,
formula = Pdgfrb_Dead_Mdl1,
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Facs_Pdgfrb/Facs_Pdgfrb_Dead_Fit1.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_Dead_Fit1 <-
add_criterion(Pdgfrb_Dead_Fit1 , c("loo", "waic", "bayes_R2"))
# Model 1: Hemisphere as a linear predictor for dead cells and sigma
Pdgfrb_Dead_Mdl2 <- bf(Dead ~ Hemisphere,
sigma ~ Hemisphere)
get_prior(Pdgfrb_Dead_Mdl2, Facs_Dataset, family = student)
# Fit model 2
Pdgfrb_Dead_Fit2 <-
brm(
data = Facs_Dataset,
family = student,
formula = Pdgfrb_Dead_Mdl2,
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Facs_Pdgfrb/Facs_Pdgfrb_Dead_Fit2.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_Dead_Fit2 <-
add_criterion(Pdgfrb_Dead_Fit2, c("loo", "waic", "bayes_R2"))
```
## Model diagnostics
We check the model fitting using posterior predictive checks
```{r}
#| label: fig-Pdgfrb_Dead_Diagnistics
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model diagnostics for the percentage of Td-Tomato+ cells
#| fig-height: 4
#| fig-width: 10
set.seed(8807)
Pdgfrb_Dead_Fit1_pp <-
brms::pp_check(Pdgfrb_Dead_Fit1,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Cells ~ Hemisphere") +
Plot_theme
Pdgfrb_Dead_Fit2_pp <-
brms::pp_check(Pdgfrb_Dead_Fit2,
ndraws = 100) +
labs(title = "Posterior predictive checks",
subtitle = "Formula: Cells ~ Hemisphere, sigma ~ Hemisphere") +
Plot_theme
Pdgfrb_Dead_Fit1_pp | Pdgfrb_Dead_Fit2_pp
```
We observe that our model with heteroskedasticity deviate less from the observed data.
```{r}
#| label: Pdgfrb_Dead_Shiny
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
#launch_shinystan(Pdgfrb_Dead_Fit1)
#launch_shinystan(Pdgfrb_Dead_Fit2)
```
## Model comparison
```{r}
#| label: Pdgfrb_Dead_Compare
#| include: true
#| warning: false
#| message: false
#| results: false
Pdgfrb_Dead_Comp <-
compare_performance(
Pdgfrb_Dead_Fit1,
Pdgfrb_Dead_Fit2,
metrics = "all"
)
Pdgfrb_Dead_Comp
```
The output depicts that model 2 is the less penalized and has a stronger explained variance (R2 = 0.51). The preceding offer sufficient grounds to select model 2 (Mdl2) as our best alternative.
We can appreciate the same results using `loo_compare`:
```{r}
#| label: fig-Pdgfrb_Dead_Compare
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Model camparison by WAIC
#| fig-height: 4
#| fig-width: 5
Pdgfrb_Dead_W <-
loo_compare(
Pdgfrb_Dead_Fit1,
Pdgfrb_Dead_Fit2,
criterion = "waic")
# Generate WAIC graph
Pdgfrb_Dead_WAIC <-
Pdgfrb_Dead_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_Dead_Fit1",
"Pdgfrb_Dead_Fit2"),
labels=c("Mdl1",
"Mdl2")
) +
coord_flip() +
labs(x = "",
y = "WAIC (score)",
title = "") +
Plot_theme
Pdgfrb_Dead_WAIC
```
# Model results
## Visualization of conditional effects
```{r}
#| label: fig-Pdgfrb_Dead_CE
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Posterior distribution for the percentage of PDGFR-β+ dead cells
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
Pdgfrb_Dead_Contrast <- Pdgfrb_Dead_Fit2 %>%
spread_draws(b_HemisphereIpsi) %>%
mutate(Hemisphere_contrast = b_HemisphereIpsi) %>%
ggplot(aes(x = Hemisphere_contrast, fill = after_stat(abs(x) < 0.11))) +
stat_halfeye() +
geom_vline(xintercept = c(-0.11, 0.11), linetype = "dashed") +
scale_fill_manual(
name="ROPE",
values = c("gray80", "skyblue"),
labels = c("False", "True")) +
scale_y_continuous(name = "Probability density") +
scale_x_continuous(name = "Contrast (Contra-Ipsi)",
limits = c(-0.2, 0.6),
breaks = seq(-0.2, 0.6, 0.2) ) +
Plot_theme +
theme (legend.position = c(0.8, 0.8))
ggsave(
plot = Pdgfrb_Dead_Contrast,
filename = "Plots/FACS_Pdgfrb/FACS_Pdgfrb_Dead_Fit1.png",
width = 8,
height = 8,
units = "cm")
Pdgfrb_Dead_Contrast
```
@fig-Pdgfrb_Dead_CE shows that the ipsilateral hemisphere (as expected) has more PDGFR-β+ dead cells at 14 DPI.
## Posterior summary
Next, We plot the posterior summary using the `describe_posterior` function:
```{r}
#| label: Pdgfrb_Dead_DescribePosterior
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
describe_posterior(
Pdgfrb_Dead_Fit1,
effects = "all",
test = c("p_direction", "rope"),
component = "all",
centrality = "median")
modelsummary(Pdgfrb_Dead_Fit1,
shape = term ~ model + statistic,
centrali2ty = "mean",
title = "Percentage of PDGFR-β+ dead cells following MCAO",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "Tables/html/Facs_Pdgfrb_Fit1_Dead_Table.html",
)
Pdgfrb_Dead_Fit1_Table <- modelsummary(Pdgfrb_Dead_Fit1,
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_Dead_Fit1_Table,
filename = "Tables/tex/Facs_Pdgfrb_Dead_Fit1_Table.tex")
```
# References
::: {#refs}
:::
```{r}
sessionInfo()
```