-
-
Save fusaroli/2114279264e83464b8e344dff7c1521b to your computer and use it in GitHub Desktop.
Livecoding of the first question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman::p_load(tidyverse, brms) | |
# Prepare the data | |
d <- Ass3 | |
#summary(d) | |
d$Diagnosis <- plyr::revalue(as.character(d$Diagnosis), | |
c("0"="Controls", "1"="Schizophrenia")) | |
d <- d %>% | |
mutate( | |
ID = as.factor(ID), | |
Diagnosis = as.factor(Diagnosis) | |
) | |
# Define the formula | |
AltercentricDiagnosis_f0 <- bf( | |
AltercentricIntrusion ~ 1 + Diagnosis | |
) | |
AltercentricDiagnosis_f <- bf( | |
AltercentricIntrusion ~ 0 + Diagnosis | |
) | |
# Design the priors | |
get_prior(AltercentricDiagnosis_f0, family = gaussian, d) | |
get_prior(AltercentricDiagnosis_f, family = gaussian, d) | |
priorDiagnosis <- c( | |
prior(normal(4, 1), class = b), | |
prior(normal(1, 2), class = sigma) | |
) | |
# Test the priors | |
AltercentricDiagnosis_PriorCheck_m <- brm( | |
formula = AltercentricDiagnosis_f, | |
data = d, | |
family = gaussian, | |
prior = priorDiagnosis, | |
sample_prior = "only" | |
) | |
pp_check(AltercentricDiagnosis_PriorCheck_m, nsamples = 100) | |
## Fitting the model | |
AltercentricDiagnosis_m <- brm( | |
formula = AltercentricDiagnosis_f, | |
data = d, | |
family = gaussian, | |
prior = priorDiagnosis, | |
sample_prior = T | |
) | |
# Posterior predictive check | |
pp_check(AltercentricDiagnosis_m, nsamples = 100) | |
## Check the model for warnings | |
AltercentricDiagnosis_m | |
# Hypothesis testing + updating check | |
plot(hypothesis(AltercentricDiagnosis_m, | |
"DiagnosisSchizophrenia > DiagnosisControls")) | |
hypothesis(AltercentricDiagnosis_m, | |
"DiagnosisSchizophrenia > DiagnosisControls") | |
conditional_effects(AltercentricDiagnosis_m) | |
plot(conditional_effects(AltercentricDiagnosis_m), points=T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment