Sciencemadness Discussion Board

need help coding a chi-squared function

spirocycle - 19-5-2011 at 16:45

I'm working on a program used to calculate confidence intervals for age-adjusted cancer rates based on the Fay Feuer method.
I've got all the bits hammered out except one major piece: the inverse-chi-squared function.

I have a pretty sneaky method that uses a binary guessing system to converge on the target value, but that hinged on a working chi-squared CDF function.

This is where my skills fail!

My current attempt was approximating the integral using simpson's method. The major problem with this is that I cant integrate from 0 when the degrees of freedom are less than two, because a horizontal asymptote appears. If I try to start the integration from an arbitrarily small value (0.0001 or so), I either get a math overflow error or a very innaccurate result. Any suggestions?