Gary Strangman wrote:
> Hi again,
> 
> Forgive me if this is a completely silly question for rpy2. I'm trying to 
> wean myself from rpy, but am confused by the new approach to conversion. 
> If I fit a model and collect summary info as follows ...
> 
> fit = robjects.r.lm(fmla,data)
> summary = robjects.r.summary(fit)
> 
> ... the summary variable comes back to python as an RVector. In rpy, it 
> was a dictionary, so if I wanted the coefficient/t-test summary-table I 
> could ask (in python) for summary['coefficients'].


R lists can have several elements with the same names, therefore 
returning a dictionary by default if not without risks.

Getting a dictionary is still possible:

import rpy2.robjects as ro

fit = ro.r["lm"]("%s ~ %s" %(ro.IntVector([1,2,3]).r_repr(),
                              ro.IntVector([3,1,2]).r_repr()))

elt = [(x, fit.r[x][0]) \
        for x in ro.r["names"](sfit)]

d = dict(elt)


> In rpy2 it appears I 
> have to ask for summary[3]. That's fine (harder to remember, but fine). 
> However, I can't seem to access any but the first column of the table. To 
> get a nice table I can ...
> 
>>>> print summary[3]
>                Estimate Std. Error    t value    Pr(>|t|)
> (Intercept) 10.9205792  2.9934159  3.6481997 0.001341692
> prerbmt      0.4226101  0.1729016  2.4442236 0.022599474
> mri         -0.3495370  0.7497424 -0.4662095 0.645450898
> 
> ... and if I want the estimate for the 2nd coefficient ...
> 
>>>> print summary[3][1]
> 0.4226101

You could index by name as well:
http://rpy.sourceforge.net/rpy2/doc/html/robjects.html#indexing


> But how do I get at the standard errors (or T-values) from python? Or is 
> there a better way to get at the contents of the returned results than 
> integer indexing?
> 
> More generally, how can one figure out what the components are for the 
> returned RVectors when calling R functions? The examples on the website 
> (nice doc, by the way!) appear to be oriented towards simply displaying 
> the results of R computations rather than retrieving R results for further 
> processing in python.

There will be more then.
Thanks for the feedback.



L.



> 
> -best
> Gary
> 
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to