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

Incomplete Beta Inverse #2513

Closed
spinkney opened this issue Jun 23, 2021 · 9 comments
Closed

Incomplete Beta Inverse #2513

spinkney opened this issue Jun 23, 2021 · 9 comments

Comments

@spinkney
Copy link
Collaborator

Description

Add incomplete beta inverse. This is needed for the quantile function of the beta distribution (if or when quantile functions get added). By having this available to users they can define the quantile function of the beta distribution as well as the quantile function of the skewed generalized t distribution

The function is available in boost at https://www.boost.org/doc/libs/1_74_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html

The derivative is defined at https://functions.wolfram.com/GammaBetaErf/InverseBetaRegularized/20/01/01/

@andrjohns
Copy link
Collaborator

Im actually planning on working on through the quantile functions (starting with the Gamma distribution at the moment), so this is already on my to-do list (unless you've already started!)

@spinkney
Copy link
Collaborator Author

Nice! I have some icdfs at https://github.com/spinkney/helpful_stan_functions/tree/main/functions%2Finverse_cdf.

If the quantile functions are getting implemented, I think I'll start a discussion on copula functions and their design.

@spinkney
Copy link
Collaborator Author

Do you know if there's any discussion on a reserved name for these? Should it be icdf or quantile?

@andrjohns
Copy link
Collaborator

I was planning on proposing using the _icdf suffix, so that it's all consistent with the lpdf/lcdf/lccdf naming scheme, but no actual discussion yet

@spinkney
Copy link
Collaborator Author

spinkney commented Jul 2, 2021

@andrjohns is it possible to also expose this function when you add the icdfs? This functionay be useful for user defined icdfs in the future

@andrjohns
Copy link
Collaborator

Yep! The plan is to expose all of the intermediary functions. This function is just waiting on the Hypergeometric pFq, which is needed for the derivatives wrt a and b

@spinkney
Copy link
Collaborator Author

spinkney commented Jul 4, 2021

Well, I found an implementation that wasn't too hard to write in Stan. The stan code is at https://github.com/spinkney/helpful_stan_functions/blob/main/functions/special/inc_beta_inverse.stanfunctions.

I checked the output on a few cases compared to qbeta in R. Not sure if you want to test against boosts version or not.

@spinkney spinkney closed this as completed Jul 4, 2021
@spinkney spinkney reopened this Jul 4, 2021
@spinkney
Copy link
Collaborator Author

@andrjohns there's a wealth of inverse cdf's here https://people.sc.fsu.edu/~jburkardt/cpp_src/cpp_src.html. I'm going to put some together in Stan but can start trying to get some into the cpp. I want to get this beta one in soon as it allows the beta, student_t, skew_student_t, and probably others right off the bat.

@bgoodri has made a good case for _qf as the suffix, especially if we start implementing the derivative of those (which we should!) and then call them _dqf and _ldqf. In addition, I've already added syntax highlighting for the _qf in the highlights.js.

Look at this student_t_qf:

# http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/JCF_Student.pdf
qt2 <- function(u, nu){
  x <- ifelse (u < 0.5, 2 * u, 2 * (1 - u))
  sign(u - 0.5) * sqrt( nu * (1 / (qbeta(x, shape1=nu / 2, shape2= 0.5))) - 1)
}

all.equal(qt2(0.2, 1), qt(0.2, 1))

@andrjohns
Copy link
Collaborator

Oh excellent, thanks for prompting me on this! Will get into having a look at those

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

No branches or pull requests

3 participants