We want to create a joint distribution by User-Defined Functions then caculate by stan. But the warning messages in the end “all iterations ended with a divergence and high R-hat”. We also try to increasing the `adapt_delta`

parameter and iterations and it seems to be work(R-hat decreased but it still larger than 1.1). We think chains have not mixed still. Some expertor said “Reparameterization” is first. But in

stan-users-guide, it is only example for Beta and Dirichlet Priors or Normal Distribution. For user-defined distribution, what should we do or could we transform priors(probit and logit). I would be really grateful in case you have any advice here.

Thanks a lot!

```
functions{
real joint_lpdf(matrix p_i, vector alpha, vector beta, real omega){
}
data{
int N;
int Nt;
int Ns;
int TP[N];
int Dis[N];
int TN[N];
int NDis[N];
int Study[N];
int Test[N];
int Total[N]; //n_ijk
}
parameters{
vector<lower=0, upper=1>[3] MU[Nt]; //mu_jk
vector<lower=0, upper=1>[3] delta[Nt]; //delta_jk
vector<lower=0, upper=1>[3] theta; //theta_j
matrix<lower=0, upper=1>[Ns, 3] p_i[Nt]; //pi_ijk
vector[Nt] omega; //omega_k
}
transformed parameters{
vector<lower=0>[3] alpha[Nt]; //alpha_jk
vector<lower=0>[3] beta[Nt]; //beta_jk
for(k in 1:Nt){
alpha[k] = (MU[k]).*((1 - (theta).*(delta[k]))./((theta).*(delta[k])));
beta[k] = (1 - MU[k]).*((1 - (theta).*(delta[k]))./((theta).*(delta[k])));
}
}
model{
//Priors
for (k in 1:Nt){
MU[k] ~ uniform(0, 1);
delta[k] ~ uniform(0, 1);
}
theta ~ uniform(0, 1);
omega ~ normal(0, 5);
for (k in 1:Nt)
p_i[k] ~ joint(alpha[k], beta[k], omega[k]);
for (n in 1:N){
TP[n] ~ binomial(Dis[n], p_i[Test[n]][Study[n], 1]);
TN[n] ~ binomial(NDis[n], p_i[Test[n]][Study[n], 2]);
Dis[n] ~ binomial(Total[n], p_i[Test[n]][Study[n], 3]);
}
}
generated quantities{
vector[3*N] loglik;
for (n in 1:N)
loglik[n] = binomial_lpmf(TN[n]| NDis[n], p_i[Test[n]][Study[n], 1]);
for (n in (N+1):(2*N))
loglik[n] = binomial_lpmf(TN[n-N]| NDis[n-N], p_i[Test[n-N]][Study[n-N], 2]);
for (n in (2*N+1):(3*N))
loglik[n] = binomial_lpmf(TN[n-2*N]| NDis[n-2*N], p_i[Test[n-2*N]][Study[n-2*N], 3]);
}
"
```

I would be really grateful in case you have any advice here.

Thanks a lot!