Error when using 0 as the mean offset in a vector of betas

Hi! I got great help from this forum on how to speed up a hierarchal model I’m running. One of the speed-ups was using the “<offset=,multiplier=>” argument when specifying my vector of betas. The issue I am having now is with respect to those offsets, which as I understand it sets the prior for the means of the betas vector. Originally I used positive numbers for all of the offsets, now I want to change some of the betas offsets to be zero (so really my goal is to give them a prior of mean=0). When I do that I get the following error (the model has been working and I did not change anything about my data or script except the values of offset):

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/ipykernel_15810/87789989.py in <module>
      3 
      4 ## Fit Stan model.
----> 5 StanFit = StanModel.sample(data=data_dict, chains=chains, iter_warmup=iter_warmup, iter_sampling=iter_sampling,
      6                            thin=thin, parallel_chains=parallel_chains, seed=0, show_progress=True)
      7 

/opt/anaconda3/envs/cmdstan/lib/python3.9/site-packages/cmdstanpy/model.py in sample(self, data, chains, parallel_chains, threads_per_chain, seed, chain_ids, inits, iter_warmup, iter_sampling, save_warmup, thin, max_treedepth, metric, step_size, adapt_engaged, adapt_delta, adapt_init_phase, adapt_metric_window, adapt_step_size, fixed_param, output_dir, sig_figs, save_diagnostics, save_profile, show_progress, refresh)
    883                     msg, runset.__repr__()
    884                 )
--> 885                 raise RuntimeError(msg)
    886 
    887             mcmc = CmdStanMCMC(runset)

RuntimeError: Error during sampling:
chain_id 1:
Initialization failed.


chain_id 2:
Initialization failed.


chain_id 3:
Initialization failed.


chain_id 4:
Initialization failed.

Command and output files:
RunSet: chains=4
 cmd:
	['/Volumes/GoogleDrive/Shared drives/foraging_project/STAN_model/foraging_sonaremote_cmdstan/fit_stan_sonaremote_model_efficent_09_28_21', 'id=1', 'random', 'seed=0', 'data', 'file=/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/t4ky_2ku.json', 'output', 'file=/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-1-m2t2rjqg.csv', 'method=sample', 'num_samples=1000', 'num_warmup=500', 'thin=1', 'algorithm=hmc', 'adapt', 'engaged=1']
 retcodes=[1, 1, 1, 1]
 csv_files:
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-1-m2t2rjqg.csv
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-2-mg2a20c4.csv
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-3-nz5w6y8n.csv
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-4-dhdmhom4.csv
 console_msgs:
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-1-m2t2rjqg-stdout.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-2-mg2a20c4-stdout.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-3-nz5w6y8n-stdout.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-4-dhdmhom4-stdout.txt
 error_msgs:
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-1-m2t2rjqg-stderr.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-2-mg2a20c4-stderr.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-3-nz5w6y8n-stderr.txt
	/var/folders/78/wsfrr0414m1fy167lrq7ntyh0000gp/T/tmpaj527q7k/fit_stan_sonaremote_model_efficent_09_28_21-202109281336-4-dhdmhom4-stderr.txt

Here are the most relevant lines from the STAN model code:

transformed data{
//  original priors 
//	vector[5] tau_prior_OM = [.3,30,3,30,3]';
//	vector[5] beta_prior_OM = [.5,100,10,100,10]';
// priors returning error
	vector[5] tau_prior_OM = [.3,30,10,30,10]'; // betas SD
	vector[5] beta_prior_OM = [.5,100,0,100,0]'; // betas mean
}
parameters {
	vector<offset=beta_prior_OM,multiplier=beta_prior_OM>[5] beta_ms; // group betas
	vector<lower=0>[5] tau_raw ;	// betas covariance scale
	matrix[NS,5] beta_s; //per subject betas
	cholesky_factor_corr[5] omega;   // betas covariance correlation
	// beta_ms[1] = inv_temp
	// beta_ms[2] = cost_Matching
	// beta_ms[3] = cost_Mismatching
	// beta_ms[4] = cost_small
	// beta_ms[5] = cost_large 
}
transformed parameters{
	vector[5] tau = tau_raw .* tau_prior_OM ;
}
model {
	omega ~ lkj_corr_cholesky(1); // prior on correlation
	tau_raw ~ normal(1,1); // prior on covariance scale
	beta_ms ~ normal(beta_prior_OM, beta_prior_OM); // prior on group betas
	matrix[5,5] L_omega = diag_pre_multiply(tau, omega) ;
	for (s in 1:NS) {
		beta_s[s] ~ multi_normal_cholesky(
			beta_ms
			, L_omega
		);
	}

I am attaching the full STAN script, and a small subset of the data, the python file that I’m using to run it (using cmdstanpy). Thanks so much for your help!

fit_stan_sonaremote_model_efficent_09_28_21.stan (2.0 KB)
fit_stan_cmdstan_sonaremote_efficent_hypothesis_test.py (2.0 KB)
foraging_sonaremote_stan_data_10subs_09_28_21.csv (653.0 KB)

You’re using the same vector to set the multipliers, which doesn’t make sense because that implies *0

Okay thank you so much!! I’m seeing that this code was part of the original solution provided from my first post, so I will post an update to that thread with the fix. Can you confirm that this is the intended code?:

parameters {
vector<offset=beta_prior_OM,multiplier=tau_prior_OM>[5] beta_ms; // group betas
...
model {
	omega ~ lkj_corr_cholesky(1); // prior on correlation
	tau_raw ~ normal(1,1); // prior on covariance scale
	beta_ms ~ normal(beta_prior_OM, tau_prior_OM); // prior on group betas
	matrix[5,5] L_omega = diag_pre_multiply(tau, omega) ;
...
```