Hello,
I am a masters student and quite new to Bayesian statistics and would greatly appreciate your help!
I am fitting mixed effect cumulative probit model in brms. I would like to check the normality and heteroscedasticity of the models residuals and look for signs of spatial autocorrelation. I was hoping to use the DHARMa package for this but keep receiving the following error.
################
Error in if (minSim == maxSim) scaledResiduals[i] = minSim else scaledResiduals[i] = runif(1, :
missing value where TRUE/FALSE needed
#####################
I have provide a reproduceable below?
If not, do you have advice on examining residuals for cumulative probit model in brms? I am particularly concerns about spatial autocorrelation.
Please let me if you need any more information.
Many thanks!
note: the code I am using is below is modified from these two posts
- Code for createDHARMa.
- Code for model creation
library(dplyr)
library(forcats)
library(tidyr)
library(modelr)
library(tidybayes)
library(rstan)
library(brms)
library(posterior)
#generate dataset
set.seed(5)
n = 10
n_condition = 5
testdata <-
tibble(
response = rep(c("A","B","C","D","E"), n),
predictor = rnorm(n * 5, c(0,1,2,1,-1,8,9,8), 3),
randomEff = rnorm(n * 5, c(2,3), 1)) %>%
mutate(randomEff = round(randomEff)) %>%
mutate(randomEff = as.factor(randomEff)) %>%
mutate(response = factor(response, order = TRUE, levels = c("A","B","C","D","E")))
str(df)
#fit model
model <- brm(response ~ predictor + (1|randomEff),
data = testdata,
family=cumulative("logit"),
file = paste0("mod1.Rmd"),
control = list(adapt_delta=0.98), backend = "cmdstanr",
chains = 4, cores = 4, warmup = 1000, iter = 2000)
# attempting DHARMa
model.check <- createDHARMa(
simulatedResponse = t(posterior_predict(model)),
observedResponse = testdata$response,
fittedPredictedResponse = apply(t(posterior_epred(model)), 1, mean),
integerResponse = TRUE)
plot(model.check)
```{r }