Skip to content

ENH: add parameter finder for degrees or freedom for students_t distribution#1385

Open
dschmitz89 wants to merge 3 commits intoboostorg:developfrom
dschmitz89:invert_student_t_to_df
Open

ENH: add parameter finder for degrees or freedom for students_t distribution#1385
dschmitz89 wants to merge 3 commits intoboostorg:developfrom
dschmitz89:invert_student_t_to_df

Conversation

@dschmitz89
Copy link
Copy Markdown
Contributor

Towards #1305

This adds a parameter finder for the student t distribution with respect to the degrees or freedom.

Disclaimer: this PR is heavily LLM supported as C++ is not (yet?) my forte.

I verified the math with a simple Python program before. I also ran a simple sanity script to see that the function actually executes. I am not so confident about the tests though as I cannot really decipher the output of b2.

Approach: We use bracket_and_solve_root with an initial guess from a second order Edgeworth expansion of the CDF. The initial guess is very good for $df > 10$ but useless for low degrees of freedom as it returns NaN. In this case or if it gives a relative error of the CDF worse than 10%, we fall back to an initial guess of 0.01.

Detailed approach for finding the initial guess

Given a quantile $x$ and a CDF value $p = P(T \leq x)$, we want to recover the degrees of freedom $\nu$.

Step 1 — Edgeworth warm start.

We use the 2nd-order Edgeworth expansion of the $t$ CDF in powers of $1/\nu$:

$$F(x;\nu) \approx \Phi(x) - \frac{\varphi(x)(x + x^3)}{4\nu} + \frac{\varphi(x)(3x + 5x^3 + 7x^5 - 3x^7)}{96\nu^2}$$
where $\Phi(x)$ is the standard normal CDF and $\phi(x)$ the standard normal PDF.
Setting $u = 1/\nu$ and $F(x;\nu) = p$ yields the quadratic

$$B u^2 - A u + (\Phi(x) - p) = 0$$

where

$$A = \frac{\varphi(x)(x + x^3)}{4}, \qquad B = \frac{\varphi(x)(3x + 5x^3 + 7x^5 - 3x^7)}{96}$$

The physically meaningful root (smallest positive $u$, i.e. largest $\nu$) gives a closed-form starting estimate $\hat\nu = 1/u$.

Step 2 — Validation.

We plug $\hat\nu$ into the exact $t$ CDF. If the relative residual $|F(x;\hat\nu) - p|/|p|$ exceeds 10%, we fall back to a safe low starting value $\nu_0 = 10^{-2}$.

@dschmitz89 dschmitz89 changed the title ENH: add parameter finder for degrees or freedom ENH: add parameter finder for degrees or freedom for students_t distribution Apr 12, 2026
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

Successfully merging this pull request may close these issues.

1 participant