views:

481

answers:

3

The following code of mine compute the confidence interval using Chi-square's 'quantile' and probability function from Boost.

I am trying to implement this function as to avoid dependency to Boost. Is there any resource where can I find such implementation?

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

using namespace std;     
using boost::math::chi_squared; 
using boost::math::quantile;

vector <double> ConfidenceInterval(double x) {
     vector <double> ConfInts; 

     // x is an estimated value in which
     // we want to derive the confidence interval.

        chi_squared distl(2);     
        chi_squared distu((x+1)*2);

        double alpha = 0.90;      

        double lower_limit = 0;   

        if (x != 0) {
          chi_squared distl(x*2);   
          lower_limit = (quantile(distl,((1-alpha)/2)))/2;
        }

        double upper_limit = (quantile(distu,1-((1-alpha)/2)))/2;

        //cout << x << "\t";      
        //cout << setprecision(5) << setw(10)  << lower_limit << "\t"; 
        //cout << setprecision(5) << setw(10)  << upper_limit << endl; 

        ConfInts.push_back(lower_limit);
        ConfInts.push_back(upper_limit);


        return ConfInts;

}
A: 

Have a look at the Gnu Scientific library. Or look in Numerical Recipes. There's also a Java version in Apache Commons Math, which should be straightforward to translate.

Charlie Martin
@Charlie: my intention is to be independent from library. GSL code has many dependencies.
neversaint
A: 

I don't understand your question. Either you have to be dependent on Boost or some other library (or copy their code), or you have to write the code yourself. What kind of "resources" are you looking for?

anon
+2  A: 

If you're looking for source code you can copy/paste, here are some links:

YMMV...

bubaker