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.sil...@biostat.ku.dk or j...@pubhealth.ku.dk
______________________________________________
R-help@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
tlum...@u.washington.edu University of Washington, Seattle
______________________________________________
R-help@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.