Hello,

The current implementation of the chi-squared distribution pdf in GSL
returns 0.0 for inputs with x<=0.0.

The domain of this function is [0.0, inf), (see e.g. Abramovitz-Stegun
here: http://people.math.sfu.ca/~cbm/aands/page_940.htm ),
so wrong values at x=0.0 are returned for nu=1.0
(gsl_ran_chisq_pdf(0.0, 1.0) should be inf) and nu=2.0 (should be
0.5).

Attached is a patch which fixes this.

Best,

Teemu
=== modified file 'randist/chisq.c'
--- randist/chisq.c	2007-09-10 18:09:35 +0000
+++ randist/chisq.c	2010-11-10 13:19:34 +0000
@@ -39,16 +39,23 @@
 double
 gsl_ran_chisq_pdf (const double x, const double nu)
 {
-  if (x <= 0)
+  if (x < 0)
     {
       return 0 ;
     }
   else
     {
-      double p;
-      double lngamma = gsl_sf_lngamma (nu / 2);
-      
-      p = exp ((nu / 2 - 1) * log (x/2) - x/2 - lngamma) / 2;
-      return p;
+      if(nu == 2.0)
+        {
+          return exp(-x/2.0 - log(2.0));
+        }
+      else
+        {
+          double p;
+          double lngamma = gsl_sf_lngamma (nu / 2);
+
+          p = exp ((nu / 2 - 1) * log (x/2) - x/2 - lngamma) / 2;
+          return p;
+        }
     }
 }

_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl

Reply via email to