Hi Peter,
Thanks for answering. Unfortunately your suggestion doesn't work with the
version we are using (Python 2.4.3, R 2.4.1, Rpy 1.0 RC2). It seems that
chisq function is waiting for a matrix as a double and not as a list. How
can we solve this?
Thanks in advance.

Output:
-----------------------------------------------------

>>> from rpy import r
(...)
>>> c1=[386,385,383]
>>> c2=[113,117,117]
>>> c=r.cbind(c1,c2)
>>> c
[[386, 113], [385, 117], [383, 117]]
>>> r.chisq_test(c)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
RException: Erro en any(x < 0) : el objeto (list) no puede ser coercido a
'double'

or

>>> r.chisq_test(r.cbind([386,385,383],[113,117,117]))["p.value"]
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
RException: Erro en any(x < 0) : el objeto (list) no puede ser coercido a
'double'

-----------------------------------------------------






2007/9/19, Peter <[EMAIL PROTECTED]>:
>
> Eloi Ribeiro wrote:
> > Hi,
> >
> > We'r trying to do a chisq test from Python using Rpy but the p-value
> > result is different depending if we do it directly in R or Python.
> > So the mistake must be in the way that data is defined.
> > Can someone help us in this matter?
> > Thanks in advance.
> >
> > Outputs:
> >
> -----------------------------------------------------------------------------
> > R output
>
> Confirmed on R 2.2.1 (yes, its old!)
>
> > m<-matrix(c(386,113,385,117,383,117),nrow=3,byrow=T)
> > chisq.test(m)$p.value
> [1] 0.9535284
>
> But notice:
>
> > chisq.test(c(386,385,383), c(113,117,117))$p.value
> [1] 0.2231302
> Warning message:
> Chi-squared approximation may be incorrect in: chisq.test(c(386, 385,
> 383), c(113, 117, 117))
>
> >
> -----------------------------------------------------------------------------
> >
> > Python / Rpy output
>
> Confirmed on an older version of RPy:
>
> >>> from rpy import *
> >>> c1 = [386,385,383]
> >>> c2 = [113,117,117]
> >>> r.chisq_test(c1,c2)["p.value"]
> Warning message:
> Chi-squared approximation may be incorrect in: function (x, y = NULL,
> correct = TRUE, p = rep(1/length(x), length(x)),
> 0.22313016014842982
>
> You are not passing the matrix correctly. One option that works is:
>
> >>> r.chisq_test(r.cbind([386,385,383],[113,117,117]))["p.value"]
> 0.9535284154083411
>
> I would suggest building an array in python (using Numeric or numpy)
> instead.
>
> Peter
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
>



-- 
Eloi Ribeiro

eloi.ribeiro[at]gmail.com
http://eloi-ribeiro.blogspot.com

Spain, Valencia
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to