# Hierarchical model with correlated parameters have non-smooth density

Dear all,

This is my first attempt for considering nonlinear multilevel hierarchical model. In the following code, I have tried to simulate parameters from prior following Stan manual. I have some concerns about the code:

1. When I simulated from the priors, the density plots are not smooth at all for some parameters, Is that okay? see attached figure.
2. All parameters in the matrix theta_raw should be positive, for biologically meaningful, how do I amend the code to make this possible?
3. A typical value for each parameter is given in the mu_a vector. At present I am not sure how to transform the sampled values in theta_raw close to the same scale as their typical values.

Any help with these are highly appreciated.

``````data {
int<lower=1> J;    //number of subjects
int<lower =1> K;   // number of parameters
vector[K] mu_a;    // Typical values
}

transformed data {
}
parameters{
matrix[J,K] a;
vector<lower = 0, upper = pi()/2>[K] tau_unif;       // tau_unif is used to reparametrise tau
cholesky_factor_corr[K] L_Omega;
matrix[K,J] z;                  //standard normal variates
}

transformed parameters {
matrix[J,K] b;
vector<lower=0>[K] tau;
matrix[J,K] theta_raw;
for(k in 1:K) tau[k] = 2.5*tan(tau_unif[k]);
b = (diag_pre_multiply(tau, L_Omega)*z)';
theta_raw = a +b;
}

model{
to_vector(a) ~ normal(0, 5);
L_Omega ~ lkj_corr_cholesky(2);
to_vector(z) ~ normal(0,1);
}
``````
``````sim_data <- list(J = 25,
K = 8,
mu_a = c(1.4e6, 6.66e-11, 6,5, 1e4, 3.7,4e4,1e-4)
)

fit_model <- stan("stan_code.stan",
data = sim_data,
chains = 4, iter = 4500,warmup = 1000,
control = list(adapt_delta = 0.8, max_treedepth = 10),
seed=12345
)