Assigning to GlobalEnv does not seem to be required.
With rpy2-2.2.0dev, a standalone example can be like:
import rpy2.interactive as r
r.importr('survcomp')
# set up the stage (omitted from earlier code snippet)
age = r.packages.stats.rnorm(100, 50, 10)
sex = r.packages.base.sample(r.IntVector((0, 1)), 100, replace = True)
stime = r.packages.stats.rexp(100)
cens = r.packages.stats.runif(100, .5, 2)
sevent = r.packages.base.as_numeric(stime.ro <= cens)
stime = r.packages.base.pmin(stime, cens)
strat = r.packages.base.sample(r.IntVector((1, 2, 3)), 100, replace = True)
# run concordance_index
res = r.packages.survcomp.concordance_index(x = age, surv_time = stime,
surv_event = sevent, strat
= strat,
method = "noether")
L.
On 2011-04-18 20:27, Anamaria Crisan wrote:
Hello!
I solved this problem(finally!) and thought I would put up the
solution if anyone was interested. The only thing that's left is
converting my output to a dictionary...which I am still working on.
Here's what it looked like:
from numpy import *
from scipy import *
from rpy2.robjects import r
import rpy2.robjects.numpy2ri
r.library("survcomp")
r.assign('prob',prob)
r.assign('survTime',survTime)
r.assign('survEvent',survEvent)
cIndexData = r('cInd<-concordance.index(x=prob, surv.time =
survTime, surv.event = survEvent, method=\"noether\",outx=\"TRUE\")')
*
*
*So, things that made a difference:*
1. Using *assign* and putting the variables in the R environment
2. I was getting my data from an SQL database and it was
converting survTime to decimal type, so I altered my code to
convert to float.
3. Previously, my data was stored in lists, after much
investigation (thanks to the help of rpy2) I found out lists end
up having a strange conversion in R, so that's why I was getting
the length error. I used numpy arrays instead and
/rpy2.robjects.numpy2ri /to convert between numpy and R. This
ended up doing the trick.
Thanks for everyone that offered help. I am really new to RPy, so
perhaps my solution was actually really obvious. I didn't think of
all these variables : )
On Mon, Apr 18, 2011 at 10:25 AM, Peter
<[email protected]
<mailto:[email protected]>> wrote:
On Mon, Apr 18, 2011 at 5:24 PM, Anamaria Crisan
<[email protected] <mailto:[email protected]>>
wrote:
> Hi,
> I've tried changing the conversion mode as suggested,
however it will die at
> the r_result = cindex(x=prob, surv_time=survTIME,
surv_even=survEVENT)
> line. I don't know how often R methods have var.name
<http://var.name> , but if someone else
> has successfully run such a method before that would be good
to know. My
> code works in R; even if I put it in an RPy module with no
other code (and
> line for line as it was done in R) it fails. There has to be
some conversion
> issue happening, but I don't know how to fix it.
Additionally RPy2 hasn't
> solved the problem yet.
Can you give a self contained example in R, and your attempt
in Python?
e.g. Try using one of the many built in example datasets in R.
Peter
--
Anamaria Crisan
Medical Genomics Research Associate
GenomeDx Biosciences Inc. | 201-1595 W. 3rd Ave, Vancouver, BC V6J 1J8
Off: 604-568-7570 | Fax: 866-505-5161
ana <http://goog_1098469627>@genomedx.com <http://@genomedx.com>
www.genomedx.com <http://www.genomedx.com/>
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list