Bugs item #1602142, was opened at 2006-11-24 03:15
Message generated for change (Comment added) made by warnes
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=453021&aid=1602142&group_id=48422
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: rpy
>Status: Pending
>Resolution: Works For Me
Priority: 5
Private: No
Submitted By: none (whatsoever)
Assigned to: Gregory Warnes (warnes)
Summary: Problem to convert numeric array into matrix
Initial Comment:
I'm working with a programm that converts a numeric array into a r-matrix.
In some R and Python versions it runs fine (e.g. python 2.4.3 and R 2.1.1)
In some versions ( e.g. R 2.2.3) the array is converted into a matrix with one
column containing lists in each cell.
I'm using the module Numeric to create the array.
I solved this by converting the array into a vector and create a matrix with
the number of rows of the array, but slows down the method.
My question:
Is this solved in the newest rpy-version or solved in any other way?
----------------------------------------------------------------------
>Comment By: Gregory Warnes (warnes)
Date: 2007-10-17 22:37
Message:
Logged In: YES
user_id=9316
Originator: NO
Provide numpy is installed, the current svn code seems to solve this
problem:
Python 2.3.5 (#1, Aug 19 2006, 21:31:42)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from rpy import *
>>> c1=[386,385,383]
>>> c2=[113,117,117]
>>> c=r.cbind(c1,c2)
>>> r.print_(c)
[,1] [,2]
[1,] 386 113
[2,] 385 117
[3,] 383 117
array([[386, 113],
[385, 117],
[383, 117]])
>>> r.chisq_test(c)
{'observed': array([[386, 113],
[385, 117],
[383, 117]]), 'residuals': array([[ 0.12040922, -0.21958259],
[-0.04825694, 0.0880031 ],
[-0.07193539, 0.13118397]]), 'p.value': 0.9535284154083411,
'statistic': {'X-squared': 0.095172106446633542}, 'expected': array([[
383.64157229, 115.35842771],
[ 385.94803464, 116.05196536],
[ 384.41039307, 115.58960693]]), 'data.name': ['structure(c(386L,
385L, 383L, 113L, 117L, 117L), .Dim = c(3L, ', '2L))'], 'parameter': {'df':
2.0}, 'method': "Pearson's Chi-squared test"}
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2007-09-21 05:44
Message:
Logged In: NO
We had this same problem:
>>> c1=[386,385,383]
>>> c2=[113,117,117]
>>> c=r.cbind(c1,c2)
>>> c
[[386, 113], [385, 117], [383, 117]]
>>> r.chisq_test(c)
rpy.RException: Error in any(x < 0) : the object (list) can not be coerced
to 'double'
We also tryied to create an array using Numeric and Numpy without success,
the function (chisq) keep reading a list of lists of integers instead of a
matrix.
Workaround suggested by Peter in [Rpy] mail list:
>>> c = [386,113,385,117,383,117]
>>> r.assign("x",c)
[386, 113, 385, 117, 383, 117]
>>> r(' chisq.test(matrix(x,nrow=3,ncol=2,byrow=TRUE))$p.value')
0.9535284154083411
Our Pc details:
* Processor Intel 32-bit
* Win 2000, 5.00.2195, Service Pack 4
* R2.5 & R2.4.1 (though we're using R2.4.1 for the tests)
* Numeric-24.2.win32-py2.4
* rpy-1.0-RC2.win32-R2.0.0-R-2.4.1-py2.4
* ActivePython 2.4.3 Build 11, Python 2.1 & Python 2.5 (yes 3 Python
version installed. We're using the v. 2.4.3 for the test)
----------------------------------------------------------------------
Comment By: Jeffrey Chang (jchang)
Date: 2007-08-30 16:04
Message:
Logged In: YES
user_id=12576
Originator: NO
I believe I am seeing this too. I am unable to create matrices in R.
This is on rpy 1.0RC3, R 2.5.1, python 2.5.1.
I do not understand the workaround described above, so am unable to test
whether that works on my setup.
>>> M = rpy.r.matrix([1, 2, 4, 5], 2, 2)
>>> M
array([[1, 4],
[2, 5]])
>>> rpy.r.print_(M)
NULL
>>> rpy.r.print_(rpy.r.dim(M))
NULL
>>> rpy.r.print_(rpy.r.dim([[1, 2], [3, 4]]))
NULL
>>> rpy.r.print_([[1, 2], [3, 4]])
[[1]]
[1] 1 2
[[2]]
[1] 3 4
[[1, 2], [3, 4]]
>>> rpy.r.print_(rpy.r.length([[1, 2], [3, 4]]))
[1] 2
2
>>> rpy.r.print_(rpy.r.mode([[1, 2], [3, 4]]))
[1] "list"
'list'
>>>
----------------------------------------------------------------------
Comment By: Gregory Warnes (warnes)
Date: 2006-11-27 09:32
Message:
Logged In: YES
user_id=9316
Originator: NO
These conversions should happen properly for all versions of RPy and R.
What platform and version of RPy are you using?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=453021&aid=1602142&group_id=48422
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list