# Implementing skew-t log-likelihood

**URL:** <https://discourse.mc-stan.org/t/implementing-skew-t-log-likelihood/7990>\
**Category:** Modeling\
**Created:** [March 9, 2019, 2:37am UTC](https://discourse.mc-stan.org/t/implementing-skew-t-log-likelihood/7990 "2019-03-09T02:37:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![siharnik](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@siharnik](https://discourse.mc-stan.org/u/siharnik)\
**Post date:** [March 9, 2019, 2:37am UTC](https://discourse.mc-stan.org/t/implementing-skew-t-log-likelihood/7990/1 "2019-03-09T02:37:24Z")

</div>

Hello,  
I am trying to implement univariate skew-t log-likelihood. There are some topics on this subject here in this forum and I am following the ideas I read.  
Univariate skew-t pdf has the following expression an is implemented in R package “sn”:

![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/c0b8d1c2d5e1a9ca5b23017e9616117e9b345659.png)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/c57b996e825c1cb1e3e7545105997ac69ec1a1a2.png)

I wrote this code for the function:

functions{  
real skew\_t\_lpdf(vector x, real xi, real omega, real alpha){  
vector[num\_elements(x)] prob;  
real lprob;  
real z;  
real zc;  
real nu;  
nu = 5;  
for (i in 1:num\_elements(x)){  
z = (x[i]-xi)/omega;  
zc = z_alpha_sqrt((nu+1)/(nu + pow(z, 2)));  
prob[i] = student\_t\_lpdf(x[i] | nu, xi, omega) + student\_t\_lcdf(zc | nu+1, 0, 1);  
}  
lprob = sum(prob);  
return lprob;  
}  
}

I dropped constants and it seems to work fine with simulated data. However, if I change arguments in student\_t\_lpdf, everything goes wrong and estimates far from what would be expected.

Instead of using student\_t\_lpdf(x[i] | nu, xi, omega), I changed for student\_t\_lpdf(z | nu, 0, 1). I can’t understand this behavior.

Can anyone help me with this issue? Do I need to provide more code?  
Thanks!

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [March 18, 2019, 12:28pm UTC](https://discourse.mc-stan.org/t/implementing-skew-t-log-likelihood/7990/2 "2019-03-18T12:28:36Z")

</div>

Please use triple backticks (`````) to mark the start and end of your code block to make it more readable. Note also that single backticks may be used to mark inline code in other text.
