Hi. When running my Stan code I receive “Parser warning” related to the “Jacobian warning”. I have used the following page: http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup to investigate the potential error, but as far as I can see, the gradient of the transformation regarding Z is equal to zero. It that correct? Or have I misunderstood something? Code is given below:
functions {
//Multivariate skewed t-distribution (Sahu, Dey & Branco, 2003)
real MskT_lpdf(real z, real nu, real xi){
real a = (tgamma((nu-1)/2)*sqrt(nu-2))/(sqrt(pi())*tgamma(nu/2))*(xi-1/xi);
real b = sqrt(pow(xi,2)+1/pow(xi,2)-1-pow(a,2));
real k = (-a/b >= z ? (b*z+a)*xi : (b*z+a)/xi);
return log(2*b/(xi+1/xi)) + lgamma((nu+1)/2)-(log(sqrt(pi()*(nu-2)))+lgamma(nu/2))-((nu+1)/2)*log(1+(pow(k,2)/(nu-2)));
}
}
data {
int<lower=0> T; //number of observations
real r[T]; //return data - notice, cannot med -100%, as this will results in negative prices
real<lower=0> sigma1; //First sigma
real omg_p;
real omg_q;
real psi_p;
real psi_q;
real alpha_q;
real alpha_p;
real lam_p;
real lam_q;
real mu_mu;
real mu_sigma;
real nu_p;
real nu_q;
real xi_p;
real xi_q;
}
parameters {
real mu;
real<lower=0,upper=1> omg; //Cannot be negative to ensure positive variance
real<lower=0,upper=1> alpha; //Cannot be negative to ensure positive variance
real<lower=0, upper=1> psi; //Cannot be negative to ensure positive variance
real<lower=0, upper=1> lam; //Cannot be negative to ensure positive variance
real<lower = 4> nu;
real<lower = 0> xi;
}
transformed parameters{
real<lower=0> sigma[T]; //Lower limit as it cannot be negative
real<lower=0, upper=(1-alpha-psi/2)> bet; //Upper limit to ensure stationarity
real inn[T];
sigma[1] = sigma1;
bet = lam - alpha - psi/2;
inn[1] = (r[1]-mu) / sigma[1];
for (t in 2:T){
sigma[t] = sqrt(omg + (alpha + psi*step(mu-r[t - 1]))*pow(r[t - 1] - mu,2) + bet*pow(sigma[t-1],2));
inn[t] = (r[t]-mu)/sigma[t];
}
}
model {
//Data distribution - model
for(t in 1:T){
inn[t]~MskT(nu,xi);
}
//prior distributions
omg~beta(omg_p, omg_q);
psi~beta(psi_p, psi_q);
alpha~beta(alpha_p, alpha_q);
lam~beta(lam_p, lam_q);
mu~normal(mu_mu, mu_sigma);
nu~normal(nu_p, nu_q);
xi~normal(xi_p, xi_q);
}
[edit: escaped code]