-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfit_model_full.R
More file actions
38 lines (28 loc) · 1.09 KB
/
Copy pathfit_model_full.R
File metadata and controls
38 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## LOAD REQUIRED PACKAGES
library("rstan")
library("brms")
rstan_options(auto_write = TRUE)
options(max.print=10000)
## PREPARE THE DATA FRAME
d = read.csv("full_volume_dataframe.csv")
d$scanner <- tolower(d$scanner)
d$hrrt <- ifelse(d$scanner=="hrrt",1,0)
d$pet_mri <- ifelse(d$scanner=="pet-mri",1,0)
d$ge <- ifelse(d$scanner=="ge_advance",1,0)
d$sampo <- ifelse(d$scanner=="sampo",1,0)
d$male <- ifelse(d$sex=="m",1,0)
d$age_sd <- (d$age - mean(d$age))/sd(d$age)
d$log_bp <- log(d$bp)
d$smoker <- ifelse(d$smoker==1,1,0)
d$roi <- as.factor(d$roi)
## SAMPLING SPECIFICATIONS
ITER <- 12000
WARMUP <- 2000
CORES <- 3
CHAINS <- 3
AD <- 0.95
## PRIOR
custom_prior <- set_prior("normal(0,1)", class = "b")
## FIT THE MODEL TO THE DATA AND DRAW POSTERIOR SAMPLES
# full model
fit1 <- brm(log_bp ~ (1 | subject) + (1 + male + age_sd + age_sd:male + smoker + hrrt + pet_mri + ge + sampo | roi) + 1 + male + age_sd + age_sd:male + smoker + hrrt + pet_mri + ge + sampo, data = d, prior = custom_prior, cores = CORES, chains = CHAINS, iter = ITER, warmup = WARMUP, control = list(adapt_delta = AD, max_treedepth = 15))