How to implement ADVI

Hi guys, I am very new to Stan. I currently have a model here. I am wondering how could I adjust to use ADVI? Would ADVI be faster than MCMC? Thank you for your help! Any advice would be awesome!

functions {
real betaModeConc_lpdf(real parm,real m,real c) {
return beta_lpdf(parm|m*(c-2)+1, (1-m)*(c-2)+1);

data {
int<lower=0> N_DNA;
int<lower=0> a[N_DNA];
int<lower=0> b[N_DNA];
int<lower=0> N_RNA;
int<lower=0> k[N_RNA];
int<lower=0> m[N_RNA];

parameters {
real<lower=0,upper=1> p;
real<lower=0,upper=1> qi[N_RNA];
real<lower=0> theta;
real<lower=2> c;
real<lower=0> s;

transformed parameters {
real<lower=0,upper=1> q;

model {
// Parameters:
c ~ gamma(1.1, 0.0005);
s ~ gamma(1.1,3);
log(theta)/s ~ normal(0,1);
for(i in 1:N_RNA)
qi[i] ~ betaModeConc(q,c);

// Likelihoods:
for(i in 1:N_DNA)
a[i] ~ binomial(a[i]+b[i],p);
for(i in 1:N_RNA)
k[i] ~ binomial(k[i]+m[i],qi[i]);

If you’re not that familiar with the model, start with MCMC and try to make it fast. There are lots of MCMC diagnostics in Stan right now.

I think it’s fair to say, the same things you’d do to make MCMC fast are the same things that’ll make ADVI fast/work in the end anyway.

Is this model something that you’ve just started working on? Or have you already got it sampling well? Is it a performance problem that makes you want to use ADVI?

I don’t think that model compiles—where is thetap defined? And if it were, are the right constraints in place to make sure q satisfies the declared constraints?