Gurung Buddha
Gurung Buddha

Reputation: 33

T distribution formula for Percent Point Function

I used python scipy library to get the ppf value. I am trying to calculate the ppf in c++ without using python. I went through many articles online but couldn't find one. Can any one help me to get ppf in c++.

In python:

>>> from scipy.stats import t
>>> t.ppf(0.75,29)
0.6830438592467807

Likewise, In c++ I want a function passing two variables (0.75,29) and return the ppf value 0.6830438592467808 .

Upvotes: 3

Views: 647

Answers (1)

jack
jack

Reputation: 1790

The boost library contains all you need to compute quantiles (aka percent point function).

A possible implementation:

#include <boost/math/distributions/students_t.hpp>

double ppf(double q, double df) {
    boost::math::students_t dist(df);
    return boost::math::quantile(dist, q);
}

See also this godbolt link.

Reference links: scipy's student t, boost's student t, boost's quantile

Upvotes: 5

Related Questions