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

Reply via email to