Hi, List and Laurent, For the chisq function I tried to used through rpy2, I just did more test with the exact code as follows: ---------------------------------------------- import rpy2.robjects as robjects
p1dist = [] p2dist = [] num = 17 for x in range(num): p1dist.append(x) p2dist.append(x-1) print p1dist print p2dist rp1dist = robjects.FloatVector(p1dist) rp2dist = robjects.FloatVector(p2dist) res = robjects.r['chisq.test'](rp1dist, rp2dist) print(str(res.r['p.value']).split()[-1]) ----------------------------------------------------- When I set num to 17, it works "Warning message: In function (x, y = NULL, correct = TRUE, p = rep(1/length(x), length(x)), : Chi-squared approximation may be incorrect 0.2350833" However, if I set num to 18 (add one more element to the two vectors to be compared by chisq.test), it doesn't work. The error message is similar to my previous post: 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 names(dimnames(x)) <- DNAME : 'names' attribute [4] must be the same length as the vector [2] Could this mean that rpy2 doesn't take a long vector or I made some stupid mistake? Thanks! Hao > Hi Hao, > > The exact example that triggers the error may matter. > > I just tried the following with rpy2-2.1dev and it worked. > > x = robjects.FloatVector((1,2,3)) > y = robjects.FloatVector((2,3,4)) > > res = robjects.r['chisq.test'](x, y) > > I only get the following > Warning message: > In function (x, y = NULL, correct = TRUE, p = rep(1/length(x), > length(x)), : > Chi-squared approximation may be incorrect > > L. > > > > Hao Fan wrote: >> Hi, list >> >> I would like to calculate the fitness of two histograms, so I >> tried to use the chisq.test() in R through rpy2. >> The python code I have is as follows: >> ------------------- >> import rpy2.robjects as robjects >> >> p1dist = [X1, X2, ... Xm] >> p2dist = [Y1, Y2, ... Ym] >> >> rp1dist = robjects.FloatVector(p1dist) >> rp2dist = robjects.FloatVector(p2dist) >> >> robjects.r['chisq.test'](rp1dist, rp2dist) >> ------------------- >> >> Then I got the following error: >> File "/usr/lib64/python2.6/site-packages/rpy2/robjects/__init__.py", >> in __call__ >> res = super(RFunction, self).__call__(*new_args, **new_kwargs) >> rinterface.RRuntimeError: Error in names(dimnames(x)) <- DNAME : >> 'names' attribute [62] must be the same length as the vector [2] >> >> >> I also tried rpy_classic, so my code change to the follows: >> -------------------- >> import rpy2.robjects as robjects >> import rpy2.rpy_classic as rpy >> rpy.set_default_mode(rpy.NO_CONVERSION) >> >> p1dist = [X1, X2, ... Xm] >> p2dist = [Y1, Y2, ... Ym] >> >> rp1dist = robjects.FloatVector(p1dist) >> rp2dist = robjects.FloatVector(p2dist) >> >> robjects.r['chisq.test'](rp1dist, rp2dist) >> ----------------- >> >> Then I got similar error: >> File "/usr/lib64/python2.6/site-packages/rpy2/rpy_classic.py", line >> 214, in __call__ >> res = self.__sexp(*args_r, **kwargs_r) >> rinterface.RRuntimeError: Error in names(dimnames(x)) <- DNAME : >> 'names' attribute [62] must be the same length as the vector [2] >> >> >> I feel this problem is due to my wrong use of the R vector, but I >> can not find it. Any hints will be mostly appreciated! >> Thanks a lot in advance! >> >> >> Hao >> >> >> >> >> >> >> >> >> >> -- Hao Fan, PhD Department of Biopharmaceutical Sciences Mission Bay, Byers Hall 1700 4th Street, Suite 501 University of California, San Francisco San Francisco, CA 94158-2330 Tel +1 (415) 514-4258, 4232, 4233 Fax +1 (415) 514-4231, 4234 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list