Joint sample of parameter and random variables

Hello
I am trying to work with random variables as parameters in the sampling. My model is more complicated, using von mises function, but I did here a unit test to understand what I do wrong :
Here is my unit test below ; My data Matrix_test is generated with scipy.stats.norm.rvs, with mean 0 and sigma 0.1. If I run this with let’s say 20 chains and 1000 iterations, stan is able to recover the mean 0 and the sigma 0.1. My question is more on the other random variable that I am generating, called here perceived_stimulus_in_rad_test. In my more complicated model, it’s creating incorrect values, far from the von mises I want. I need to sample also on these when computing the posterior, as they are implicated in the computation of the more complicated model. But here, if you run this on 1 chain, 1 iteration, and you print perceived_stimulus_in_rad_test, then plot it on python, you don’t get a normal distribution at all (and same problem when using von_mises instead of normal). It’s kind of flat looking uniform, and going from -150 to 150 or so… Where I am doing something wrong ? thank you in advance

data {
	int<lower=1> N;  // number of trials
	real Matrix_test[N]; // data generated with scipy.stats.norm.rvs, with mean 0 and sigma 0.1
}

parameters {
	real<lower=0.05, upper=0.2> sigma;  // perceptual noise
	real<lower=-pi(), upper=pi()> mu; // mean of the distribution
	vector[N] perceived_stimulus_in_rad_test ;
}

model {
	for (i in 1:N){
		perceived_stimulus_in_rad_test[i] ~ normal(0, sigma);
	}
	print(sigma)
	print(perceived_stimulus_in_rad_test)
	
	Matrix_test ~ normal(mu, sigma);
}

my full script with the von mises etc can be seen here : https://www.dropbox.com/s/w4ceealamdokh6e/rule_model_test.stan?dl=0

1 Like

I took the liberty to put your code inside some ``` quotes so that it gets properly formatted. Hope that helps!