# Skew T distribution in Stan

Hi @andrjohns , I have the same problem as @Nelson_Lima_de_Souza_Filh , but for the construction of the skew t distribution lcdf and lpdf, could you help me?

This is a trickier one. According to Eq 1.1 here the PDF for the univariate Skew-T with location \mu, scale \sigma, df \nu and skewness \lambda is given by:

f(y;\mu,\sigma,\nu,\lambda)=2\sigma^{-1}t(z;\nu)T(\lambda z \tau; \nu+1)

Where:

z = \frac{y - \mu}{\sigma} \\ \tau = \left(\frac{\nu + 1}{z^2 +\nu}\right)^{1/2}

And T(;) and t(;) are the PDF and CDF, respectively, of the standard student’s T.

We could specify the log of this PDF in Stan as:

functions {
real skew_t_lpdf(real y, real mu, real sigma, real nu, real lambda) {
real z = (y - mu) / sigma;
real tau = sqrt((nu + 1) / (z^2 + nu));
real t_lcdf = student_t_lcdf(z, nu, 0, 1);
real t_lpdf = student_t_lpdf(lambda*z*tau, nu+1, 0, 1);

return log2() + -1*log(sigma) + t_lcdf + t_lpdf;
}
}


Note that this is completely untested, so I would recommend verifying against known-good values (or an implementation in another package, like R)

I couldn’t find a definition of the CDF for the skew t, so I can’t be much help there unfortunately

1 Like

Skew t cdf

Looks fun

3 Likes

Hi @spinkney , I appreciate your contribution but as I have little experience in stan programming I wouldn’t know how to write this code in stan.

Is there a way to create the cdf just like the integral of the pdf?

It would be useful to add skew-t to Stan if you can get it working well.

1 Like

I moved all these posts to a new topic as it’s unrelated to the slash and skew slash

I have the generalized_skew_t lpdf and lcdf functions at helpful_stan_functions/skew_generalized_t.stanfunctions at main · spinkney/helpful_stan_functions · GitHub.

These reduce to skew T by setting p = 2. However, it appears that the parameterization is different from the sn R package. Due to the use of lambda which is between -1, 1. The Skew T that it reduces to is the skew T from https://www.ssc.wisc.edu/~bhansen/papers/ier_94.pdf equation 10 (p. 710, pdf p. 6).

I also have the quantile function in that repo for this distribution.

5 Likes