Hi there,
I am trying to fit a beta binomial model in brms and I get the following error; I’ve seen a similar error posted in Nov18 but I’m running this on a server with Ubuntu, 16 CPU and 64 RAM and I expect the source of the error to be different:
Error in FUN(X[[i]], ...) :
trying to get slot "mode" from an object (class "try-error") that is not an S4 object
Calls: brm ... eval -> .fun -> .fun -> .local -> sapply -> lapply -> FUN
In addition: Warning message:
In parallel::mclapply(1:chains, FUN = callFun, mc.preschedule = FALSE, :
6 function calls resulted in an error
Execution halted
this is the model I’m trying to fit:
brm_fit <-
brm(
formula =
distance | vint(trials)
~ 1
+ (1 | person)
+ (1 | word),
data=data,
family = beta_binomial2,
stanvars = stanvars,
prior = priors,
cores = 6,
silent = F,
seed = 42,
chains = 6,
iter = 6000,
warmup = 3000,
delta = 0.99,
save_pars = save_pars(all = TRUE)
)
I prepared the family the following way:
beta_binomial2 <- custom_family(
"beta_binomial2", dpars = c("mu", "phi"),
links = c("logit", "log"), lb = c(NA, 0),
type = "int", vars = "vint1[n]"
)
stan_funs <- "
real beta_binomial2_lpmf(int y, real mu, real phi, int T) {
return beta_binomial_lpmf(y | T, mu * phi, (1 - mu) * phi);
}
int beta_binomial2_rng(real mu, real phi, int T) {
return beta_binomial_rng(T, mu * phi, (1 - mu) * phi);
}
"
stanvars <- stanvar(scode = stan_funs, block = "functions")
log_lik_beta_binomial2 <- function(i, prep) {
mu <- prep$dpars$mu[, i]
phi <- prep$dpars$phi
trials <- prep$data$vint1[i]
y <- prep$data$Y[i]
beta_binomial2_lpmf(y, mu, phi, trials)
}
posterior_predict_beta_binomial2 <- function(i, prep, ...) {
mu <- prep$dpars$mu[, i]
phi <- prep$dpars$phi
trials <- prep$data$vint1[i]
beta_binomial2_rng(mu, phi, trials)
}
posterior_epred_beta_binomial2 <- function(prep) {
mu <- prep$dpars$mu
trials <- prep$data$vint1
trials <- matrix(trials, nrow = nrow(mu), ncol = ncol(mu), byrow = TRUE)
mu * trials
}
thanks in advance