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
> m<-matrix(c(386,113,385,117,383,117),nrow=3,byrow=T)
> m
[,1] [,2]
[1,] 386 113
[2,] 385 117
[3,] 383 117
> chisq.test(m)
Pearson's Chi-squared test
data: m
X-squared = 0.0952, df = 2, p-value = 0.9535
-----------------------------------------------------------------------------
Python / Rpy output
>>> from rpy import *
RHOME= C:\Archivos de programa\R\R-2.4.1
RVERSION= 2.4.1
RVER= 2041
RUSER= K:\
Loading the R DLL C:\Archivos de programa\R\R-2.4.1\bin\R.dll .. Done.
Loading Rpy version 2041 .. Done.
Creating the R object 'r' .. Done
>>> c1 = [386,385,383]
>>> c2 = [113,117,117]
>>> c1
[386, 385, 383]
>>> c2
[113, 117, 117]
>>> r.chisq_test(c1,c2)
Warning message:
Chi-squared approximation may be incorrect in: function (x, y = NULL,
correct = TRUE, p = rep(1/length(x), length(x)),
{'observed': [[0, 1], [0, 1], [1, 0]],
'residuals': [[-0.57735026918962573, 0.40824829046386307], [-
0.57735026918962573, 0.40824829046386307], [1.1547005383792517, -
0.81649658092772603]],
'p.value': 0.22313016014842979,
'statistic': {'X-squared': 3.0000000000000004},
'expected': [[0.33333333333333331, 0.66666666666666663], [
0.33333333333333331, 0.66666666666666663], [0.33333333333333331,
0.66666666666666663]],
'data.name': 'c(386, 385, 383) and c(113, 117, 117)',
'parameter': {'df': 2.0},
'method': "Pearson's Chi-squared test"}
-----------------------------------------------------------------------------
--
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