I would like to fit a mixture of two von Mises distribution to data points with two peaks at 0 and \pi. Below is the complete script that I have written for this purpose:

```
library(rstan)
rstan_options(auto_write = TRUE)
model_code <- "
data {
int<lower=0> N;
vector[N] y;
}
parameters {
simplex[2] theta;
vector[2] kappa_link;
vector[2] mu_link;
}
model {
real ps[2];
real kappa[2];
real mu[2];
mu_link ~ normal(0,5);
kappa_link ~ normal(0,2);
mu[1] = 2*atan(mu_link[1]);
mu[2] = 2*atan(mu_link[2]);
kappa[1] = exp(kappa_link[1]);
kappa[2] = exp(kappa_link[2]);
for (n in 1:N) {
if (kappa[1] < 100) {
ps[1] = log(theta[1]) + von_mises_lpdf(y[n] | mu[1], kappa[1]);
}
else {
ps[1] = log(theta[1]) + normal_lpdf(y[n] | mu[1], sqrt(1/kappa[1]));
}
if (kappa[2] < 100) {
ps[2] = log(theta[2]) + von_mises_lpdf(y[n] | mu[2], kappa[2]);
}
else {
ps[2] = log(theta[2]) + normal_lpdf(y[n] | mu[2], sqrt(1/kappa[2]));
}
target += log_sum_exp(ps);
}
}"
N <- 200
weight <- 0.7
y1 <- rep(0, N*weight)
y2 <- rep(pi, N*(1-weight))
Y <- c(y1, y2)
model <- stan_model(model_code = model_code, allow_undefined = TRUE,
verbose = TRUE)
m <- sampling(model, data = list(N=N, y=Y), chains = 1)
m_summary <- summary(m)
vals <- m_summary$summary[, 'mean']
kappa1 <- exp(vals['kappa_link[1]'])
kappa2 <- exp(vals['kappa_link[2]'])
mu1 <- 2*atan(vals['mu_link[1]'])
mu2 <- 2*atan(vals['mu_link[2]'])
print(c(kappa1, kappa2, mu1, mu2))
```

At the end of the sampling run, I am getting the following warning messages:

1: There were 971 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See

http://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded 2: Examine the pairs() plot to diagnose sampling problems

3: The largest R-hat is 1.93, indicating chains have not mixed.

Running the chains for more iterations may help. See

http://mc-stan.org/misc/warnings.html#r-hat

4: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.

Running the chains for more iterations may help. See

http://mc-stan.org/misc/warnings.html#bulk-ess

5: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.

I have looked at the provided links above and increased the max_treedepth to above 10 but I am not getting any improvements. I am unsure what are the steps that I can take to improve the model. I appreciate any help to move forward.