Hi, Laurent, I test the "clean" code I you suggested. It works! You are right, I also have a few other functions defined together with this chisq calculation. Basicly they are file IOs written in normal python. So it seems those parts caused the problem but not the rpy part. Thanks a lot for your great help! Now I know where to go! :-)
all the best 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