Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add student_t_qf #2752

Open
spinkney opened this issue Jun 6, 2022 · 1 comment
Open

Add student_t_qf #2752

spinkney opened this issue Jun 6, 2022 · 1 comment
Assignees

Comments

@spinkney
Copy link
Collaborator

spinkney commented Jun 6, 2022

Description

With the incorporation of inv_inc_beta from pr #2637 it is easy to add. Will follow the organization of the files from the std_normal_qf pr #2744

Example

student_t_qf(real u, real nu) 
student_t_qf(real u, vector nu) 
student_t_qf(real u, array[] real nu) 
student_t_qf(vector u, real nu) 
student_t_qf(vector u, vector nu) 
student_t_qf(vector u, array[] real nu) 
student_t_qf(array[] real u, real nu) 
student_t_qf(array[] real u, vector nu) 
student_t_qf(array[] real u, array[] real nu) 

// implementation is simple
student_t_qf(real u, real nu)  {
  real x = u < 0.5 ? 2 * u : 2 * (1 - u);
  return sign(u - 0.5) * sqrt( nu * (1 / (inv_inc_beta(nu / 2, 0.5, x))) - 1);
}
// where 
// inv_inc_beta(a, b, p)
//  * @param a Shape parameter a >= 0; a and b can't both be 0
// * @param b Shape parameter b >= 0
// * @param p Random variate. 0 <= p <= 1
@spinkney spinkney self-assigned this Jun 6, 2022
@spinkney
Copy link
Collaborator Author

spinkney commented Jun 13, 2022

I believe I can wrap the qf from boost. They say that the method is faster than using the inv_inc_beta implementation above. You can see the comment in boost at https://github.com/boostorg/math/blob/b2538faaf9802af8e856c603b9001e33db826676/include/boost/math/distributions/students_t.hpp#L251.

However, I need to add the derivatives. Luckily, the 2nd value of the inv_inc_beta is a constant. I can reuse the implementation that is already in stan-math for that part. The method above can be auto-diffed through to test my implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant