forked from elalilab/Stroke_PDGFR-B_Reactivity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widefield_5x_Ipsilateral_Pdgfrb_LowHigh_Str.qmd
394 lines (316 loc) · 12.3 KB
/
Widefield_5x_Ipsilateral_Pdgfrb_LowHigh_Str.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
---
title-block-banner: true
title: "Analysis of PDGFR-β-low and PDGFR-β high+ cells in the ipsilateral hemisphere (striatal-only lesions)"
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 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
theme: spacelab
knitr:
opts_chunk:
warning: false
message: false
csl: science.csl
bibliography: references.bib
---
# Preview
In this notebook, we analyze the proportion and distribution of PDGFR-β_Low and PDGFR-β_High+ in brains with only striatal lesions. We performed a separate image pre-processing, cell detection and data analysis for these animals given that the experiments were carried out at a different moment. We performed automatic cell detection and classification using QuPath [@bankhead2017]. We also create point patterns using the coordinates of detecting cells to perform Point Pattern analysis.
**Parent dataset:** PDGFR-β and GFAP-stained ischemic hemispheres imaged at 5x (with stitching). Samples are grouped at 14 and 30 days post-ischemia (DPI). The raw images and pre-processing scripts (if applicable) are available at the Zenodo repository (10.5281/zenodo.10553084) under the name `Widefield_5x_Ipsilateral_Gfap-Pdgfrb.zip`. Individual cells were detected and classified into PDGFR-β^low^ (Pdgfrb_NonReact) and PDGFR-β^high^ (Pdgfrb_React) using QuPath [@bankhead2017].The complete QuPath project, including classifiers and output data as .tsv files is available at https://osf.io/ty4z5.
**Working dataset**: The `Widefield_5x_Ipsilateral_Gfap-Pdgfrb_Inten_Str.csv`data frame containing the number of PDGFR-β^low^ (Pdgfrb_NonReact) and PDGFR-β^high^ (Pdgfrb_React) cells in the ischemic hemisphere. Here, we analyze the proportion and distribution of these populations.
# 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("devtools")
#library(devtools)
#install.packages(c("bayesplot", "bayestestR", "brms","broom.mixed", "dplyr", "easystats", "distributional", "ggplot","gtsummary", "modelbased", "modelr", "modelsummary", "patchwork", "poorman", "tidybayes", "tidyverse"))
library(bayesplot)
library(bayestestR)
library(brms)
library(broom.mixed)
library(dplyr)
library(easystats)
library(distributional)
library(ggplot2)
library(gtsummary)
library(modelbased)
library(modelr)
library(modelsummary)
library(patchwork)
library(poorman)
library(tidybayes)
library(tidyverse)
```
# 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
)
```
# Exploratory data visualization
```{r}
#| label: Pdgfrb_Striatum_Table
#| include: true
#| warning: false
#| message: false
#| tbl-cap: "Data set"
# We load the dataset in case is not present in the R environment
Pdgfrb_Striatum <- read.csv(file = "Data_Processed/Widefield_5x_Ipsilateral_Gfap-Pdgfrb/Widefield_5x_Ipsilateral_Gfap-Pdgfrb_Inten_Str.csv", header = TRUE)
gt::gt(Pdgfrb_Striatum[1:10,])
```
For this analysis, we focus on `DPI` (Days post-ischemia), `Pdgfrb_NonReact`, `Pdgfrb_React` variables to analyze these cells proportions in the ischemic brain. Next, we visualize the raw data to guide the statistical modeling. We plot the response variables as a scatter plot fitting a linear model, given that this data set comprises just two time points.
```{r}
#| label: fig-Pdgfrb_LowHigh_Str_Exploratory
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Exploratory data visualization for PDGFR-β^low^ and PDGFR-β^high^ (striatal lesions)
#| fig-width: 9
#| fig-height: 4
set.seed(8807)
# PDGFR-β^low^
###################
Striatum_Pdgfr_Low_Sctr <-
ggplot(
data = Pdgfrb_Striatum,
aes(x = DPI,
y = Pdgfrb_NonReact)) +
geom_smooth(
method = "lm",
se = TRUE,
color = "black") +
geom_jitter(
width = 0.5,
shape = 1,
size = 1.5,
color = "black") +
scale_y_continuous(name= expression("Number of PDGFR-β"^low)) +
scale_x_continuous(name="Days post-ischemia (DPI) ",
breaks=c(14,30)) +
Plot_theme
# PDGFR-β^low^
#######################
Striatum_Pdgfr_High_Sctr <-
ggplot(
data = Pdgfrb_Striatum,
aes(x = DPI,
y = Pdgfrb_React)) +
geom_smooth(
method = "lm",
se = TRUE,
color = "black") +
geom_jitter(
width = 0.5,
shape = 1,
size = 1.5,
color = "black") +
scale_y_continuous(name= expression("Number of PDGFR-β"^high)) +
scale_x_continuous(name="Days post-ischemia (DPI) ",
breaks=c(14,30)) +
Plot_theme
Striatum_Pdgfr_Low_Sctr | Striatum_Pdgfr_High_Sctr
```
@Pdgfrb_Striatum_LowHigh_Exploratory show that PDGFR-β^low^ (non-reactive cells) show a wide dispersion give the reduced number of observations at 14 DPI. Meanwhile, PDGFR-β^high^ display an increasing trend from 14 to 30 DPI. As done for brain with cortico-striatal lesions, we fit the model using a binomial family distribution. Please refer to the `Widefield_5x_Ipsilateral_Pdgfrb_LowHigh.qmd` notebook for additional details of this distribution model.
# Statistical modeling
## Fit the model
We fit a linear model using a binomial distribution `DPI` as a linear predictor for the probability of PDGFR-𝛽^high^:
$$
\log\left(\frac{p_{i}}{1 - p_{i}}\right) = \alpha + \beta_{1} \times DPI_{i}
$$
This model uses weakly informative priors based on the information gathered from the model for corticostriatal lesions. The prior take the following notation:
$$
\begin{align}
b \sim \mathcal{N}(1, 0.2), \text{lb}=0 \\
\text{Intercept} \sim student_t(3, 0, 2), \text{lb}=0 \\
\end{align}
$$
```{r}
#| label: Pdgfrb_LowHigh_Str_Modeling
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
Pdgfrb_Prop_Str_Mdl1 <- bf(Pdgfrb_React | trials(Pdgfrb_Total) ~ DPI)
get_prior(Pdgfrb_Prop_Str_Mdl1, Pdgfrb_Striatum, family = binomial())
Pdgfrb_Prop_Str_Prior1 <-
c(prior(normal(1,0.2), class = b, lb = 0),
prior(student_t(3, 0, 2), class = Intercept, lb = 0))
# Fit model 1
Pdgfrb_Prop_Str_Fit1 <-
brm(
data = Pdgfrb_Striatum,
family = binomial(),
formula = Pdgfrb_Prop_Str_Mdl1,
prior = Pdgfrb_Prop_Str_Prior1,
chains = 4,
cores = 4,
warmup = 2500,
iter = 5000,
seed = 8807,
control = list(adapt_delta = 0.99, max_treedepth = 15),
file = "Models/Widefield_5x_Ipsilateral_Pdgfrb_LowHigh/Widefield_5x_Ipsilateral_Str_LowHigh_Fit1.rds",
file_refit = "never")
# Add loo for model comparison
Pdgfrb_Prop_Strl_Fit1 <-
add_criterion(Pdgfrb_Prop_Str_Fit1, c("loo", "waic", "bayes_R2"))
```
## Model diagnostics
We perform model checks using the `pp_check` function:
```{r}
#| label: fig-Pdgfrb_LowHigh_Str_Diagnistics
#| include: true
#| warning: false
#| message: false
#| results: false
#| cache: true
#| fig-cap: Model diagnostics for the probability of PDGFR-𝛽^high^ (striatal lesions)
#| fig-height: 4
#| fig-width: 5
set.seed(8807)
Pdgfrb_Prop_Str_Mdl1_pp <-
brms::pp_check(Pdgfrb_Prop_Str_Fit1,
ndraws = 100) +
labs(title = expression("Posterior predictive checks (PDGFR-β)"),
subtitle = "Formula: PDGFR_React | PDGFR_Total ~ DPI") +
Plot_theme
Pdgfrb_Prop_Str_Mdl1_pp
```
Similar to our cortico-striatal injuries, our predictions exhibit a moderate deviations from the data. We further diagnose calculating Leave-One-Out Cross-Validation (Loo) using the `loo` function from `brms`.
```{r}
#| label: Pdgfrb_Str_Loo
#| include: true
#| warning: false
#| message: false
loo(Pdgfrb_Prop_Str_Fit1)
```
The results show that most observations are problematic. In particular, 48% of observations belonging to the very bad category, suggest that the importance sampling weights for these observations are highly variable. This model does not have a good fit and must include additional variables.
# Model results
## Visualization of conditional effects
```{r}
#| label: fig-Pdgfr_LowHigh_Str_CondEff
#| include: true
#| warning: false
#| message: false
#| results: false
#| fig-cap: Posterior for PDGFR-𝛽^low^ and PDGFR-𝛽^high^ (striatal lesions)
#| fig-width: 4
#| fig-height: 3
set.seed(8807)
# We create the graph for convex hull
Pdgfrb_Prop_Str_DPI <-
conditional_effects(Pdgfrb_Prop_Str_Fit1)
Pdgfrb_Prop_Str_DPI <- plot(Pdgfrb_Prop_Str_DPI,
plot = FALSE)[[1]]
Pdgfrb_Prop_Str_fig <- Pdgfrb_Prop_Str_DPI +
scale_y_continuous(name = expression ("(p) Pdgfrb-β"^high)) +
scale_x_continuous(name="DPI") +
scale_color_manual(
values = c("#0048BA", "red"),
name="Condition"
) +
scale_fill_manual(
values = c("#0048BA", "red"),
name="Condition"
) +
Plot_theme +
theme(legend.position = "top", legend.direction = "horizontal")
ggsave(
plot = Pdgfrb_Prop_Str_fig,
filename = "Plots/Widefield_5x_Ipsilateral_Pdgfrb_LowHigh/Widfield_5x_Ipsilateral_Pdgfrb_LowHigh_Str.png",
width = 9,
height = 9,
units = "cm")
Pdgfrb_Prop_Str_fig
```
@fig-Pdgfr_LowHigh_Str_CondEff show an increasing probability for reactive PDGFR-β with a low uncertainty. This shows a clear contrast with cortico-striatal lesions which exhibit twice the probability at 14 and 30 DPI.
## Posterior summary
Here, we visualize the results in numerical terms using the `describe_posterior` function:
```{r}
#| label: Pdgfr_LowHigh_Str_DescribePosterior
#| include: true
#| warning: false
#| message: false
#| results: false
describe_posterior(
Pdgfrb_Prop_Str_Fit1,
effects = "all",
test = c("p_direction", "rope"),
component = "all",
centrality = "median")
modelsummary(Pdgfrb_Prop_Str_Fit1,
shape = term ~ model + statistic,
centrali2ty = "mean",
title = "PDGFR-β low and high-intensity populations in striatal-only lesions following MCAO",
statistic = "conf.int",
gof_omit = 'ELPD|ELDP s.e|LOOIC|LOOIC s.e|WAIC|RMSE',
output = "Tables/html/Widefield_5x_Ipsilateral_Pdgfrb_LowHigh_Str_Table.html",
)
Pdgfrb_Prop_Str_Fit1_Table <- modelsummary(Pdgfrb_Prop_Str_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_Prop_Str_Fit1_Table, filename = "Tables/tex/Widefield_5x_Ipsilateral_Pdgfrb_LowHigh_Str_Table.tex")
```
::: {#refs}
:::
```{r}
sessionInfo()
```