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: ######################> system('R CMD SHLIB reproduceError.c')make: `reproduceError.so' is up to date.>> reproduceError <- function(x){+ dyn.load('reproduceError.so') + .C('tempCfunction',as.double(x)) + dyn.unload('reproduceError.so') + invisible(NULL) + }>> pchisq(5.464342,1,lower.tail = FALSE)[1] 0.01940836> reproduceError(5.464342)stat = 5.464342, p = 0.019408> pchisq(5.464342,1,lower.tail = FALSE)[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> reproduceError(5.464342)stat = 5.464342, p = 0.019408> reproduceError(5.464342)stat = 5.464342, p = nan Warning message: In reproduceError(5.464342) : ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.> pchisq(5.464342,1,lower.tail = FALSE)[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> pchisq(5.464342,1,lower.tail = FALSE)[1] 0.01940836> pchisq(5.464342,1,lower.tail = FALSE)[1] 0.01940836>> sessionInfo()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 -- /**************************************** Jeremy Silver Research Assistant University of Copenhagen, Denmark ph: +45 3532 7917 email: j.silver at biostat.ku.dk or jere at pubhealth.ku.dk
I don't get the error, but I assume it's because your C function returns
a double and .C() assumes it is a void function.
-thomas
On Mon, 19 Jan 2009, Jeremy Silver wrote:
> 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:
>
> ######################
>
>> system('R CMD SHLIB reproduceError.c')
>
> make: `reproduceError.so' is up to date.
>
>>
>
>> reproduceError <- function(x){
>
> + dyn.load('reproduceError.so')
>
> + .C('tempCfunction',as.double(x))
>
> + dyn.unload('reproduceError.so')
>
> + invisible(NULL)
>
> + }
>
>>
>
>> pchisq(5.464342,1,lower.tail = FALSE)
>
> [1] 0.01940836
>
>> reproduceError(5.464342)
>
> stat = 5.464342, p = 0.019408
>
>> pchisq(5.464342,1,lower.tail = FALSE)
>
> [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
>
>> reproduceError(5.464342)
>
> stat = 5.464342, p = 0.019408
>
>> reproduceError(5.464342)
>
> stat = 5.464342, p = nan
>
> Warning message:
>
> In reproduceError(5.464342) :
>
> ** NON-convergence in pgamma()'s pd_lower_cf() f= nan.
>
>> pchisq(5.464342,1,lower.tail = FALSE)
>
> [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
>
>> pchisq(5.464342,1,lower.tail = FALSE)
>
> [1] 0.01940836
>
>> pchisq(5.464342,1,lower.tail = FALSE)
>
> [1] 0.01940836
>
>>
>
>> sessionInfo()
>
> 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
>
> --
> /****************************************
> Jeremy Silver
> Research Assistant
> University of Copenhagen, Denmark
> ph: +45 3532 7917
> email: j.silver at biostat.ku.dk or jere at pubhealth.ku.dk
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
On Mon, 2009-01-19 at 09:54 +0100, Jeremy Silver wrote:> Dear R experts,(...)> > pchisq(5.464342,1,lower.tail = FALSE) > > [1] 0.01940836 > > > reproduceError(5.464342) > > stat = 5.464342, p = 0.019408 > > > pchisq(5.464342,1,lower.tail = FALSE) > > [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 > >(...)> > > sessionInfo() > > 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 baseHi Jeremy, In my computer your error is not occur. Look This:> pchisq(5.464342,1,lower.tail = FALSE)[1] 0.01940836> pchisq(5.464342,1,lower.tail = FALSE)[1] 0.01940836> sessionInfo()R version 2.8.1 Patched (2009-01-16 r47630) x86_64-unknown-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 Well, do you already try update your R? -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil