Skip to content
Prev 167462 / 398502 Next

pchisq error

Dear R experts,

I'm trying to call 'pchisq' from within a C subroutine. The following
error is returned:

   ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.

This error message is not printed the first time I call 'pchisq' from
the C subroutine, but the second time or the next time I call 'pchisq'
from within R.

My session output is shown below:

######################
make: `reproduceError.so' is up to date.
+   dyn.load('reproduceError.so')

+   .C('tempCfunction',as.double(x))

+   dyn.unload('reproduceError.so')

+   invisible(NULL)

+ }
[1] 0.01940836
stat = 5.464342, p = 0.019408
[1] NaN

Warning messages:

1: In pchisq(5.464342, 1, lower.tail = FALSE) :

   ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.

2: In pchisq(q, df, lower.tail, log.p) : NaNs produced
stat = 5.464342, p = 0.019408
stat = 5.464342, p = nan

Warning message:

In reproduceError(5.464342) :

   ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.
[1] NaN

Warning messages:

1: In pchisq(5.464342, 1, lower.tail = FALSE) :

   ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.

2: In pchisq(q, df, lower.tail, log.p) : NaNs produced
[1] 0.01940836
[1] 0.01940836
R version 2.8.0 (2008-10-20) 

i686-pc-linux-gnu 

locale:

LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base     

#############################


The C file (reproduceError.c) with the subroutine tempCfunction is:

#############################

#include <stdio.h>

#include <Rmath.h>

#include <R.h>

#include <Rinternals.h>

#include <string.h>

double tempCfunction(double *x){

  double stat = x[0];

  double pval = pchisq(stat, 1.0 , 0, 0);

  printf("stat = %f, p = %f\n",stat,pval);

  

  return pval;

}

#############################

Can anybody explain this behaviour?

Thanks,

Jeremy