> -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Bhanu Mangipudi > Sent: Wednesday, November 11, 2009 11:16 AM > To: r-help@r-project.org > Subject: [R] fisher.test negative value error > > Hi all, > > I am new to python, R and rpy2. I having few errors when I am using > 'fisher.test' function where I am struck now. Please help to > fix these bugs. > My code for fisher.test goes this way > > *from rpy2 import * > import rpy2.robjects as robjects > def fisherExact(a,b,c,d): > v = [a,b,c,d] > m = robjects.r['matrix'](v,2,2) > s = robjects.r['fisher.test'](m) > return s > * > > Here the value of a=0,b=1,c=0 and d=1. so the matrix m should > be like this > > [,1] [,2] > [1,] 0 0 > [2,] 1 1 > > But I am getting an error like this > > *File > "/usr/lib64/python2.6/site-packages/rpy2/robjects/__init__.py", line > 422, in __call__ > res = super(RFunction, self).__call__(*new_args, **new_kwargs) > rinterface.RRuntimeError: Error in function (x, y = NULL, > workspace = 2e+05, > hybrid = FALSE, control = list(), : > all entries of 'x' must be nonnegative and finite*
I think you are passing a list matrix to fisher.test, not a numeric matrix. E.g., > fisher.test(matrix(list(0,1,0,1),2,2)) Error in fisher.test(matrix(list(0, 1, 0, 1), 2, 2)) : all entries of 'x' must be nonnegative and finite The python v should be a numeric array instead of a list. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > clearly every element of matrix m is +ve but I don't know why > I am getting > this error. I am using python 2.6,R-core-2.9.2-1 and rpy2. > > Please help me in this regard. > > Thanks, > Bhanu. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > ______________________________________________ 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.