Dear all,
(I am using cmdstan in r.)
Thanks for your attention first of all. I am writing this post to ask why creating an intermediate variable would fail my working model and how to solve the issue. Specifically, I have a basic model which works perfectly as below:
data{
int<lower=1> N;
int<lower=1> N_papers;
vector[N] coef;
array[N] int<lower = 1, upper = N> paper_nr;
vector<lower=0>[N] se;
}
parameters{
vector<lower=0>[N] coefhat;
real<lower=0> df;
vector<lower=0>[N_papers] coefpaper;
real<lower=0> sigma_paper;
real mu_l;
real<lower=0> sigma_l;
}
model{
// priors:
sigma_paper ~ normal( 0 , 5 );
mu_l ~ normal( 1 , 5 );
sigma_l ~ normal( 0 , 5 );
coef ~ normal( coefhat , se );
coefhat ~ student_t(df , coefpaper[paper_nr] , sigma_paper );
coefpaper ~ lognormal( mu_l , sigma_l );
}
Now, as I want to add a linear regression part to the model, I have to create an intermediate variable as the dependent variable. To check the validity, I thus initially adapt my basic model as below (please note the commented line is the final version I want to achieve, where Q is the transformed matrix of independent variables):
data{
int<lower=1> N;
int<lower=1> K;
int<lower=1> N_papers;
vector[N] coef;
array[N] int<lower = 1, upper = N> paper_nr;
vector[N] se;
}
parameters{
vector<lower=0>[N] coefhat;
real<lower=0> df;
vector<lower=0>[N_papers] coefpaper;
real<lower=0> sigma_paper;
real mu_l;
real<lower=0> sigma_l;
}
model{
vector[N] omega;
sigma_l ~ normal( 0 , 5 );
sigma_paper ~ normal( 0 , 5 );
mu_l ~ normal( 1 , 5 );
coef ~ normal( coefhat , se );
// omega = Q * beta_tilde + coefpaper[paper_nr];
omega = coefpaper[paper_nr];
coefhat ~ student_t(df , omega, sigma_paper );
omega ~ lognormal( mu_l , sigma_l );
}
Now, the model has difficulty in fitting (the four chains are not mixed). I have tried to adjust initial values but it does not work.
Could you please share your knowledge of this case and tell me any potential approach I can attempt to solve it?
Thank you very much.
Elon