Hi David,
You need to use R's print function, rather than python's:
from rpy import *
data = {
"y":[1,2,3,4],
"x":[1,1,2,2]
}
set_default_mode(NO_CONVERSION)
lm = r.lm(r("y~x"),data)
summary_lm = r.summary(lm)
tmp = r.print_ (summary_lm)
Note the underscore on print, to avoid conflict with python's own
print statement.
-G
On Sep 6, 2007, at 4:26PM , David Marks wrote:
> Hi,
>
> I'm just getting used to the rpy module and so far I think it's
> pretty great. One thing I haven't figured out though is how to
> print R formatting. Here's my exact problem. I want to print the
> "summary" of an lm object in the same format that it prints in R.
> Here's the R version:
> > y = c(3,4,5,6)
> > x = c(1,1,2,2)
> > summary(lm(y~x))
>
> Call:
> lm(formula = y ~ x)
>
> Residuals:
> 1 2 3 4
> -0.5 0.5 -0.5 0.5
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 1.5000 1.1180 1.342 0.312
> x 2.0000 0.7071 2.828 0.106
>
> Residual standard error: 0.7071 on 2 degrees of freedom
> Multiple R-Squared: 0.8, Adjusted R-squared: 0.7
> F-statistic: 8 on 1 and 2 DF, p-value: 0.1056
>
> >
>
> The python version is
>
> >>> data = {"y":[1,2,3,4],"x":[1,1,2,2]}
> >>> lm = with_mode(0,r.lm)(r("y~x"),data)
> >>> print r.summary(lm)
> {'terms': <Robj object at 0xb7d3e2c0>, 'fstatistic': {'dendf': 2.0,
> 'value': 8.0000000000000036, 'numdf': 1.0}, 'aliased': {'x': False,
> '(Intercept)': False}, 'df': [2, 2, 2], 'call': <Robj object at
> 0xb7d3e2a0>, 'residuals': {'1': - 0.49999999999999972, '3':
> -0.50000000000000011, '2': 0.49999999999999983, '4':
> 0.49999999999999994}, 'adj.r.squared': 0.70000000000000007,
> 'cov.unscaled': array([[ 2.5, -1.5],
> [- 1.5, 1. ]]), 'r.squared': 0.80000000000000004, 'sigma':
> 0.70710678118654735, 'coefficients': array([[-0.5 ,
> 1.11803399, -0.4472136 , 0.69848866],
> [ 2. , 0.70710678, 2.82842712 , 0.10557281]])}
> >>>
>
> Is there anyway to get the print statement to give me the same nice
> formatting as I get in R? Thanks,
>
> David
> ----------------------------------------------------------------------
> ---
> 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/
> <mime-attachment.txt>
-------------------------------------------------------------------------
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