I am playing with the data in Reading wild minds: A computational assay of Theory of Mind sophistication across seven primate species , where different kinds of primates play a “matching pennies” game (guess in which hand is the tasty treat).
I define a handful of possible strategies and want to build a mixture model trying to identify which strategy each primate is mostly likely using.
The two simplest ones (as an example here):
Strategy 1: Simple Bias: the primate just picks the left hand with a fixed rate. E.g. the primate is left handed and tends to pick left 80% of the time.
Strategy 2: Biased Nash: the primate keeps track of how many times the food was in the left hand so far, and picks accordingly (more likely to pick left, the higher the proportion of times food was in the left hand)
I build the models on a single primate and all works nicely. I then try to scale up to all the primates in a given species. The single strategy models work nicely. The mixture model fails, plausibly due to how I specify that theta (the probability of picking strategy 1) could differ by primate.
Data: Dropbox - SampleData.csv - Simplify your life
# Setting the family as a mixture of two bernoulli
mix <- mixture(bernoulli, bernoulli, order = "none")
# Defining the two bernoullis and conditioning theta on individual
mix_f1 <- bf(
left ~ 1 ,
mu1 ~ 1 + (1 | individual),
mu2 ~ 1 + LeftProb + (1 + LeftProb | individual),
theta1 ~ 1 + (1|individual)
)
# defining priors
mix_p1 <- c(
prior(normal(0,0.3), class=Intercept, dpar=mu1),
prior(normal(0,0.3), class=Intercept, dpar=mu2),
prior(normal(0,0.3), class=b, dpar=mu2),
prior(normal(0, .3), class = sd, dpar=mu1),
prior(normal(0, .3), class = sd, dpar=mu2),
prior(normal(0, .3), class = sd, dpar=theta1),
prior(lkj(3), class = cor)
)
# Fittng the model
mix_m1 <- brm(
mix_f1,
d,
family = mix,
mix_p1,
sample_prior = T,
chains = 1,
cores = 2,
backend = "cmdstanr",
threads = threading(2),
file = paste0("mix_m1"),
file_refit = "on_change",
control = list(
adapt_delta = 0.99,
max_treedepth = 20
)
)
Commenting away the backend all works. but with cmstanr (no matter if threading or not), I get
Compiling Stan program…
Start sampling
Running MCMC with 1 chain, with 2 thread(s) per chain…Chain 1 num_threads = 2
Warning: Chain 1 finished unexpectedly!Error in rstan::read_stan_csv(out$output_files()) :
csvfiles does not contain any CSV file name
In addition: Warning message:
No chains finished successfully. Unable to retrieve the fit.
I am unable to figure out why this is. Any suggestion?