You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/jeZQnQRUsDs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Hi Bob,
The function I implemented is as follows:
real skew_student_t_log(real y, real nu, real mu, real sigma, real skew) {
real lp;
lp <- 0;
if (skew<=0)
reject("skew has to be positive. Found skew=",skew);
if (y<mu)
lp<- student_t_log(y*skew, nu, mu*skew, sigma);
else
lp<- student_t_log(y/skew, nu, mu/skew, sigma);
lp <- lp + log(2*skew)-log(1+skew*skew);
return lp;
}
and I call it like this:
y ~ skew_student_t(nu, mu, sigma, skew);
It follows Fernandez, C. and Steel definition, also used by R package skewt (except that they do not use sigma or mu).
I did not attempt to code as per newer definition by Azzalini and Capitanio, because it requires multiplying the density by the cumulative distribution, and the latter has reportedly some numerical problems if used in this way: https://groups.google.com/forum/?fromgroups#!searchin/stan-users/skew$20student/stan-users/j44ipDdQep8/kIx4bC2GsA4J
That’s great, but e.g. I do not know how to efficiently sample from this distribution, and I would like to do it in generated quantities block.
So, looking forward for a full implementation of the Skew Student in Stan, yours :-)
Slawek
You can drop the multiplier 2 in the adjustment, because
log(2 * skew) = log(2) = log(skew)
and Stan only needs densities up to an additive constant.
real skew_student_t_log(real y, real nu, real mu, real sigma, real skew) {
real z; real zc;
if (sigma <= 0)
reject("Scale has to be positive. Found sigma=", sigma);
z<- (y-mu)/sigma;
zc<- skew*z*sqrt((nu+1)/(nu+square(z)));
return -log(sigma) + student_t_log(z, nu, 0, 1) + student_t_cdf_log(zc, nu+1, 0, 1);
}
Regards,
Slawek
- Bob