# Boost Users :

Subject: Re: [Boost-users] [math/distributions] Problem using inv-chi**2 andquantiles
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-06-14 12:15:27

> I'm trying to duplicate Excel's CHIINV to calculate confidence limits
> for an observed number of events. I think I'm nearly there, largely as a
> result of trial and error, but the boost results still significantly
> differ from the Excel results, so I've presumably messed up somewhere.
> Any advice will be *greatly* appreciated.
>
> The Excel formulas I'm using are:
>
> lo limit = CHIINV((1+\$C\$3)/2, 2*B6)/2
> hi limit = CHIINV((1-\$C\$3)/2, 2*(B6+1))/2
>
> where \$C\$3 is the confidence level required (95%), and B6 is the number
> of events observed. In Excel, 'CHIINV' is documented as:
>
>> CHIINV(probability,degrees_freedom)
>> Probability is a probability associated with the chi-squared
>> distribution.
>> Degrees_freedom is the number of degrees of freedom.
>
> For 17 events, for example, Excel is producing limits of [9.90, 27.22].
>
> I've attached my complete boost test program below, which I hope does
> the same thing, but there was a large amount of guesswork here. This
> program produces results of [10.67, 25.98] for 17 events.
>
> Can anyone tell me what I'm doing wrong?

quantile(boost::math::chi_squared(2*17), (0.05)/2) / 2

and

quantile(boost::math::chi_squared(2*17), (0.95)/2) / 2

should reproduce your EXCEL results, but they're not formula's I recognize
for chi squared confidence limits, so I'll leave it for you to decide if
this is what you actually want ;-)

HTH, John.