I am trying to fit a random-intercept only Wiener model, following @Henrik_Singmann’s blog post but am running into the error Exception: no more scalars to read (found before start of program)
.
As far as I can tell, this is related to the inits
since without them I don’t get this error (I instead get an error that I should use inits 🙃).
(Note the bogus data and sample_prior = "only"
are for the rep-ex only - I get the same error with real data and sample_prior = "no"
.)
library(brms)
fs_data <- data.frame(
ID = 1:62,
RT = rlnorm(62, sdlog = 0.2),
ACC = sample(0:1, 62, TRUE)
)
formula <- bf(RT | dec(ACC) ~ 1 + (1 | p | ID),
bs ~ 1 + (1 | p | ID),
ndt ~ 1 + (1 | p | ID),
bias ~ 1 + (1 | p | ID))
wiener_fam <- wiener(
link = "identity",
link_bs = "identity",
link_ndt = "identity",
link_bias = "identity"
)
prior <-
set_prior("normal(0.28, 5)", class = "Intercept") +
set_prior("normal(0.31, 0.1)", class = "Intercept", dpar = "bs") +
set_prior("normal(0.27, 0.1)", class = "Intercept", dpar = "ndt") +
set_prior("normal(0.5, 0.2)", class = "Intercept", dpar = "bias")
tmp_dat <- make_standata(formula,
family = wiener_fam,
data = fs_data,
prior = prior)
initfun <- function() list(
Intercept = 0.28,
Intercept_bs = 0.3,
Intercept_ndt = 0.3,
Intercept_bias = 0.5,
sd_1 = rep(0.7, tmp_dat$M_1),
z_1 = matrix(0.05, tmp_dat$M_1, tmp_dat$N_1),
L_1 = diag(tmp_dat$M_1)
)
set.seed(16112020) # selecting a seed until it runs
mod_random <- brm(formula,
data = fs_data,
family = wiener(),
sample_prior = "only",
prior = prior,
chains = 2, iter = 2000, warmup = 500,
cores = 2,
inits = initfun,
backend = "cmdstanr")
#> Compiling Stan program...
#> Start sampling
#> Running MCMC with 2 parallel chains...
#>
#> Chain 1 Unrecoverable error evaluating the log probability at the initial value.
#> Chain 1 Exception: no more scalars to read (found before start of program)
#> Chain 1 Exception: no more scalars to read (found before start of program)
#> Chain 2 Unrecoverable error evaluating the log probability at the initial value.
#> Chain 2 Exception: no more scalars to read (found before start of program)
#> Chain 2 Exception: no more scalars to read (found before start of program)
#> Warning: Chain 1 finished unexpectedly!
#>
#> Warning: Chain 2 finished unexpectedly!
#>
#> Warning: Use read_cmdstan_csv() to read the results of the failed chains.
#> Error in cmdstanr::read_cmdstan_csv(out$output_files(), variables = "", :
#> Assertion on 'files' failed: No file provided.
#> In addition: Warning messages:
#> 1: All chains finished unexpectedly! Use the $output(chain_id) method for more information.
#>
#> 2: No chains finished successfully. Unable to retrieve the fit.
- Operating System: Win11
- brms Version: 2.16.3
- cmdstanr Version: 0.4.0