adoDojo
adoDojo

Reputation: 31

Calculating Inverse_chi_squared_distribution using boost

I'm trying to implement a function to calculate inverse_chi_squared_distribution, boost has a container named inverse_chi_squared_distribution, however, when I try to create an instance of the class I get this error too few template arguments for class template 'inverse_chi_squared_distribution'. I'm on wsl:ubuntu-18.04 and other boost functions/containers work fine.

Here's the code generating the error: boost::math::inverse_chi_squared_distribution<double> invChi(degValue);

Not exactly sure how to calculate it even if this instance is created (was gonna just hit and miss till I get it) so help using this to calculate the function would be much appreciated, thanks.

Upvotes: 1

Views: 657

Answers (1)

John Maddock
John Maddock

Reputation: 11

OK, do you want the inverse of a chi-squared distribution (ie its quantile) or do you want the "inverse chi squared distribution" which is a distribution in it's own right, also with an inverse/quantile!

If the former, then assuming v degrees of freedom, and probability p then this would do it:

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

double chi_squared_quantile(double v, double p)
{
   return quantile(boost::math::chi_squared(v), p);
}

If the latter, then example usages might be:

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

double inverse_chi_squared_quantile(double v, double p)
{
   return quantile(boost::math::inverse_chi_squared(v), p);
}
double inverse_chi_squared_pdf(double v, double x)
{
   return pdf(boost::math::inverse_chi_squared(v), x);
}
double inverse_chi_squared_cdf(double v, double x)
{
   return cdf(boost::math::inverse_chi_squared(v), x);
}

There are other options - you can calculate with types other than double then you would use boost::math::inverse_chi_squared_distribution<MyType> in place of the convenience typedef inverse_chi_squared.

Upvotes: 1

Related Questions