Prior for each level

#1

Hi,
I have a factor with different levels and I would like to assign different priors for each level. Could you please help me with that?

As example, I have the following data. M and P are two factors and R the response. M has 5 levels and in following model I have set the same prior for all the 5 levels. However, I would like to assign different prior for each level.

M <- rep(1:5, each=6 )
P <- rep(1:3, each=10 )
R <- runif(30, 0, 2)
dat <- cbind.data.frame(M, P, R)

model.stan <- '
data{
 int <lower=1> N;
 int M[N];
 int P[N];
 vector[N] R;
}
parameters{
 real M_mu[5];
 real P_mu[3];
 real<lower=0> sigma;
}

transformed parameters{
 real mu[N];
for(n in 1:N)
 mu[n] = M_mu[M[n]] + P_mu[P[n]];
}

model{
 M_mu ~ normal(0,1);
 P_mu ~ normal(0,1);
 sigma ~ exponential(1);

 R ~ normal( mu, sigma);
}
'

stan_samples <- stan(model_code = model.stan, model_name='new',
	data = list(
		N = nrow(dat),
		M = dat $M, 
		P = dat $P,
		R = dat $R
		) 
	) 

print(stan_samples,  pars=c('M_mu', 'P_mu','sigma'), probs=c(0.05, 0.95),  digits_summary=4) 

Thanks

#2

People will be able to help you better if you share your model.

#3

I hope the example will make clear what I am asking… it might be super simple but I am new and I can’t see any solution

#4

For example

M_mu[1] ~ normal(1,2);
M_mu[2] ~ normal(2,3);
M_mu[3] ~ normal(3,4);
M_mu[4] ~ normal(4,5);
M_mu[5] ~ normal(5,6);