On Mon, 2009-06-29 at 10:37 -0300, Donovan Parks wrote:
> Hello,
>
> I am new to RPy (and R in general) and am having trouble getting
> started. I'm performing a linear regression as follows:
>
> r = robjects.r
> xVec = robjects.FloatVector(X)
> yVec = robjects.FloatVector(Y)
> robjects.globalEnv["xVec"] = xVec
> robjects.globalEnv["yVec"] = yVec
> reg = r.lm("xVec ~ yVec")
>
> print(r.summary(reg))
>
> This works like a charm, although I am a little confused at why I need
> to declares my vectors into the global R namespace.
That's one way to do so, but you do not need to do so.
Other possibilities are:
- any arbitrary Environment
- a DataFrame (with the parameters to lm() "data")
- into the formula
http://rpy.sourceforge.net/rpy2/doc/html/robjects.html#formulae
> However, my real
> problem is dealing with the results. For example, I can obtain the
> adjusted r squared value as follows:
>
> summary = r.summary(reg)
> aRR = summary.r["adj.r.squared"]
>
> Now, print(aRR) gives me:
>
> $adj.r.squared
> [1] 0.1106428
>
> My question is how do I get at the actual value 0.1106428. I would
> have thought aRR[0] would do the trick, but this just returns an
> RVector. Obviously I am missing something fundamental here. Thanks for
> any and all help.
Try summary.r["adj.r.squared"][0][0]
Lists are a little particular, and the python __getitem__ / "[" operator
maps R's "[" operator. The first "[0]" gets you the first "list" items,
and the second "[0]" gets you the element.
rpy2-2.1.x (in development) is proposing an improvement by having R's
"[[" mapped as well.
(see
http://rpy.sourceforge.net/rpy2/doc-dev/html/robjects.html#extracting-items
)
L.
> Thanks,
> Donovan
>
> ------------------------------------------------------------------------------
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list